Skip to content

Normalizer: new rule LOOSE_NULL_DEFINITIONS to allow more null definitions in 3.0 spec. - #23932

Merged
wing328 merged 9 commits into
masterfrom
ericdriggs-fix/3.0-nullable-object-null-type-detection
Jun 3, 2026
Merged

wing328 merged 9 commits into
masterfrom
ericdriggs-fix/3.0-nullable-object-null-type-detection

Conversation

@wing328

@wing328 wing328 commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

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 #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:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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_DEFINITIONS to OpenAPINormalizer; enabling it sets ModelUtils.looseNullDefinitions = true.
    • Updates docs with a CLI example using modules/openapi-generator/src/test/resources/bugs/issue_anyof_bare_nullable_object.yaml.
  • Bug Fixes

    • Updates ModelUtils.isNullTypeSchema to treat a bare nullable object (no $ref, no additionalProperties) as null in 3.0.x when the rule is enabled; 3.1 remains unchanged.
    • Ensures SIMPLIFY_ONEOF_ANYOF collapses $ref | {type: object, nullable: true} into a typed nullable field; adds tests for 3.0 and 3.1 and guards objects with properties or additionalProperties from being treated as null.

Written for commit 0e501ef. Summary will update on new commits.

Review in cubic

eric-driggs and others added 6 commits April 24, 2026 15:53
…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>
@wing328 wing328 changed the title Ericdriggs fix/3.0 nullable object null type detection Normalizer: new rule LOOSE_NULL_DEFINITIONS to allow more null definitions in 3.0 spec. Jun 3, 2026
@wing328
wing328 marked this pull request as ready for review June 3, 2026 08:46
@wing328 wing328 added Enhancement: Feature OpenAPI Normalizer Normalize the spec for easier processing labels Jun 3, 2026
@wing328 wing328 added this to the 7.23.0 milestone Jun 3, 2026

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

3 issues found across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread docs/customization.md Outdated
@wing328
wing328 merged commit 7ee4a73 into master Jun 3, 2026
15 checks passed
@wing328
wing328 deleted the ericdriggs-fix/3.0-nullable-object-null-type-detection branch June 3, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement: Feature OpenAPI Normalizer Normalize the spec for easier processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants