From 3167a415ad6d6dbc2c7b28bc005cf48c6089c9c0 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Fri, 4 Nov 2022 13:32:10 +0000 Subject: [PATCH] Remove ignored_fields from JObject --- .../fabric8/java/generator/nodes/JObject.java | 33 +++++++------------ .../java/generator/CompilationTest.java | 2 +- .../fabric8/java/generator/GeneratorTest.java | 33 +++++++++++++++++++ 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java index eaf67a63674..6d783ce7d5f 100644 --- a/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java +++ b/java-generator/core/src/main/java/io/fabric8/java/generator/nodes/JObject.java @@ -37,15 +37,6 @@ public class JObject extends AbstractJSONSchema2Pojo implements JObjectExtraAnnotations { - private static final Set IGNORED_FIELDS = new HashSet<>(); - - static { - IGNORED_FIELDS.add("description"); - IGNORED_FIELDS.add("schema"); - IGNORED_FIELDS.add("example"); - IGNORED_FIELDS.add("examples"); - } - private final String type; private final String className; private final String pkg; @@ -97,19 +88,17 @@ public JObject( } for (Map.Entry field : fields.entrySet()) { - if (!IGNORED_FIELDS.contains(field.getKey())) { - String nextPrefix = (config.getPrefixStrategy() == Config.Prefix.ALWAYS) ? classPrefix : ""; - String nextSuffix = (config.getSuffixStrategy() == Config.Suffix.ALWAYS) ? classSuffix : ""; - this.fields.put( - field.getKey(), - AbstractJSONSchema2Pojo.fromJsonSchema( - field.getKey(), - field.getValue(), - nextPackagePath, - nextPrefix, - nextSuffix, - config)); - } + String nextPrefix = (config.getPrefixStrategy() == Config.Prefix.ALWAYS) ? classPrefix : ""; + String nextSuffix = (config.getSuffixStrategy() == Config.Suffix.ALWAYS) ? classSuffix : ""; + this.fields.put( + field.getKey(), + AbstractJSONSchema2Pojo.fromJsonSchema( + field.getKey(), + field.getValue(), + nextPackagePath, + nextPrefix, + nextSuffix, + config)); } } } diff --git a/java-generator/core/src/test/java/io/fabric8/java/generator/CompilationTest.java b/java-generator/core/src/test/java/io/fabric8/java/generator/CompilationTest.java index 9677fbb9d21..52b155a4621 100644 --- a/java-generator/core/src/test/java/io/fabric8/java/generator/CompilationTest.java +++ b/java-generator/core/src/test/java/io/fabric8/java/generator/CompilationTest.java @@ -209,7 +209,7 @@ void testKameletCRDCompiles() throws Exception { // Assert assertTrue(compilation.errors().isEmpty()); - assertEquals(13, compilation.sourceFiles().size()); + assertEquals(16, compilation.sourceFiles().size()); assertEquals(Compilation.Status.SUCCESS, compilation.status()); } diff --git a/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java b/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java index d18c10c6c36..9c3d09ed7d3 100644 --- a/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java +++ b/java-generator/core/src/test/java/io/fabric8/java/generator/GeneratorTest.java @@ -664,6 +664,39 @@ void testObjectWithPreservedFields() { assertTrue(clzT.get().getFieldByName("additionalProperties").isPresent()); } + @Test + void testObjectWithSpecialFieldNames() { + // Arrange + Map props = new HashMap<>(); + JSONSchemaProps newObj = new JSONSchemaProps(); + newObj.setType("string"); + props.put("description", newObj); + + JObject obj = new JObject( + null, + "t", + props, + null, + false, + "", + "", + defaultConfig, + null, + Boolean.FALSE, + null); + + // Act + GeneratorResult res = obj.generateJava(); + + // Assert + assertEquals(1, res.getTopLevelClasses().size()); + assertEquals("T", res.getTopLevelClasses().get(0).getName()); + + Optional clzT = res.getTopLevelClasses().get(0).getCompilationUnit().getClassByName("T"); + assertTrue(clzT.isPresent()); + assertTrue(clzT.get().getFieldByName("description").isPresent()); + } + @Test void testObjectNullableFieldsManagement() { // Arrange