From 122adf90e787a62c8741bd3acb03f918e17fccf8 Mon Sep 17 00:00:00 2001 From: Tomohisa Igarashi Date: Fri, 15 Sep 2023 13:37:42 -0400 Subject: [PATCH] fix: bindingMode: off is converted to bindingMode: false Fixes: #863 --- .../deployment/camelroute/CamelRoute.java | 13 ++++++++++ .../CamelRestDSLStepParserServiceTest.java | 19 ++++++++++++++ .../camelroute/rest-dsl-bindingMode-off.yaml | 25 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 camel-support/src/test/resources/io/kaoto/backend/camel/service/step/parser/camelroute/rest-dsl-bindingMode-off.yaml diff --git a/camel-support/src/main/java/io/kaoto/backend/camel/model/deployment/camelroute/CamelRoute.java b/camel-support/src/main/java/io/kaoto/backend/camel/model/deployment/camelroute/CamelRoute.java index 86c5fbc0..6ba3021c 100644 --- a/camel-support/src/main/java/io/kaoto/backend/camel/model/deployment/camelroute/CamelRoute.java +++ b/camel-support/src/main/java/io/kaoto/backend/camel/model/deployment/camelroute/CamelRoute.java @@ -176,5 +176,18 @@ public Object getRestConfiguration() { public void setRestConfiguration(Object restConfiguration) { this.restConfiguration = restConfiguration; + if (!(restConfiguration instanceof Map)) { + return; + } + // YAML 1.1 assumes "off" to be a boolean "false", restore it as a string + var map = (Map) restConfiguration; + var camelBindingMode = map.get("bindingMode"); + if (camelBindingMode instanceof Boolean && !((Boolean) camelBindingMode)) { + map.put("bindingMode", "off"); + } + var kebabBindingMode = map.get("binding-mode"); + if (kebabBindingMode instanceof Boolean && !((Boolean) camelBindingMode)) { + map.put("binding-mode", "off"); + } } } diff --git a/camel-support/src/test/java/io/kaoto/backend/camel/service/step/parser/camelroute/CamelRestDSLStepParserServiceTest.java b/camel-support/src/test/java/io/kaoto/backend/camel/service/step/parser/camelroute/CamelRestDSLStepParserServiceTest.java index f5bfb3b5..334db01c 100644 --- a/camel-support/src/test/java/io/kaoto/backend/camel/service/step/parser/camelroute/CamelRestDSLStepParserServiceTest.java +++ b/camel-support/src/test/java/io/kaoto/backend/camel/service/step/parser/camelroute/CamelRestDSLStepParserServiceTest.java @@ -1,6 +1,7 @@ package io.kaoto.backend.camel.service.step.parser.camelroute; import io.kaoto.backend.api.metadata.catalog.StepCatalog; +import io.kaoto.backend.camel.KamelHelper; import io.kaoto.backend.camel.service.dsl.camelroute.CamelRouteDSLSpecification; import io.kaoto.backend.api.service.step.parser.StepParserService; import io.kaoto.backend.model.step.Step; @@ -12,6 +13,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -60,4 +62,21 @@ void deepParse() throws IOException { assertThat(yaml).isEqualToNormalizingNewlines(route); assertTrue(camelRestDSLSpecification.getDeploymentGeneratorService().supportedCustomResources().isEmpty()); } + + @Test + void bindingModeOff() throws Exception { + var route = new String(this.getClass().getResourceAsStream("rest-dsl-bindingMode-off.yaml").readAllBytes(), + StandardCharsets.UTF_8); + assertTrue(camelRestDSLSpecification.getStepParserService().appliesTo(route)); + List> flows = + camelRestDSLSpecification.getStepParserService().getParsedFlows(route); + var yaml = camelRestDSLSpecification.getDeploymentGeneratorService().parse(flows); + var restConfiguration = KamelHelper.YAML_MAPPER + .readValue(yaml, java.util.List.class).stream() + .filter(e -> ((Map)e).containsKey("restConfiguration")) + .map(e -> ((Map)e).get("restConfiguration")) + .findFirst() + .get(); + assertThat(((Map)restConfiguration).get("bindingMode")).isEqualTo("off"); + } } diff --git a/camel-support/src/test/resources/io/kaoto/backend/camel/service/step/parser/camelroute/rest-dsl-bindingMode-off.yaml b/camel-support/src/test/resources/io/kaoto/backend/camel/service/step/parser/camelroute/rest-dsl-bindingMode-off.yaml new file mode 100644 index 00000000..088d4753 --- /dev/null +++ b/camel-support/src/test/resources/io/kaoto/backend/camel/service/step/parser/camelroute/rest-dsl-bindingMode-off.yaml @@ -0,0 +1,25 @@ +- restConfiguration: + component: servlet + bindingMode: off + inlineRoutes: true + apiComponent: openapi +- rest: + id: this-is-the-rest-definition + path: /api/v3 + put: + - consumes: application/json,application/xml + id: updatePet + path: /pet + param: + - name: body + required: true + type: body + to: + uri: direct:updatePet +- route: + id: from-route + from: + uri: direct:updatePet + steps: + - log: + message: ${body}