Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore allOf behaviour (model composition) for definition with a single schema reference #5977

Merged
merged 4 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -1104,9 +1104,9 @@ public static Header getHeader(OpenAPI openAPI, String name) {
public static Map<String, List<String>> getChildrenMap(OpenAPI openAPI) {
Map<String, Schema> allSchemas = getSchemas(openAPI);

// FIXME: The collect here will throw NPE if a spec document has only a single oneOf hierarchy.
Map<String, List<Entry<String, Schema>>> groupedByParent = allSchemas.entrySet().stream()
.filter(entry -> isComposedSchema(entry.getValue()))
.filter(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas)!=null)
Copy link
Contributor Author

@spacether spacether Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filtering prevents a NPE from happening when getParentName returns null, that's why I deleted the comment on line 1107 on the left. If I omit this filtering, the NPE is seen when we run our tests.

.collect(Collectors.groupingBy(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas)));

return groupedByParent.entrySet().stream()
Expand Down Expand Up @@ -1165,14 +1165,6 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
int nullSchemaChildrenCount = 0;
boolean hasAmbiguousParents = false;
List<String> refedWithoutDiscriminator = new ArrayList<>();
String schemaName = "";
for (String thisSchemaName : allSchemas.keySet()) {
Schema sc = allSchemas.get(thisSchemaName);
if (isComposedSchema(sc) && (ComposedSchema) sc == composedSchema) {
schemaName = thisSchemaName;
break;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted to original code


if (interfaces != null && !interfaces.isEmpty()) {
for (Schema schema : interfaces) {
Expand All @@ -1189,10 +1181,7 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
} else {
// not a parent since discriminator.propertyName is not set
hasAmbiguousParents = true;
boolean isNotExtractedInlineSchema = !parentName.equals(schemaName+"_allOf");
if (isNotExtractedInlineSchema) {
refedWithoutDiscriminator.add(parentName);
}
refedWithoutDiscriminator.add(parentName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted to original code

}
} else {
// not a ref, doing nothing, except counting the number of times the 'null' type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ public void testAllOfSingleRefWithOwnPropsNoDiscriminator() {
Schema schema = openAPI.getComponents().getSchemas().get("MessageEventCoreWithTimeListEntries");
codegen.setOpenAPI(openAPI);
CodegenModel model = codegen.fromModel("MessageEventCoreWithTimeListEntries", schema);
Assert.assertEquals(model.parent, "MessageEventCore");
Assert.assertEquals(model.allParents, Collections.singletonList("MessageEventCore"));
Assert.assertEquals(model.parent, null);
Assert.assertEquals(model.allParents, null);
}

@Test
Expand Down