forked from loafle/openapi-generator-original
Improve "allOf" support (#1169)
* Add test case which reproduces issue340 * Take the first $ref we find in the allOf-List
This commit is contained in:
parent
aa31e42ce7
commit
a1d242595e
@ -4215,13 +4215,13 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
protected String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
protected String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
||||||
if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) {
|
if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) {
|
||||||
Schema schema = composedSchema.getAllOf().get(0);
|
for (Schema schema : composedSchema.getAllOf()) {
|
||||||
String ref = schema.get$ref();
|
String ref = schema.get$ref();
|
||||||
if (StringUtils.isBlank(ref)) {
|
if (!StringUtils.isBlank(ref)) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return ModelUtils.getSimpleRef(ref);
|
return ModelUtils.getSimpleRef(ref);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,6 +453,16 @@ public class DefaultCodegenTest {
|
|||||||
verifyPersonDiscriminator(personModel.discriminator);
|
verifyPersonDiscriminator(personModel.discriminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParentName() {
|
||||||
|
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/allOf.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
|
||||||
|
Schema child = openAPI.getComponents().getSchemas().get("Child");
|
||||||
|
CodegenModel childModel = codegen.fromModel("Child", child, openAPI.getComponents().getSchemas());
|
||||||
|
Assert.assertEquals(childModel.parentSchema, "Person");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCallbacks() {
|
public void testCallbacks() {
|
||||||
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/callbacks.yaml", null, new ParseOptions()).getOpenAPI();
|
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/callbacks.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
@ -53,9 +53,9 @@ components:
|
|||||||
Child:
|
Child:
|
||||||
description: A representation of a child
|
description: A representation of a child
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/Person'
|
|
||||||
- type: object
|
- type: object
|
||||||
properties:
|
properties:
|
||||||
age:
|
age:
|
||||||
type: integer
|
type: integer
|
||||||
format: int32
|
format: int32
|
||||||
|
- $ref: '#/components/schemas/Person'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user