Skip to content

Commit

Permalink
less complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP authored and manusa committed Dec 24, 2021
1 parent b207298 commit 0d58835
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,7 @@ private T internalFromImpl(String name, TypeRef typeRef, Set<String> visited) {
.toArray(JsonNode[]::new);
return enumProperty(enumValues);
} else {
if (!resolving) {
visited.clear();
resolving = true;
} else {
String visitedName = name + ":" + classRef;
if (!def.getFullyQualifiedName().startsWith("java") && visited.contains(visitedName)) {
throw new IllegalArgumentException("Found a cyclic reference involving the field " + name + " of type " + classRef.getFullyQualifiedName());
}
visited.add(visitedName);
}

T res = internalFromImpl(def, visited);
resolving = false;
return res;
return resolveNestedClass(name, def, visited);
}

}
Expand All @@ -441,6 +428,23 @@ private T internalFromImpl(String name, TypeRef typeRef, Set<String> visited) {
// Flag to detect cycles
private boolean resolving = false;

private T resolveNestedClass(String name, TypeDef def, Set<String> visited) {
if (!resolving) {
visited.clear();
resolving = true;
} else {
String visitedName = name + ":" + def.getFullyQualifiedName();
if (!def.getFullyQualifiedName().startsWith("java") && visited.contains(visitedName)) {
throw new IllegalArgumentException("Found a cyclic reference involving the field " + name + " of type " + def.getFullyQualifiedName());
}
visited.add(visitedName);
}

T res = internalFromImpl(def, visited);
resolving = false;
return res;
}

/**
* Builds the schema for specifically handled property types (e.g. intOrString properties)
*
Expand Down

0 comments on commit 0d58835

Please sign in to comment.