[dart-dio] Fix nullable inline object models#23867
Conversation
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.
| * <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
e1561fe to
de63f7e
Compare
|
please resolve the merge conflicts when you've time. |
we just merged #24140 yesterday which is related to this fix please have a look to see if that meets your requirement as well (and see if this PR is still needed) |
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 (and request params) as nullable.Bug Fixes
ModelUtils.isNullableto detect type-arraynull; apply across model, property, parameter, and request body generation (including$refs).nullablewhen promoting inline schemas and when creating$refs/components inInlineModelResolverandDefaultCodegen(also carryrequired).nulland warn only on deprecatednullable/x-nullable; document the nullable-attribute helper; add tests and a 3.1 fixture.Refactors
ModelUtils.hasType,ModelUtils.hasExtension, andDefaultCodegen.hasNullableMarkerto centralize nullability markers and reduce duplicate checks.Written for commit 5668185. Summary will update on new commits.