Skip to content

Commit

Permalink
Fix(catalog): Expressions does not show input expression field as req…
Browse files Browse the repository at this point in the history
…uired
  • Loading branch information
shivamG640 committed Oct 10, 2024
1 parent f95f50e commit 9ec6148
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ public String getDataFormatCatalog() throws Exception {
var json = JsonMapper.asJsonObject(dataFormatCatalog).toJson();
var catalogTree = (ObjectNode) jsonMapper.readTree(json);
catalogTree.set("propertiesSchema", dataFormatSchema);
// setting required property to all the dataformats schema
setRequiredToPropertiesSchema(dataFormatSchema, catalogTree);
answer.set(dataFormatName, catalogTree);
}
StringWriter writer = new StringWriter();
Expand Down Expand Up @@ -267,6 +269,8 @@ public String getLanguageCatalog() throws Exception {
var json = JsonMapper.asJsonObject(languageCatalog).toJson();
var catalogTree = (ObjectNode) jsonMapper.readTree(json);
catalogTree.set("propertiesSchema", languageSchema);
// setting required property to all the languages schema
setRequiredToPropertiesSchema(languageSchema, catalogTree);
answer.set(languageName, catalogTree);
}
StringWriter writer = new StringWriter();
Expand Down Expand Up @@ -709,11 +713,26 @@ public String getLoadBalancerCatalog() throws Exception {
var json = JsonMapper.asJsonObject(loadBalancerCatalog).toJson();
var catalogTree = (ObjectNode) jsonMapper.readTree(json);
catalogTree.set("propertiesSchema", loadBalancerSchema);
// setting required property to all the load-balancers schema
setRequiredToPropertiesSchema(loadBalancerSchema, catalogTree);
answer.set(loadBalancerName, catalogTree);
}
StringWriter writer = new StringWriter();
var jsonGenerator = new JsonFactory().createGenerator(writer).useDefaultPrettyPrinter();
jsonMapper.writeTree(jsonGenerator, answer);
return writer.toString();
}

private void setRequiredToPropertiesSchema(ObjectNode camelYamlDslSchema, ObjectNode catalogModel) {
List<String> required = new ArrayList<>();
var camelYamlDslProperties = camelYamlDslSchema.withObject("/properties").properties().stream()
.map(Map.Entry::getKey).toList();
for (var propertyName : camelYamlDslProperties) {
var catalogPropertySchema = catalogModel.withObject("/properties").withObject("/" + propertyName);
if (catalogPropertySchema.has("required") && catalogPropertySchema.get("required").asBoolean()) {
required.add(propertyName);
}
}
catalogModel.withObject("/propertiesSchema").set("required", jsonMapper.valueToTree(required));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public void testGetDataFormatCatalog() throws Exception {
assertEquals("Custom", customPropertiesSchema.get("title").asText());
var refProperty = customPropertiesSchema.withObject("/properties").withObject("/ref");
assertEquals("Ref", refProperty.get("title").asText());
var customPropertiesSchemaRequiredFields = customPropertiesSchema.withArray("/required");
assertFalse(customPropertiesSchemaRequiredFields.isEmpty());
assertEquals(1, customPropertiesSchemaRequiredFields.size(), "Size should be 1");
}

@Test
Expand All @@ -180,21 +183,26 @@ public void testDataFormatEnumParameter() throws Exception {
@Test
public void testGetLanguageCatalog() throws Exception {
assertFalse(languageCatalog.has("file"));
var customModel = languageCatalog
var languageModel = languageCatalog
.withObject("/language")
.withObject("/model");
assertEquals("model", customModel.get("kind").asText());
assertEquals("Language", customModel.get("title").asText());
var customProperties = languageCatalog
assertEquals("model", languageModel.get("kind").asText());
assertEquals("Language", languageModel.get("title").asText());
var languageProperties = languageCatalog
.withObject("/language")
.withObject("/properties");
assertEquals("Language", customProperties.withObject("/language").get("displayName").asText());
var customPropertiesSchema = languageCatalog
assertEquals("Language", languageProperties.withObject("/language").get("displayName").asText());
var languagePropertiesSchema = languageCatalog
.withObject("/language")
.withObject("/propertiesSchema");
assertEquals("Language", customPropertiesSchema.get("title").asText());
var languageProperty = customPropertiesSchema.withObject("/properties").withObject("/language");
assertEquals("Language", languagePropertiesSchema.get("title").asText());
var languageProperty = languagePropertiesSchema.withObject("/properties").withObject("/language");
assertEquals("Language", languageProperty.get("title").asText());
var languagePropertiesSchemaRequiredFields = languagePropertiesSchema.withArray("/required");
assertFalse(languagePropertiesSchemaRequiredFields.isEmpty());
assertEquals(2, languagePropertiesSchemaRequiredFields.size(), "Size should be 2");
assertEquals("expression", languagePropertiesSchemaRequiredFields.get(0).asText());
assertEquals("language", languagePropertiesSchemaRequiredFields.get(1).asText());
}

@Test
Expand Down Expand Up @@ -294,15 +302,25 @@ public void testGetLoadBalancerCatalog() throws Exception {
var failoverModel = loadBalancerCatalog.withObject("/failoverLoadBalancer/model");
assertEquals("failoverLoadBalancer", failoverModel.get("name").asText());
var failoverSchema = loadBalancerCatalog.withObject("/failoverLoadBalancer/propertiesSchema");
var failoverSchemaRequiredFields = failoverSchema.withArray("/required");
assertTrue(failoverSchemaRequiredFields.isEmpty());
var maximumFailoverAttempts = failoverSchema.withObject("/properties/maximumFailoverAttempts");
assertEquals("string", maximumFailoverAttempts.get("type").asText());
assertEquals("-1", maximumFailoverAttempts.get("default").asText());

var roundRobinSchema = loadBalancerCatalog.withObject("/roundRobinLoadBalancer/propertiesSchema");
var roundRobinSchemaRequiredFields = roundRobinSchema.withArray("/required");
assertTrue(roundRobinSchemaRequiredFields.isEmpty());
var roundRobinId = roundRobinSchema.withObject("/properties/id");
assertEquals("string", roundRobinId.get("type").asText());

var customModel = loadBalancerCatalog.withObject("/customLoadBalancer/model");
assertEquals("Custom Load Balancer", customModel.get("title").asText());
var customSchema = loadBalancerCatalog.withObject("/customLoadBalancer/propertiesSchema");
var customSchemaRequiredFields = customSchema.withArray("/required");
assertFalse(customSchemaRequiredFields.isEmpty());
assertEquals(1, customSchemaRequiredFields.size(), "Size should be 1");
assertEquals("ref", customSchemaRequiredFields.get(0).asText());
assertEquals("Custom Load Balancer", customSchema.get("title").asText());
var customRef = customSchema.withObject("/properties/ref");
assertEquals("Ref", customRef.get("title").asText());
Expand Down

0 comments on commit 9ec6148

Please sign in to comment.