Skip to content

Commit

Permalink
more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP authored and manusa committed Dec 24, 2021
1 parent e463dc4 commit b207298
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,20 @@ private T internalFromImpl(String name, TypeRef typeRef, Set<String> visited) {
.toArray(JsonNode[]::new);
return enumProperty(enumValues);
} else {
String visitedName = def.getFullyQualifiedName() + "-" + name;
if (!def.getFullyQualifiedName().startsWith("java") && visited.contains(visitedName)) {
throw new IllegalArgumentException("Found a cyclic reference involving the field " + name + " of type " + def.getFullyQualifiedName());
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);
}
visited.add(visitedName);
return internalFromImpl(def, visited);

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

}
Expand All @@ -430,6 +438,9 @@ private T internalFromImpl(String name, TypeRef typeRef, Set<String> visited) {
}
}

// Flag to detect cycles
private boolean resolving = false;

/**
* Builds the schema for specifically handled property types (e.g. intOrString properties)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,4 @@

public class CyclicStatus {
private String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,5 @@

public class NoCyclicStatus {
private String message;
// private Ref ref1;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
private Ref ref1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public class Ref {

private int ref;

protected Inner inner;

public static class Inner { }

}
Loading

0 comments on commit b207298

Please sign in to comment.