mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
Fix ClassCastException in OpenAPINormalizer on composed schemas in 3.1 (#17912)
This commit is contained in:
@@ -458,33 +458,31 @@ public class OpenAPINormalizer {
|
||||
} 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) {
|
||||
|
||||
@@ -467,4 +467,12 @@ public class OpenAPINormalizerTest {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user