OpenAPITools / OpenAPITools/openapi-generator

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

Open
#21,565 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the provided OpenAPI schema and open-generator-config.yaml with the @openapitools/openapi-generator-cli command to reproduce the dart-dio output. Compare generated properties for nullable concrete fields with nullable $ref fields; done means nullable: true and x-nullable: true are honored for references under the stated configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.