fix: keep allOf members that have properties alongside a validation keyword
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
referencingParentsurvives normalization. Verified that this test fails without the fix
(the whole allOf was dropped, so Child lost the inherited properties).- Full
OpenAPINormalizerTest(64 tests) andModelUtilsTest(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.sh— no 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:
Commit all changed files../mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
(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 next to a validation keyword but omits type: object. Child models now inherit those properties, preserving the JSON contract.
- Bug Fixes
- Updated
ModelUtils.isUnsupportedSchema()to only treat a schema as validation-only when bothgetTypes()(OAS 3.1) andgetType()(OAS 3.0) are null, it has validation keywords, and it has noproperties. - Added
OpenAPINormalizerTest.testAllOfMemberWithValidationAndPropertiesIsKeptwith a 3.0 sample; tests pass and regenerating samples shows no diffs.
- Updated