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

[DON'T MERGE] feat(Form): Support anyOf & oneOf #1939

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d57b3f0
feat(Form): Support anyOf & oneOf
lordrip Jan 15, 2025
6d3e959
feat(Form): support PasswordField
tplevko Jan 24, 2025
e518184
chore: Show `DisabledField` for ArrayFields
lordrip Jan 24, 2025
2a2fbc3
chore: Add omitFields support
lordrip Jan 24, 2025
8e515de
fix(CanvasForm): Avoid rerender CanvasForm
lordrip Jan 24, 2025
d57d61e
feat(Form): Give priority to matching model and schema types
lordrip Jan 27, 2025
2b9d1dc
chore: Fix lint and build
lordrip Jan 27, 2025
b0aa319
feat(Form): Clean current schema after switching to another schema
lordrip Jan 27, 2025
8e05a80
feat(Form): Add ArrayField
lordrip Jan 27, 2025
8157dc7
Feat: Added new EIPGenerator
lordrip Jan 15, 2025
060d0e7
chore: Improve single property schema naming
lordrip Jan 28, 2025
fe36256
feat(Catalog): Remove simple string schemas in favor of complex ones
lordrip Jan 28, 2025
8c027e5
feat(Catalog): Add CamelCatalogSchemaEnhancer
lordrip Jan 28, 2025
e334242
chore(tests): Cache JavaType to Camel model map
lordrip Jan 29, 2025
43f72c1
feat(Catalog): Add group/label information
lordrip Jan 29, 2025
b9a42de
Fix(EIP_Generator): Sorting root properties and definitions propertie…
shivamG640 Jan 29, 2025
c6743e2
Fix(Catalog): Restrict group information for empty EIP properties
shivamG640 Jan 29, 2025
92da3c1
feat(Form): Add EnumField
tplevko Jan 30, 2025
ad24c43
Fix(Catalog): Add Bean information on EIP Properties
shivamG640 Jan 30, 2025
a03ee95
chore: extract capitalize functionality to separate function
lordrip Jan 31, 2025
cad1652
feat(Form): Add property filtering and grouping
lordrip Jan 31, 2025
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
Prev Previous commit
Next Next commit
feat(Catalog): Add group/label information
  • Loading branch information
lordrip committed Jan 29, 2025
commit 43f72c1aecabd874ec907faa3a15ae8caf7aa9d8
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.apache.camel.catalog.CamelCatalog;
import org.apache.camel.tooling.model.EipModel;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.*;

public class CamelCatalogSchemaEnhancer {

private final CamelCatalog camelCatalog;
private final Map<String, String> JAVA_TYPE_TO_MODEL_NAME = new LinkedHashMap<>();
private final Map<String, String> JAVA_TYPE_TO_MODEL_NAME = new HashMap<>();

public CamelCatalogSchemaEnhancer(CamelCatalog camelCatalog) {
this.camelCatalog = camelCatalog;
Expand Down Expand Up @@ -101,6 +99,54 @@ void sortPropertiesAccordingToCatalog(EipModel model, ObjectNode modelNode) {
// TODO: Sort properties according to the Camel catalog
}

/**
* Fill the group/label information of the model in the schema
*
* @param modelName the name of the Camel model
* @param modelNode the JSON schema node of the model
*/
void fillGroupInformation(String modelName, ObjectNode modelNode) {
EipModel model = camelCatalog.eipModel(modelName);
if (model == null) {
return;
}

fillGroupInformation(model, modelNode);
}

/**
* Fill the group/label information of the model in the schema
*
* @param model the Camel model
* @param modelNode the JSON schema node of the model
*/
void fillGroupInformation(EipModel model, ObjectNode modelNode) {
List<EipModel.EipOptionModel> modelOptions = model.getOptions();

modelNode.withObject("properties").fields().forEachRemaining(entry -> {
String propertyName = entry.getKey();

Optional<EipModel.EipOptionModel> modelOption =
modelOptions.stream().filter(option -> option.getName().equals(propertyName)).findFirst();
if (modelOption.isEmpty()) {
return;
}

String group =
modelOption.get().getGroup() != null ? modelOption.get().getGroup() : modelOption.get().getLabel();
if (group == null) {
return;
}

ObjectNode propertyNode = (ObjectNode) entry.getValue();
if (propertyNode.has("$comment")) {
propertyNode.put("$comment", propertyNode.get("$comment").asText() + "|group:" + group);
} else {
propertyNode.put("$comment", "group:" + group);
}
});
}

/**
* Get the Camel model by its Java type
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ public Map<String, ObjectNode> generate() {

camelCatalogSchemaEnhancer.fillRequiredPropertiesIfNeeded(eipName, eipJSONSchema);
camelCatalogSchemaEnhancer.sortPropertiesAccordingToCatalog(eipName, eipJSONSchema);
camelCatalogSchemaEnhancer.fillGroupInformation(eipName, eipJSONSchema);
iterateOverDefinitions(eipJSONSchema.withObject("definitions"), (model, node) -> {
if (model == null) {
return;
}

camelCatalogSchemaEnhancer.fillRequiredPropertiesIfNeeded(model, node);
camelCatalogSchemaEnhancer.sortPropertiesAccordingToCatalog(model, node);
camelCatalogSchemaEnhancer.fillGroupInformation(model, node);
});

eipMap.put(eipName, eipJSON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,43 @@ void shouldFillRequiredPropertiesIfNeededForModel() {
assertTrue(requiredProperties.contains("expression"));
}

@Test
void shouldFillGroupInformationForModelName() {
var choiceNode = camelYamlDslSchema
.withObject("items")
.withObject("definitions")
.withObject("org.apache.camel.model.ChoiceDefinition");

EipModel model = camelCatalog.eipModel("choice");
camelCatalogSchemaEnhancer.fillGroupInformation(model, choiceNode);

var idPropertyNode = choiceNode.withObject("properties").withObject("id");
var preconditionPropertyNode = choiceNode.withObject("properties").withObject("precondition");

assertTrue(idPropertyNode.has("$comment"));
assertTrue(preconditionPropertyNode.has("$comment"));
assertEquals("group:common", idPropertyNode.get("$comment").asText());
assertEquals("group:advanced", preconditionPropertyNode.get("$comment").asText());
}

@Test
void shouldFillGroupInformationForMode() {
var choiceNode = camelYamlDslSchema
.withObject("items")
.withObject("definitions")
.withObject("org.apache.camel.model.ChoiceDefinition");

camelCatalogSchemaEnhancer.fillGroupInformation("choice", choiceNode);

var idPropertyNode = choiceNode.withObject("properties").withObject("id");
var preconditionPropertyNode = choiceNode.withObject("properties").withObject("precondition");

assertTrue(idPropertyNode.has("$comment"));
assertTrue(preconditionPropertyNode.has("$comment"));
assertEquals("group:common", idPropertyNode.get("$comment").asText());
assertEquals("group:advanced", preconditionPropertyNode.get("$comment").asText());
}

@Test
void shouldGetCamelModelByJavaType() {
EipModel setHeaderModel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class EIPGeneratorTest {
Expand Down Expand Up @@ -94,8 +95,7 @@ void shouldFillRequiredPropertiesFromSchemaIfNeeded() {
void shouldFillRequiredPropertiesFromDefinitionsIfNeeded() {
var eipsMap = eipGenerator.generate();

ObjectNode definitions =
eipsMap.get("setHeader").withObject("propertiesSchema").withObject("definitions");
ObjectNode definitions = eipsMap.get("setHeader").withObject("propertiesSchema").withObject("definitions");

assertTrue(definitions.has("org.apache.camel.model.language.ConstantExpression"));
assertTrue(definitions.withObject("org.apache.camel.model.language.ConstantExpression").has("required"));
Expand All @@ -111,4 +111,32 @@ void shouldFillRequiredPropertiesFromDefinitionsIfNeeded() {
.forEachRemaining(item -> simpleExpressionRequired.add(item.asText()));
assertTrue(simpleExpressionRequired.contains("expression"));
}

@Test
void shouldFillGroupInformation() {
var eipsMap = eipGenerator.generate();

var setHeaderNode = eipsMap.get("setHeader");
var namePropertyNode = setHeaderNode.withObject("propertiesSchema").withObject("properties").withObject("name");

assertTrue(namePropertyNode.has("$comment"));
assertEquals("group:common", namePropertyNode.get("$comment").asText());
}

@Test
void shouldFillGroupInformationFromDefinitions() {
var eipsMap = eipGenerator.generate();

var setHeaderNode = eipsMap.get("setHeader");
var expressionPropertiesNode = setHeaderNode.withObject("propertiesSchema").withObject("definitions")
.withObject("org.apache.camel.model.language.SimpleExpression").withObject("properties");

var expressionPropertyNode = expressionPropertiesNode.withObject("expression");
var trimPropertyNode = expressionPropertiesNode.withObject("trim");

assertTrue(expressionPropertyNode.has("$comment"));
assertTrue(trimPropertyNode.has("$comment"));
assertEquals("group:common", expressionPropertyNode.get("$comment").asText());
assertEquals("group:advanced", trimPropertyNode.get("$comment").asText());
}
}
Loading