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 @@ -4215,12 +4215,12 @@ public static Set<String> getProducesInfo(OpenAPI openAPI, Operation operation)

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,16 @@ public void testDiscriminatorWithCustomMapping() {
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();
Expand Down
4 changes: 2 additions & 2 deletions modules/openapi-generator/src/test/resources/3_0/allOf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'