Skip to content

Commit

Permalink
Remove ignored_fields from JObject
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP authored and manusa committed Nov 8, 2022
1 parent 1faf6b5 commit 3167a41
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@

public class JObject extends AbstractJSONSchema2Pojo implements JObjectExtraAnnotations {

private static final Set<String> 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;
Expand Down Expand Up @@ -97,19 +88,17 @@ public JObject(
}

for (Map.Entry<String, JSONSchemaProps> 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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,39 @@ void testObjectWithPreservedFields() {
assertTrue(clzT.get().getFieldByName("additionalProperties").isPresent());
}

@Test
void testObjectWithSpecialFieldNames() {
// Arrange
Map<String, JSONSchemaProps> 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<ClassOrInterfaceDeclaration> clzT = res.getTopLevelClasses().get(0).getCompilationUnit().getClassByName("T");
assertTrue(clzT.isPresent());
assertTrue(clzT.get().getFieldByName("description").isPresent());
}

@Test
void testObjectNullableFieldsManagement() {
// Arrange
Expand Down

0 comments on commit 3167a41

Please sign in to comment.