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

fix: bindingMode: off is converted to bindingMode: false #864

Merged
merged 1 commit into from
Sep 16, 2023
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 @@ -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<String, Object>) 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");
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -60,4 +62,21 @@
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<StepParserService.ParseResult<Step>> flows =
camelRestDSLSpecification.getStepParserService().getParsedFlows(route);
var yaml = camelRestDSLSpecification.getDeploymentGeneratorService().parse(flows);
var restConfiguration = KamelHelper.YAML_MAPPER
.readValue(yaml, java.util.List.class).stream()

Check notice on line 75 in camel-support/src/test/java/io/kaoto/backend/camel/service/step/parser/camelroute/CamelRestDSLStepParserServiceTest.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

camel-support/src/test/java/io/kaoto/backend/camel/service/step/parser/camelroute/CamelRestDSLStepParserServiceTest.java#L75

Unnecessary use of fully qualified name 'java.util.List' due to existing import 'java.util.List'
.filter(e -> ((Map)e).containsKey("restConfiguration"))
.map(e -> ((Map)e).get("restConfiguration"))
.findFirst()
.get();
assertThat(((Map)restConfiguration).get("bindingMode")).isEqualTo("off");
}
}
Original file line number Diff line number Diff line change
@@ -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}