Normalizer: new rule LOOSE_NULL_DEFINITIONS to allow more `null` definitions in 3.0 spec.
Merged
WI
6mo ago+162+162+012345678901234567890123456789-6-6-0123456789
Normalizer: new rule LOOSE_NULL_DEFINITIONS to allow more null definitions in 3.0 spec
When set to true, {type: object, nullable: true} (in 3.0 spec) is considered as null type in 3.1 spec.
based on https://github.com/OpenAPITools/openapi-generator/pull/23621 by @ericdriggs
e.g. in CLI
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i modules/openapi-generator/src/test/resources/bugs/issue_anyof_bare_nullable_object.yaml -o /tmp/java-okhttp/ --openapi-normalizer LOOSE_NULL_DEFINITIONS=true
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Summary by cubic
Fixes null-type detection in OpenAPI 3.0.x for {type: object, nullable: true} so anyOf/oneOf patterns like $ref | null simplify to typed nullable fields, not Object or wrapper classes. Adds the LOOSE_NULL_DEFINITIONS normalizer option to enable this behavior.
-
New Features
- Adds
LOOSE_NULL_DEFINITIONStoOpenAPINormalizer; enabling it setsModelUtils.looseNullDefinitions = true. - Updates docs with a CLI example using
modules/openapi-generator/src/test/resources/bugs/issue_anyof_bare_nullable_object.yaml.
- Adds
-
Bug Fixes
- Updates
ModelUtils.isNullTypeSchemato treat a bare nullable object (no$ref, noadditionalProperties) asnullin 3.0.x when the rule is enabled; 3.1 remains unchanged. - Ensures
SIMPLIFY_ONEOF_ANYOFcollapses$ref | {type: object, nullable: true}into a typed nullable field; adds tests for 3.0 and 3.1 and guards objects withpropertiesoradditionalPropertiesfrom being treated asnull.
- Updates