[dart-dio] Fix nullable inline object models#23867
Open
ShellWen wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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.isNullableto treatschema.typescontaining"null"as nullable. - Preserve/propagate nullability when inline schemas are promoted to
$refviaInlineModelResolver, and useModelUtils.isNullablemore consistently inDefaultCodegen(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> |
ab72e44 to
e1561fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-diofields 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 \ testResult:
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. Generateddart-diomodels now correctly mark these fields as nullable.ModelUtils.isNullableto detect type-arraynulland use it across model, property, and parameter generation (including refs).nullablewhen promoting inline schemas and creating$refs/components inInlineModelResolverandDefaultCodegen(carryrequiredtoo).nulland warn only on deprecatednullable/x-nullable; add tests and a 3.1 fixture.Written for commit e1561fe. Summary will update on new commits. Review in cubic