Skip to content

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

Description

@donald

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If a schema has properties but omits type: object, and it also carries any validation keyword
(minProperties, maxProperties, ...), it is classified as "validation without a type" and silently
dropped from allOf
. Every model that inherits it loses those properties.

There is no error and no warning — the generated model is simply missing fields, which breaks the JSON
contract at runtime.

Omitting type: object next to properties is very common in 3.0 specs, so this is easy to hit by accident.

openapi-generator version

7.25.0-SNAPSHOT, built from master at commit 4aed9c1c635.

OpenAPI declaration file content or url
openapi: 3.0.3
info: { title: t, version: 1.0.0 }
paths:
  /x:
    get:
      operationId: getX
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Child" }
components:
  schemas:
    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 }
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
  -i spec.yaml -g typescript-fetch -o out

typescript-fetch is only used for a short reproduction. The member is removed in OpenAPINormalizer,
so this is generator-agnostic.

Steps to reproduce
  1. Save the spec above as spec.yaml
  2. Run the command above
  3. Look at out/models/Child.ts

Actual output

export interface Child {
    gamma?: string;
}

alpha and beta are gone. Exit code is 0; nothing is logged at default verbosity.

Expected output

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

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

Suggest a fix

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

https://github.com/OpenAPITools/openapi-generator/blob/4aed9c1c635/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java#L2724

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 — meaning any 3.0 schema with
a validation keyword and no explicit type is judged unsupported, including plain models.

Requiring that the schema also has no properties (and checking getType() as well, so the 3.0 case is
recognised at all) fixes it: a schema with properties is a model, not bare validation.

I have a patch with a regression test ready and will open a PR shortly.

Related issues/PRs

Searched open and closed issues/PRs for isUnsupportedSchema, removeUnsupportedSchemasFromAllOf, and
allOf members losing properties; I could not find an existing report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions