Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ClassCastException in OpenAPINormalizer on composed schemas #17912

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -458,33 +458,31 @@ public Schema normalizeSchema(Schema schema, Set<Schema> visitedSchemas) {
} else if (ModelUtils.isAllOf(schema)) { // allOf
return normalizeAllOf(schema, visitedSchemas);
} else if (ModelUtils.isComposedSchema(schema)) { // composed schema
ComposedSchema cs = (ComposedSchema) schema;

if (ModelUtils.isComplexComposedSchema(cs)) {
cs = (ComposedSchema) normalizeComplexComposedSchema(cs, visitedSchemas);
if (ModelUtils.isComplexComposedSchema(schema)) {
schema = normalizeComplexComposedSchema(schema, visitedSchemas);
}

if (cs.getAllOf() != null && !cs.getAllOf().isEmpty()) {
return normalizeAllOf(cs, visitedSchemas);
if (schema.getAllOf() != null && !schema.getAllOf().isEmpty()) {
return normalizeAllOf(schema, visitedSchemas);
}

if (cs.getOneOf() != null && !cs.getOneOf().isEmpty()) {
return normalizeOneOf(cs, visitedSchemas);
if (schema.getOneOf() != null && !schema.getOneOf().isEmpty()) {
return normalizeOneOf(schema, visitedSchemas);
}

if (cs.getAnyOf() != null && !cs.getAnyOf().isEmpty()) {
return normalizeAnyOf(cs, visitedSchemas);
if (schema.getAnyOf() != null && !schema.getAnyOf().isEmpty()) {
return normalizeAnyOf(schema, visitedSchemas);
}

if (cs.getProperties() != null && !cs.getProperties().isEmpty()) {
normalizeProperties(cs.getProperties(), visitedSchemas);
if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
normalizeProperties(schema.getProperties(), visitedSchemas);
}

if (cs.getAdditionalProperties() != null) {
if (schema.getAdditionalProperties() != null) {
// normalizeAdditionalProperties(m);
}

return cs;
return schema;
} else if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
normalizeProperties(schema.getProperties(), visitedSchemas);
} else if (schema instanceof BooleanSchema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,12 @@ public void testFilter() {
assertEquals(openAPI.getPaths().get("/person/display/{personId}").getDelete().getExtensions().get("x-internal"), false);
assertEquals(openAPI.getPaths().get("/person/display/{personId}").getPut().getExtensions().get("x-internal"), true);
}
}

@Test
public void testComposedSchemaDoesNotThrow() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_1/composed-schema.yaml");

OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, Collections.emptyMap());
openAPINormalizer.normalize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.1.0
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/payment:
post:
operationId: payment
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Payment"

components:
schemas:
Payment:
type: object
properties:
label:
type: string
otherLabel:
type: string
amount:
type: number
oneOf:
- required:
- label
- amount
- required:
- otherLabel
- amount
Loading