Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
fix: don't lose examples on properties
Browse files Browse the repository at this point in the history
Fixes #714
  • Loading branch information
Delawen committed Jun 30, 2023
1 parent 5f0b26f commit f6b9008
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void beans() throws Exception {
@ValueSource(strings = {"Camel Route#route-multi.yaml", "KameletBinding#kamelet-binding-multi.yaml",
"Kamelet#eip.kamelet.yaml", "Kamelet#kamelet-multi.yaml", "Camel Route#rest-dsl-multi.yaml",
"Camel Route#route-with-beans.yaml", "Integration#integration.yaml",
"Integration#integration-multiroute.yaml"})
"Integration#integration-multiroute.yaml", "Kamelet#jms-amqp-10-source.kamelet.yaml"})
void roundTrip(String file) throws IOException {

String[] parameters = file.split("#");
Expand Down Expand Up @@ -469,7 +469,7 @@ void uniqueName() throws IOException {
@ValueSource(strings = {"Kamelet#eip.kamelet.yaml", "Integration#integration.yaml",
"Camel Route#route-with-beans.yaml", "Camel Route#rest-dsl-multi.yaml",
"KameletBinding#kamelet-binding.yaml", "Kamelet#kamelet2.yaml",
"Integration#integration-multiroute.yaml"})
"Integration#integration-multiroute.yaml", "Kamelet#jms-amqp-10-source.kamelet.yaml"})
void changeNameAndDescription(String file) throws IOException {

String[] parameters = file.split("#");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
annotations:
camel.apache.org/kamelet.icon: data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIi
camel.apache.org/kamelet.support.level: Stable
camel.apache.org/provider: Apache Software Foundation
camel.apache.org/catalog.version: 4.0.0-SNAPSHOT
camel.apache.org/kamelet.group: JMS
camel.apache.org/kamelet.namespace: Messaging
labels:
camel.apache.org/requires.runtime: camel-k
camel.apache.org/kamelet.type: source
name: jms-amqp-10-source
spec:
definition:
description: Consume data from any AMQP 1.0 compliant message broker
properties:
destinationType:
default: queue
description: The JMS destination type (queue or topic).
title: Destination Type
type: string
destinationName:
description: The JMS destination name.
title: Destination Name
type: string
remoteURI:
description: The JMS URL.
example: amqp://my-host:31616
title: Broker URL
type: string
required:
- destinationName
- remoteURI
title: JMS - AMQP 1.0 Source
type: object
dependencies:
- camel:jms
- camel:amqp
- camel:kamelet
- camel:core
template:
from:
uri: jms:{{destinationType}}:{{destinationName}}
parameters:
connectionFactory: '#bean:{{connectionFactoryBean}}'
steps:
- to:
uri: kamelet:sink
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ private static Step getRestParentStep() {
var parameters = new LinkedList<Parameter>();
final var path =
new StringParameter(Rest.PATH_LABEL, "Path of the endpoint",
"Path where this endpoint is listening.", null, null);
"Path where this endpoint is listening.", null, null, null,null, null);
parameters.add(path);
final var description =
new StringParameter(Rest.DESCRIPTION_LABEL, "Description of the endpoint",
"Human readable description of this endpoint.", null, null);
"Human readable description of this endpoint.", null, null, null,null, null);
parameters.add(description);
step.setParameters(parameters);
return step;
Expand Down
15 changes: 15 additions & 0 deletions kamelet-support/src/main/java/io/kaoto/backend/KamelPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,21 @@ private void setParameters(final List<Parameter> parameters, final Definition de
}
property.setTitle(p.getTitle());
property.setType(p.getType());
property.setNullable(p.getNullable());
if (p.getEnum() != null) {
var enumerable = new LinkedList<AnyType>();
for (var enumy : p.getEnum()) {
var anyType = new AnyType();
anyType.setValue(enumy);
enumerable.add(anyType);
}
property.set_enum(enumerable);
}
if (p.getExamples() != null && p.getExamples().length > 0) {
var example = new AnyType();
example.setValue(p.getExamples()[0]);
property.setExample(example);
}
def.getProperties().put(p.getId(), property);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public class KameletRepresenter extends Representer {
public static final String PARAMETERS = "parameters";
public static final String URI = "uri";
public static final String NAME = "name";
public static final String KIND = "kind";
public static final String API_VERSION = "apiVersion";

public KameletRepresenter() {
super(new DumperOptions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.fabric8.kubernetes.api.model.AnyType;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.kaoto.backend.api.metadata.catalog.StepCatalog;
import io.kaoto.backend.api.service.step.parser.StepParserService;
Expand Down Expand Up @@ -122,40 +123,67 @@ private void processParameters(final ParseResult<Step> res,
Parameter p;
switch (def.getType()) {
case "string":
p = new StringParameter(key, def.getTitle(),
p = new StringParameter(key,
def.getTitle(),
def.getDescription(),
def.getNullable(),
def.get_enum() != null ? def.get_enum().toArray(new String[]{}) : null,
def.getExample() != null ?
new String[]{String.valueOf(def.getExample().getValue())} :
null,
def.get_default() != null ?
String.valueOf(def.get_default().getValue()) : null,
def.getFormat());
break;
case "number":
p = new NumberParameter(key, def.getTitle(),
def.getDescription(),
def.getDescription(), def.getNullable(),
def.get_enum() != null ? def.get_enum().toArray(new Double[]{}) : null,
def.getExample() != null ?
new Number[]{Double.valueOf(String.valueOf(def.getExample().getValue()))} :
null,
def.get_default() != null ?
Double.valueOf(String.valueOf(def.get_default().getValue()))
: null);
break;
case "integer":
p = new IntegerParameter(key, def.getTitle(),
def.getDescription(),
def.getDescription(), def.getNullable(),
def.get_enum() != null ? def.get_enum().toArray(new Integer[]{}) : null,
def.getExample() != null ?
new Integer[]{Integer.valueOf(String.valueOf(def.getExample().getValue()))} :
null,
def.get_default() != null ?
Integer.valueOf(String.valueOf(def.get_default().getValue())) : null);
break;
case "boolean":
p = new BooleanParameter(key, def.getTitle(),
def.getDescription(),
def.getDescription(), def.getNullable(),
def.get_enum() != null ? def.get_enum().toArray(new Boolean[]{}) : null,
def.getExample() != null ?
new Boolean[]{Boolean.valueOf(String.valueOf(def.getExample().getValue()))} :
null,
def.get_default() != null ?
Boolean.valueOf(String.valueOf(def.get_default().getValue())) : null);
break;
case "array":
p = new ArrayParameter(key, def.getTitle(),
def.getDescription(),
def.getDescription(), def.getNullable(),
def.get_enum() != null ? def.get_enum().toArray(new Object[][]{}) : null,
def.getExample() != null ?
new Object[][]{ (Object[]) def.getExample().getValue()} :
null,
def.get_default() != null ?
String.valueOf(def.get_default().getValue()).split(",") :
null);
break;
default:
p = new ObjectParameter(key, def.getTitle(), def.getDescription(), def.get_default());
p = new ObjectParameter(key, def.getTitle(), def.getDescription(), def.getNullable(),
def.get_enum().toArray(new AnyType[0]),
def.getExample() != null ?
new Object[]{ def.getExample().getValue()} :
null,
def.get_default());
}
res.getParameters().add(p);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ private StringParameter getStringParameter(final ParameterEntry parameter) {
id,
parameterData.get(DISPLAY_NAME),
parameterData.get(DESCRIPTION),
null, null, null,
parameterData.getOrDefault(DEFAULT_VALUE, null),
null
);
Expand All @@ -259,6 +260,7 @@ private NumberParameter getNumberParameter(final ParameterEntry parameter) {
id,
parameterData.get(DISPLAY_NAME),
parameterData.get(DESCRIPTION),
null, null, null,
value
);
}
Expand All @@ -271,6 +273,7 @@ private ObjectParameter getObjectParameter(final ParameterEntry parameter) {
id,
parameterData.get(DISPLAY_NAME),
parameterData.get(DESCRIPTION),
null, null, null,
parameterData.getOrDefault(DEFAULT_VALUE, null)
);
}
Expand All @@ -283,6 +286,7 @@ private BooleanParameter getBooleanParameter(final ParameterEntry parameter) {
id,
parameterData.get(DISPLAY_NAME),
parameterData.get(DESCRIPTION),
null, null, null,
Boolean.parseBoolean(parameterData
.getOrDefault(DEFAULT_VALUE, "false"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,22 @@ private Parameter getParameter(final KameletDefinitionProperty property,
return switch (type) {
//number, integer, string, boolean, array, object, or null
case "number" -> new NumberParameter(id, title, description,
null, null, null,
value != null ? Double.valueOf(String.valueOf(value)) : null);
case "integer" -> new IntegerParameter(id, title, description,
null, null, null,
value != null ? Integer.valueOf(String.valueOf(value)) : null);
case "string" -> new StringParameter(id, title, description,
null, null, null,
value != null ? String.valueOf(value) : null, property.getFormat());
case "boolean" -> new BooleanParameter(id, title, description,
null, null, null,
value != null ? Boolean.valueOf(String.valueOf(value)) : null);
case "array" -> new ArrayParameter(id, title, description,
null, null, null,
value != null ? String.valueOf(value).split(",") : null);
default -> new ObjectParameter(id, title, description,
value);
null, null, null, value);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void parse() {
p.setValue("loggerName");
p.setId("loggerName");
step.getParameters().add(p);
p = new StringParameter("level", "level", "", "default", null);
p = new StringParameter("level", "level", "", null, null, null,"default", null);
p.setValue("info");
step.getParameters().add(p);
steps.add(step);
Expand Down Expand Up @@ -99,7 +99,7 @@ void parse() {
step.setKind("EIP");
step.setName("set-body");
step.setParameters(new LinkedList<>());
p = new StringParameter("constant", "constant", "", "default", null);
p = new StringParameter("constant", "constant", "",null, null, null, "default", null);
p.setValue("Hello Llama");
step.getParameters().add(p);
steps.add(1, step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,27 @@ private void assertBrowseJsonHasBeenParsedCorrectly(
Map<String, Parameter> expectedParameterValues = Map.of(
"name", new StringParameter(
"name", "Name", "d1",
null, null, null,
null, null),
"bridgeErrorHandler", new BooleanParameter(
"bridgeErrorHandler", "Bridge Error Handler",
"d2", false),
"d2",
null, null, null, false),
"exceptionHandler", new ObjectParameter(
"exceptionHandler", "Exception Handler",
"d3", null),
"d3",
null, null, null,null),
"exchangePattern", new ObjectParameter(
"exchangePattern", "Exchange Pattern",
"d4", null),
"d4",
null, null, null,null),
"lazyStartProducer", new BooleanParameter(
"lazyStartProducer", "Lazy Start Producer",
"d5", false),
"d5",
null, null, null,false),
"step-id-kaoto", new StringParameter("step-id-kaoto", "Step ID",
"Identifier of this step inside the route.", null, null)
"Identifier of this step inside the route.",
null, null, null,null, null)
);

expectedParameterValues.get("name").setPath(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,19 @@ private void assertBrowseJsonHasBeenParsedCorrectly(
assertIterableEquals(List.of("name"), parsedStep.getRequired());

Map<String, Parameter> expectedParameterValues = Map.of(
"name", new StringParameter("name", "Name", "d1", null, null),
"bridgeErrorHandler", new BooleanParameter("bridgeErrorHandler", "Bridge Error Handler", "d2", false),
"exceptionHandler", new ObjectParameter("exceptionHandler", "Exception Handler", "d3", null),
"exchangePattern", new ObjectParameter("exchangePattern", "Exchange Pattern", "d4", null),
"lazyStartProducer", new BooleanParameter("lazyStartProducer", "Lazy Start Producer", "d5", false),
"name", new StringParameter("name", "Name", "d1",
null, null, null, null, null),
"bridgeErrorHandler", new BooleanParameter("bridgeErrorHandler", "Bridge Error Handler", "d2",
null, null, null,false),
"exceptionHandler", new ObjectParameter("exceptionHandler", "Exception Handler", "d3",
null, null, null,null),
"exchangePattern", new ObjectParameter("exchangePattern", "Exchange Pattern", "d4",
null, null, null,null),
"lazyStartProducer", new BooleanParameter("lazyStartProducer", "Lazy Start Producer", "d5",
null, null, null,false),
"step-id-kaoto", new StringParameter("step-id-kaoto", "Step ID", "Identifier of this step inside the " +
"route.", null, null)
"route.",
null, null, null,null, null)
);

expectedParameterValues.get("name").setPath(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ public class ArrayParameter extends Parameter<Object[]> {
private Integer minItems;
private Boolean uniqueItems;

public ArrayParameter(final String id, final String title,
final String description, final Object[] v) {
super(id, title, description, v);
public ArrayParameter(final String id,
final String title,
final String description,
final Boolean nullable,
final Object[][] enumeration,
final Object[][] examples,
final Object[] defaultValue) {
super(id, title, description, nullable, enumeration, examples, defaultValue);
}

public ArrayParameter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class BooleanParameter extends Parameter<Boolean> {

public BooleanParameter(final String id, final String title,
final String description, final Boolean v) {
super(id, title, description, v);
public BooleanParameter(final String id,
final String title,
final String description,
final Boolean nullable,
final Boolean[] enumeration,
final Boolean[] examples,
final Boolean defaultValue) {
super(id, title, description, nullable, enumeration, examples, defaultValue);
}

public BooleanParameter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ public class IntegerParameter extends Parameter<Integer> {
private Integer maximum;
private Integer minimum;

public IntegerParameter(final String id, final String title,
final String description, final Integer v) {
super(id, title, description, v);
public IntegerParameter(final String id,
final String title,
final String description,
final Boolean nullable,
final Integer[] enumeration,
final Integer[] examples,
final Integer defaultValue) {
super(id, title, description, nullable, enumeration, examples, defaultValue);
}

public IntegerParameter() {
Expand Down
Loading

0 comments on commit f6b9008

Please sign in to comment.