forked from loafle/openapi-generator-original
parent
9fa9b115e3
commit
05a2f4b240
@ -1166,11 +1166,13 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
// TODO better logic to handle compose schema
|
// TODO better logic to handle compose schema
|
||||||
if (schema instanceof ComposedSchema) { // composed schema
|
if (schema instanceof ComposedSchema) { // composed schema
|
||||||
ComposedSchema cs = (ComposedSchema) schema;
|
ComposedSchema cs = (ComposedSchema) schema;
|
||||||
for (Schema s : cs.getAllOf()) {
|
if(cs.getAllOf() != null) {
|
||||||
if (s != null) {
|
for (Schema s : cs.getAllOf()) {
|
||||||
// using the first schema defined in allOf
|
if (s != null) {
|
||||||
schema = s;
|
// using the first schema defined in allOf
|
||||||
break;
|
schema = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,4 +202,16 @@ public class DefaultCodegenTest {
|
|||||||
Assert.assertEquals(co.produces.size(), 1);
|
Assert.assertEquals(co.produces.size(), 1);
|
||||||
Assert.assertEquals(co.produces.get(0).get("mediaType"), "application/json");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user