Normalizer: new rule LOOSE_NULL_DEFINITIONS to allow more null definitions in 3.0 spec. - #23932
Merged
wing328 merged 9 commits intoJun 3, 2026
Merged
Conversation
…OpenAPI 3.0.x
The SIMPLIFY_ONEOF_ANYOF normalizer failed to simplify anyOf schemas
where the nullable branch uses {type: "object", nullable: true} instead
of an untyped schema or {type: "null"}. This caused Java (and likely
other) code generators to produce Object or synthetic wrapper classes
instead of the intended typed nullable field.
This pattern is a valid OpenAPI 3.0.x idiom for expressing nullability
alongside a $ref in anyOf/oneOf. It is produced by apispec >= 6.7.1
(the most widely used OpenAPI spec generator for Python/Flask/Marshmallow)
and potentially other spec generators.
Root cause: isNullTypeSchema() did not recognize an empty nullable object
({type: "object", nullable: true} with no properties and no $ref) as a
null-type schema. The fix adds a check for this pattern, scoped to 3.0.x
only via !(schema instanceof JsonSchema), since OpenAPI 3.1 expresses
nullability differently via type arrays.
Test coverage:
- isNullTypeSchemaTest: 3.0 sentinel (true), sentinel with properties (false)
- isNullTypeSchemaTestWith31Spec: 3.1 sentinel correctly returns false
- isNullTypeSchemaInlineAnyOfSentinelTest: inline anyOf sub-schema recognized
- testAnyOfNullableObjectSentinelResolvesToTypedField: end-to-end Java
codegen produces Address field, no synthetic OrderShippingAddress wrapper
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…/github.com/ericdriggs/openapi-generator into ericdriggs-fix/3.0-nullable-object-null-type-detection
null definitions in 3.0 spec.
wing328
marked this pull request as ready for review
June 3, 2026 08:46
Contributor
There was a problem hiding this comment.
3 issues found across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
wing328
deleted the
ericdriggs-fix/3.0-nullable-object-null-type-detection
branch
June 3, 2026 09:28
4 tasks done
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.
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 asnulltype in 3.1 spec.based on #23621 by @ericdriggs
e.g. in CLI
PR checklist
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.
Summary by cubic
Fixes null-type detection in OpenAPI 3.0.x for
{type: object, nullable: true}soanyOf/oneOfpatterns like$ref | nullsimplify to typed nullable fields, notObjector wrapper classes. Adds theLOOSE_NULL_DEFINITIONSnormalizer option to enable this behavior.New Features
LOOSE_NULL_DEFINITIONStoOpenAPINormalizer; enabling it setsModelUtils.looseNullDefinitions = true.modules/openapi-generator/src/test/resources/bugs/issue_anyof_bare_nullable_object.yaml.Bug Fixes
ModelUtils.isNullTypeSchemato treat a bare nullable object (no$ref, noadditionalProperties) asnullin 3.0.x when the rule is enabled; 3.1 remains unchanged.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.Written for commit 0e501ef. Summary will update on new commits.