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,12 +4215,12 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
|
||||
if (composedSchema.getAllOf() != null && !composedSchema.getAllOf().isEmpty()) {
|
||||
Schema schema = composedSchema.getAllOf().get(0);
|
||||
String ref = schema.get$ref();
|
||||
if (StringUtils.isBlank(ref)) {
|
||||
return null;
|
||||
for (Schema schema : composedSchema.getAllOf()) {
|
||||
String ref = schema.get$ref();
|
||||
if (!StringUtils.isBlank(ref)) {
|
||||
return ModelUtils.getSimpleRef(ref);
|
||||
}
|
||||
}
|
||||
return ModelUtils.getSimpleRef(ref);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -453,6 +453,16 @@ public class DefaultCodegenTest {
|
||||
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
|
||||
public void testCallbacks() {
|
||||
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/3_0/callbacks.yaml", null, new ParseOptions()).getOpenAPI();
|
||||
|
@ -53,9 +53,9 @@ components:
|
||||
Child:
|
||||
description: A representation of a child
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/Person'
|
||||
- type: object
|
||||
properties:
|
||||
age:
|
||||
type: integer
|
||||
format: int32
|
||||
format: int32
|
||||
- $ref: '#/components/schemas/Person'
|
||||
|
Loading…
x
Reference in New Issue
Block a user