Skip to content

[Dart] Compilation errors for NOTION.COM api #7807

Description

@WolfgangHG

Found as part of #7774:

Using the source code from 2026-06-17 and this command:

.\it\generate-code.ps1 -descriptionUrl https://developers.notion.com/openapi.json  -language "dart" -dev
.\it\exec-cmd.ps1 -descriptionUrl https://developers.notion.com/openapi.json  -language "dart"

The generated client does not compile:

Analyzing lib...

  error • models\error_api400.dart:11:5 • Undefined class 'PublicApiCommonErrorResponseAdditionalData'. Try changing the
          name to the name of an existing class, or creating a class with the name
          'PublicApiCommonErrorResponseAdditionalData'. • undefined_class
  error • models\error_api400.dart:32:179 • Undefined class 'PublicApiCommonErrorResponseAdditionalData'. Try changing
          the name to the name of an existing class, or creating a class with the name
          'PublicApiCommonErrorResponseAdditionalData'. • undefined_class
  error • models\error_api400.dart:54:101 • The name 'PublicApiCommonErrorResponseAdditionalData' isn't a type, so it
          can't be used as a type argument. Try correcting the name to an existing type, or defining a type named
          'PublicApiCommonErrorResponseAdditionalData'. • non_type_as_type_argument
  ... 
  (repeated for a lot of error classes)
  ...
  error • models\internal_or_external_file_with_name_response.dart:11:5 • Non-nullable instance field 'additionalData'
          must be initialized. Try adding an initializer expression, or add a field initializer in this constructor, or
          mark it 'late'. • not_initialized_non_nullable_instance_field
  error • models\rich_text_item_response.dart:11:5 • Non-nullable instance field 'additionalData' must be initialized.
          Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'. •
          not_initialized_non_nullable_instance_field
  error • models\user_object_response.dart:11:5 • Non-nullable instance field 'additionalData' must be initialized. Try
          adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'. •
          not_initialized_non_nullable_instance_field
  error • models\view_config_response_donut_labels.dart:5:10 • A value of type 'String' can't be assigned to a parameter
          of type 'ViewConfigResponseDonutLabels' in a const constructor. Try using a subtype, or removing the keyword
          'const'. • const_constructor_param_type_mismatch
  error • models\view_config_response_donut_labels.dart:5:10 • The argument type 'String' can't be assigned to the
          parameter type 'ViewConfigResponseDonutLabels'.  • argument_type_not_assignable
  error • models\view_config_response_donut_labels.dart:6:5 • Class 'ViewConfigResponseDonutLabels' can't define static
          member 'value' and have instance member 'ViewConfigResponseDonutLabels.value' with the same name. Try renaming
          the member to a name that doesn't conflict. • conflicting_static_and_instance
  error • models\view_config_response_donut_labels.dart:6:11 • A value of type 'String' can't be assigned to a parameter
          of type 'ViewConfigResponseDonutLabels' in a const constructor. Try using a subtype, or removing the keyword
          'const'. • const_constructor_param_type_mismatch
  error • models\view_config_response_donut_labels.dart:6:11 • The argument type 'String' can't be assigned to the
          parameter type 'ViewConfigResponseDonutLabels'.  • argument_type_not_assignable
  error • models\view_config_response_donut_labels.dart:7:10 • A value of type 'String' can't be assigned to a parameter
          of type 'ViewConfigResponseDonutLabels' in a const constructor. Try using a subtype, or removing the keyword
          'const'. • const_constructor_param_type_mismatch
  error • models\view_config_response_donut_labels.dart:7:10 • The argument type 'String' can't be assigned to the
          parameter type 'ViewConfigResponseDonutLabels'.  • argument_type_not_assignable
  error • models\view_config_response_donut_labels.dart:8:18 • A value of type 'String' can't be assigned to a parameter
          of type 'ViewConfigResponseDonutLabels' in a const constructor. Try using a subtype, or removing the keyword
          'const'. • const_constructor_param_type_mismatch
  error • models\view_config_response_donut_labels.dart:8:18 • The argument type 'String' can't be assigned to the
          parameter type 'ViewConfigResponseDonutLabels'.  • argument_type_not_assignable
  error • models\view_config_response_donut_labels.dart:9:11 • All final variables must be initialized, but 'value'
          isn't. Try adding an initializer for the field. • final_not_initialized_constructor
  error • models\view_config_response_donut_labels.dart:9:41 • 'value' is a static field in the enclosing class. Fields
          initialized in a constructor can't be static. Try removing the initialization. • initializer_for_static_field
  error • models\view_config_response_donut_labels.dart:9:46 • 'value' is final and was given a value when it was
          declared, so it can't be set to a new value. Try removing one of the initializations. •
          final_initialized_in_declaration_and_constructor

85 issues found.

This is the content of the file "error_api400.dart":

// ignore_for_file: type=lint
import 'package:microsoft_kiota_abstractions/microsoft_kiota_abstractions.dart';
import './error_api400_code.dart';

/// auto generated
class ErrorApi400 extends ApiException implements AdditionalDataHolder, Parsable {
    ///  Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
    @override
    Map<String, Object?> additionalData;
    ///  The additional_dataProperty property
    PublicApiCommonErrorResponseAdditionalData? additionalDataProperty;
    ///  The code property
    ErrorApi400Code? code;
    ///  The object property
    UntypedNode? object;
    ///  The status property
    UntypedNode? status;
    /// Instantiates a new [ErrorApi400] and sets the default values.
    ErrorApi400( {
        super.message,
        super.statusCode,
        super.responseHeaders,
        super.innerExceptions,
        required this.additionalData,
        this.additionalDataProperty,
        this.code,
        this.object,
        this.status,
    });

A file for "PublicApiCommonErrorResponseAdditionalData" does not exist, but there is a file "public_api_common_error_response.dart" containing a class "PublicApiCommonErrorResponse".

The component "error_api_400" is defined like this:

"error_api_400": {
  "allOf": [
    {
      "$ref": "#/components/schemas/publicApiCommonErrorResponse"
    },
    {
      "type": "object",
      "properties": {
        "code": {
          "enum": [
            "invalid_json",
            "invalid_request_url",
            "invalid_request",
            "missing_version",
            "validation_error"
          ]
        },
        "status": {
          "const": 400
        }
      },
      "required": [
        "code",
        "status"
      ],
      "additionalProperties": false
    }
  ]
},

This compilation error goes away with two changes to "error_api400.dart" - but I don't know whether this is correct code 😄:

// ignore_for_file: type=lint
import 'package:microsoft_kiota_abstractions/microsoft_kiota_abstractions.dart';
import './error_api400_code.dart';
import './public_api_common_error_response.dart';

/// auto generated
class ErrorApi400 extends ApiException implements AdditionalDataHolder, Parsable {
    ///  Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
    @override
    Map<String, Object?> additionalData;
    ///  The additional_dataProperty property
    PublicApiCommonErrorResponse? additionalDataProperty;
    ///  The code property
    ErrorApi400Code? code;

I did not analyze the other errors further.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions