Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(catalog): Load required fields for Expressions, Data-formats and Load-balancers #1548

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading