Skip to content

fix: keep allOf members that have properties alongside a validation keyword - #24551

Open
donald wants to merge 1 commit into
OpenAPITools:masterfrom
donald:fix/allof-member-properties-dropped
Open

fix: keep allOf members that have properties alongside a validation keyword#24551
donald wants to merge 1 commit into
OpenAPITools:masterfrom
donald:fix/allof-member-properties-dropped

Conversation

@donald

@donald donald commented Aug 1, 2026

Copy link
Copy Markdown

Fixes #24550

What

A schema carrying properties but omitting type: object, next to a validation keyword, was classified as
"validation without a type" and silently dropped from allOf. Every model inheriting it lost those
properties — no error, no warning, just a smaller model and a broken JSON contract.

Parent:
  minProperties: 2            # validation keyword, and no `type: object`
  properties:
    alpha: { type: string }
    beta:  { type: string }
Child:
  allOf: [{ $ref: '#/components/schemas/Parent' }]
  properties:
    gamma: { type: string }
// before
export interface Child { gamma?: string; }                              // alpha/beta gone

// after
export interface Child { alpha?: string; beta?: string; gamma?: string; }

Removing minProperties — or adding an explicit type: object — makes the properties reappear, which is
what makes this easy to hit without noticing.

Why

OpenAPINormalizer.removeUnsupportedSchemasFromAllOf()
drops every allOf member for which ModelUtils.isUnsupportedSchema() returns true, and that check was:

if (schema.getTypes() == null && hasValidation(schema)) {
    // just validation without type
    return true;
}

getTypes() is only populated for 3.1, so for a 3.0 spec it is always null. In practice that means any
3.0 schema with a validation keyword and no explicit type was judged unsupported — including ones that are
plainly models. Omitting type: object next to properties is very common in 3.0 specs.

How

Also require that the schema has no properties, and check getType() alongside getTypes() so the 3.0
case is recognised at all. A schema with properties is a model, not bare validation.

The intent of the original check — skipping schemas that are only validation, and if/then schemas —
is preserved; the existing isUnsupportedSchemaTest assertions still pass unchanged.

Testing

  • OpenAPINormalizerTest.testAllOfMemberWithValidationAndPropertiesIsKept — asserts the allOf member
    referencing Parent survives normalization. Verified that this test fails without the fix
    (the whole allOf was dropped, so Child lost the inherited properties).
  • Full OpenAPINormalizerTest (64 tests) and ModelUtilsTest (68 tests, including the existing
    isUnsupportedSchemaTest) pass.
  • Regenerated all 787 sample configs (./bin/generate-samples.sh ./bin/configs/*.yaml) and
    ./bin/utils/export_docs_generators.shno diff.

Note on the full test run: mvn test on modules/openapi-generator reports one pre-existing failure,
OpenApiSchemaValidationsTest.testNullTypeInOas31_noWarning. It fails identically on unmodified
master (4aed9c1c635) — verified by reverting the patch and re-running — and is unrelated to this change.

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
    
    Commit all changed files.
    (Both scripts were run; neither produced any change, so there is nothing to commit beyond the fix and its test.)
  • File the PR against the correct branch: master
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

This is in the language-agnostic core (OpenAPINormalizer / ModelUtils), so it is not owned by one
language committee. CC @wing328

🤖 Generated with Claude Code


Summary by cubic

Fixes dropped allOf members when a referenced schema has properties alongside a validation keyword but omits type: object. Child models now correctly inherit those properties, preserving the JSON contract.

  • Bug Fixes
    • Updated ModelUtils.isUnsupportedSchema() to only treat a schema as validation-only when it lacks both getTypes() (OAS 3.1) and getType() (OAS 3.0), has validation keywords, and has no properties.
    • Added OpenAPINormalizerTest.testAllOfMemberWithValidationAndPropertiesIsKept with a 3.0 sample; full tests pass and regenerating samples shows no diffs.

Written for commit dd946ff. Summary will update on new commits.

Review in cubic

…eyword

A schema carrying `properties` but omitting `type: object`, next to a
validation keyword, was classified as "validation without a type" and
silently dropped from allOf. Every model inheriting it lost those
properties -- no error, no warning, just a smaller model and a broken JSON
contract:

    Parent:
      minProperties: 2          # validation keyword, no `type: object`
      properties:
        alpha: { type: string }
        beta:  { type: string }
    Child:
      allOf: [{ $ref: '#/components/schemas/Parent' }]
      properties:
        gamma: { type: string }

    // before: Child has only `gamma`
    // after:  Child has `alpha`, `beta`, `gamma`

OpenAPINormalizer.removeUnsupportedSchemasFromAllOf() drops any allOf
member for which ModelUtils.isUnsupportedSchema() returns true, and that
check was:

    schema.getTypes() == null && hasValidation(schema)

Omitting `type: object` next to `properties` is very common in 3.0 specs,
and getTypes() is only populated for 3.1, so in practice any 3.0 schema
with a validation keyword and no explicit type was judged unsupported --
including ones that are plainly models.

Require that the schema also has no properties (and check getType() as
well, so the 3.0 case is recognised at all). A schema with properties is a
model, not bare validation.

Regenerating all 787 sample configs produces no diff.

@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.

No issues found across 3 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] allOf member with properties + a validation keyword is silently dropped, losing its properties

1 participant