Skip to content

Commit 5d2fab6

Browse files
committed
Improve hasParent -> isParentReferencedInChild
1 parent befa7fa commit 5d2fab6

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ protected void ensureInheritanceForDiscriminatorMappings(Schema parent, Schema c
17591759
String reference = "#/components/schemas/" + parentName;
17601760
List<Schema> allOf = child.getAllOf();
17611761
if (allOf != null) {
1762-
if (hasParent(parent, child, reference, visitedSchemas)) {
1762+
if (isParentReferencedInChild(parent, child, reference, visitedSchemas)) {
17631763
// already done, so no need to add
17641764
return;
17651765
}
@@ -1784,22 +1784,22 @@ protected void ensureInheritanceForDiscriminatorMappings(Schema parent, Schema c
17841784
/**
17851785
* return true if the child as an allOf referencing the parent schema.
17861786
*/
1787-
private boolean hasParent(Schema parent, Schema child, String reference, Set<Schema> visitedSchemas) {
1787+
private boolean isParentReferencedInChild(Schema parent, Schema child, String reference, Set<Schema> visitedSchemas) {
17881788
if (child == null || visitedSchemas.contains(child)) {
17891789
return false;
17901790
}
1791-
visitedSchemas.add(child);
17921791
if (child.get$ref() != null && child.get$ref().equals(reference)) {
17931792
return true;
17941793
}
17951794
child = ModelUtils.getReferencedSchema(openAPI, child);
1795+
if (visitedSchemas.contains(child)) {
1796+
return false;
1797+
}
1798+
visitedSchemas.add(child);
17961799
List<Schema> allOf = child.getAllOf();
17971800
if (allOf != null) {
17981801
for (Schema schema : allOf) {
1799-
if (visitedSchemas.contains(schema)) {
1800-
return false;
1801-
}
1802-
if (hasParent(parent, schema, reference, visitedSchemas)) {
1802+
if (isParentReferencedInChild(parent, schema, reference, visitedSchemas)) {
18031803
return true;
18041804
}
18051805
}

0 commit comments

Comments
 (0)