Skip to content

[dart-dio] Fix nullable inline object models#23867

Open
ShellWen wants to merge 1 commit into
OpenAPITools:masterfrom
ShellWen:fix-dart-dio-nullable-inline-object
Open

[dart-dio] Fix nullable inline object models#23867
ShellWen wants to merge 1 commit into
OpenAPITools:masterfrom
ShellWen:fix-dart-dio-nullable-inline-object

Conversation

@ShellWen
Copy link
Copy Markdown

@ShellWen ShellWen commented May 25, 2026

What does this PR do?

Fixes nullable handling for OAS 3.1 inline object schemas using the type-array form, e.g. type: [object, null], after they are promoted to inline component models.

This keeps dart-dio fields nullable for schemas like issue #23866.

How was this tested?

mvn -s /tmp/openapi-generator-maven-settings.xml \
  -pl modules/openapi-generator \
  -Dtest=org.openapitools.codegen.dart.dio.DartDioModelTest,org.openapitools.codegen.utils.ModelUtilsTest,org.openapitools.codegen.validations.oas.OpenApiSchemaValidationsTest,org.openapitools.codegen.DefaultCodegenTest \
  test

Result: Tests run: 254, Failures: 0, Errors: 0, Skipped: 0.

Fixes #23866


Summary by cubic

Fixes nullable handling for OAS 3.1 inline object schemas using type arrays like type: [object, null], so promoted inline models keep nullability. Generated dart-dio models now correctly mark these fields as nullable.

  • Bug Fixes
    • Extend ModelUtils.isNullable to detect type-array null and use it across model, property, and parameter generation (including refs).
    • Preserve nullable when promoting inline schemas and creating $refs/components in InlineModelResolver and DefaultCodegen (carry required too).
    • Update OAS 3.1 validation to ignore type-array null and warn only on deprecated nullable/x-nullable; add tests and a 3.1 fixture.

Written for commit e1561fe. Summary will update on new commits. Review in cubic

Copilot AI review requested due to automatic review settings May 25, 2026 10:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes nullability propagation for OpenAPI 3.1 inline object schemas declared with type-array unions (e.g. type: [object, "null"]) after they’re promoted to inline component models, ensuring generators (notably dart-dio) keep the field nullable.

Changes:

  • Extend ModelUtils.isNullable to treat schema.types containing "null" as nullable.
  • Preserve/propagate nullability when inline schemas are promoted to $ref via InlineModelResolver, and use ModelUtils.isNullable more consistently in DefaultCodegen (models, properties, parameters).
  • Add regression coverage across dart-dio, DefaultCodegen, ModelUtils, and OAS schema validation recommendations, plus a new repro spec fixture.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
modules/openapi-generator/src/test/resources/3_1/dart-dio/issue_23866.yaml Adds the OAS 3.1 repro spec fixture used by new/updated tests.
modules/openapi-generator/src/test/java/org/openapitools/codegen/validations/oas/OpenApiSchemaValidationsTest.java Adds test ensuring type-array null doesn’t trigger the deprecated nullable recommendation.
modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java Adds unit test verifying ModelUtils.isNullable detects type-array null.
modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java Adds regression test asserting CodegenProperty.isNullable for type-array null inline object properties.
modules/openapi-generator/src/test/java/org/openapitools/codegen/dart/dio/DartDioModelTest.java Adds dart-dio-specific regression test asserting nullability is preserved for promoted inline object models.
modules/openapi-generator/src/main/java/org/openapitools/codegen/validations/oas/OpenApiSchemaValidations.java Refines nullable-attribute recommendation to only trigger on actual nullable/x-nullable, not on type-array null.
modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java Updates isNullable implementation and Javadoc to include OAS 3.1 type-array null handling.
modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java Ensures nullability survives inline schema promotion to $ref by setting nullable on generated ref schemas when appropriate.
modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java Switches nullability detection to ModelUtils.isNullable across model/property/parameter paths and adds a helper to avoid overwriting derived nullability unless explicitly marked.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1769 to 1774
* <p>
* In addition, if the OAS document is 3.1 or above, isNullable returns true if the input
* schema is a 'oneOf' composed document with at most two children, and one of the children
* is the 'null' type.
* is the 'null' type. It also returns true if the schema uses the OAS 3.1 type-array form
* and one of the types is 'null'.
* <p>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 9 files

Re-trigger cubic

@ShellWen ShellWen force-pushed the fix-dart-dio-nullable-inline-object branch from ab72e44 to e1561fe Compare May 25, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][dart-dio] OAS 3.1 type: ["object", "null"] on inline object schema produces non-nullable Dart field

2 participants