Skip to content
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 @@ -1166,11 +1166,13 @@ public String getSchemaType(Schema schema) {
// TODO better logic to handle compose schema
if (schema instanceof ComposedSchema) { // composed schema
ComposedSchema cs = (ComposedSchema) schema;
for (Schema s : cs.getAllOf()) {
if (s != null) {
// using the first schema defined in allOf
schema = s;
break;
if(cs.getAllOf() != null) {
for (Schema s : cs.getAllOf()) {
if (s != null) {
// using the first schema defined in allOf
schema = s;
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,16 @@ public void testEnsureNoDuplicateProduces() {
Assert.assertEquals(co.produces.size(), 1);
Assert.assertEquals(co.produces.get(0).get("mediaType"), "application/json");
}

@Test
public void testGetSchemaTypeWithComposedSchemaWithOneOf() {
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/composed-oneof.yaml", null, new ParseOptions()).getOpenAPI();
final DefaultCodegen codegen = new DefaultCodegen();

Operation operation = openAPI.getPaths().get("/state").getPost();
Schema schema = ModelUtils.getSchemaFromRequestBody(operation.getRequestBody());
String type = codegen.getSchemaType(schema);

Assert.assertNotNull(type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
openapi: 3.0.1
info:
title: oneOf test
version: '1.0'
servers:
- url: 'http://localhost:8000/'
paths:
/state:
get:
operationId: getState
responses:
'200':
description: OK
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/ObjA'
- $ref: '#/components/schemas/ObjB'
discriminator:
propertyName: realtype
mapping:
a-type: '#/components/schemas/ObjA'
b-type: '#/components/schemas/ObjB'
post:
operationId: createState
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/ObjA'
- $ref: '#/components/schemas/ObjB'
discriminator:
propertyName: realtype
mapping:
a-type: '#/components/schemas/ObjA'
b-type: '#/components/schemas/ObjB'
required: true
responses:
'201':
description: OK
components:
schemas:
ObjA:
type: object
properties:
realtype:
type: string
message:
type: string
ObjB:
type: object
properties:
realtype:
type: string
description:
type: string
code:
type: integer
format: int32