Bug Report Checklist
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
- Save the spec above as
spec.yaml
- Run the command above
- 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.
Bug Report Checklist
Description
If a schema has
propertiesbut omitstype: object, and it also carries any validation keyword(
minProperties,maxProperties, ...), it is classified as "validation without a type" and silentlydropped 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: objectnext topropertiesis very common in 3.0 specs, so this is easy to hit by accident.openapi-generator version
7.25.0-SNAPSHOT, built frommasterat commit4aed9c1c635.OpenAPI declaration file content or url
Generation Details
typescript-fetchis only used for a short reproduction. The member is removed inOpenAPINormalizer,so this is generator-agnostic.
Steps to reproduce
spec.yamlout/models/Child.tsActual output
alphaandbetaare gone. Exit code is 0; nothing is logged at default verbosity.Expected output
Removing
minProperties: 2fromParent— or adding an explicittype: object— makes the propertiesreappear, 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
getTypes()is only populated for 3.1, so for a 3.0 spec it is always null — meaning any 3.0 schema witha validation keyword and no explicit type is judged unsupported, including plain models.
Requiring that the schema also has no
properties(and checkinggetType()as well, so the 3.0 case isrecognised 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, andallOf members losing properties; I could not find an existing report.