From 0d588357e0afe6899a2e584d404b1eae3afadc85 Mon Sep 17 00:00:00 2001 From: andreaTP Date: Tue, 21 Dec 2021 18:34:18 +0000 Subject: [PATCH] less complexity --- .../crd/generator/AbstractJsonSchema.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java b/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java index 5f77ee775bb..b1463c32b2c 100644 --- a/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java +++ b/crd-generator/api/src/main/java/io/fabric8/crd/generator/AbstractJsonSchema.java @@ -416,20 +416,7 @@ private T internalFromImpl(String name, TypeRef typeRef, Set 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); } } @@ -441,6 +428,23 @@ private T internalFromImpl(String name, TypeRef typeRef, Set visited) { // Flag to detect cycles private boolean resolving = false; + private T resolveNestedClass(String name, TypeDef def, Set 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) *