Skip to content

[BUG] Dart-dio ignoring nullable references (nullableReferenceTypes: true) #21565

Description

@JamesFieldist

Bug Report Checklist

  • [X ] Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

dart-dio doesn't honor nullable references types. Doesn't matter if nullableReferenceTypes: true or not.

openapi-generator version

7.14.0

OpenAPI declaration file content or url
"TacitQuestionDto": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "primaryCategory",
          "secondaryCategory",
          "tertiaryCategory",
          "divisions",
          "question",
          "questionType",
          "frequency",
          "owningContact",
          "noOfLines",
          "options",
          "standAlone"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Id",
            "format": "uuid",
            "nullable": true
          },
          "primaryCategory": {
            "nullable": false,
            "$ref": "#/components/schemas/CategoryRefDto"
          },
          "secondaryCategory": {
            "nullable": false,
            "$ref": "#/components/schemas/CategoryRefDto"
          },
          "tertiaryCategory": {
            "nullable": true,
            "$ref": "#/components/schemas/CategoryRefDto",
            "x-nullable": true
          },
          "divisions": {
            "type": "array",
            "nullable": false,
            "items": {
              "$ref": "#/components/schemas/TacitDivisionDto"
            }
          },
          "descriptor": {
            "type": "string",
            "nullable": true
          },
          "order": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "question": {
            "type": "string",
            "nullable": false
          },
          "questionType": {
            "nullable": false,
            "$ref": "#/components/schemas/AnswerTypes"
          },
          "noOfLines": {
            "type": "integer",
            "format": "int32",
            "nullable": false
          },
          "askDelayAfterNoAnswerDays": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "frequency": {
            "nullable": false,
            "$ref": "#/components/schemas/TacitQuestionFrequency"
          },
          "options": {
            "type": "array",
            "nullable": false,
            "items": {
              "type": "string"
            }
          },
          "hiddenBy": {
            "type": "array",
            "nullable": true,
            "items": {
              "type": "string"
            }
          },
          "standAlone": {
            "type": "boolean",
            "nullable": false
          },
          "owningContact": {
            "nullable": false,
            "$ref": "#/components/schemas/ContactRefDto"
          },
          "followupQuestions": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/QuestionRefDto"
            }
          }
        }
      },

(for JSON code), so it becomes more readable. If it is longer than about ten lines,
please create a Gist (https://gist.github.com) or upload it somewhere else and
link it here.
-->

Generation Details

open-generator-config.yaml file:


generatorName: dart-dio
additionalProperties:
  pubName: api
  pubVersion: 0.0.1
  pubDescription: "API client for Dart"
  serializationLibrary: json_serializable
  enablePostProcessFile: true
  enumPropertyNaming: original
  useEnumExtension: true
  useSingleRequestParameter: true
  withSeparateModelsAndApi: true
  modelPropertyNaming: original
  supportNullable: true # Ensure OpenAPI nullable rules are respected
  legacyDiscriminatorBehavior: false
  strictNullChecks: true
  nullableReferenceTypes: true # If using C# generation
Steps to reproduce

Use any openapi document that has a nullable reference in it.

Run the cli like this:

			"@openapitools/openapi-generator-cli",
			"generate",
			"-i",
			"http://localhost:16049/help/v1/openapi.json",
			"-g",
			"dart-dio",
			"-c",
			"open-generator-config.yaml",
			"--enable-post-process-file"

The resulting property on the class generated will not be nullable and should be.

Related issues/PRs

Couldn't find any.

Suggest a fix

The dart generator(s) should honor nullable: true and/or x-nullable: true per the documentation on reference properties on schemas. As it stands right now it only honors nullable on concrete types, not references to other objects.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions