Skip to content

Commit b207298

Browse files
andreaTPmanusa
authored andcommitted
more edge cases
1 parent e463dc4 commit b207298

File tree

5 files changed

+190
-191
lines changed

5 files changed

+190
-191
lines changed

crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,20 @@ private T internalFromImpl(String name, TypeRef typeRef, Set<String> visited) {
416416
.toArray(JsonNode[]::new);
417417
return enumProperty(enumValues);
418418
} else {
419-
String visitedName = def.getFullyQualifiedName() + "-" + name;
420-
if (!def.getFullyQualifiedName().startsWith("java") && visited.contains(visitedName)) {
421-
throw new IllegalArgumentException("Found a cyclic reference involving the field " + name + " of type " + def.getFullyQualifiedName());
419+
if (!resolving) {
420+
visited.clear();
421+
resolving = true;
422+
} else {
423+
String visitedName = name + ":" + classRef;
424+
if (!def.getFullyQualifiedName().startsWith("java") && visited.contains(visitedName)) {
425+
throw new IllegalArgumentException("Found a cyclic reference involving the field " + name + " of type " + classRef.getFullyQualifiedName());
426+
}
427+
visited.add(visitedName);
422428
}
423-
visited.add(visitedName);
424-
return internalFromImpl(def, visited);
429+
430+
T res = internalFromImpl(def, visited);
431+
resolving = false;
432+
return res;
425433
}
426434

427435
}
@@ -430,6 +438,9 @@ private T internalFromImpl(String name, TypeRef typeRef, Set<String> visited) {
430438
}
431439
}
432440

441+
// Flag to detect cycles
442+
private boolean resolving = false;
443+
433444
/**
434445
* Builds the schema for specifically handled property types (e.g. intOrString properties)
435446
*

crd-generator/api/src/test/java/io/fabric8/crd/example/cyclic/CyclicStatus.java

-8
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,4 @@
1717

1818
public class CyclicStatus {
1919
private String message;
20-
21-
public String getMessage() {
22-
return message;
23-
}
24-
25-
public void setMessage(String message) {
26-
this.message = message;
27-
}
2820
}

crd-generator/api/src/test/java/io/fabric8/crd/example/nocyclic/NoCyclicStatus.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,5 @@
1717

1818
public class NoCyclicStatus {
1919
private String message;
20-
// private Ref ref1;
21-
22-
public String getMessage() {
23-
return message;
24-
}
25-
26-
public void setMessage(String message) {
27-
this.message = message;
28-
}
20+
private Ref ref1;
2921
}

crd-generator/api/src/test/java/io/fabric8/crd/example/nocyclic/Ref.java

+4
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ public class Ref {
1919

2020
private int ref;
2121

22+
protected Inner inner;
23+
24+
public static class Inner { }
25+
2226
}

0 commit comments

Comments
 (0)