This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6d5b4831054 Fix CAMEL-17989 (#7464)
6d5b4831054 is described below
commit 6d5b4831054d9d7c7993e5754dfaef9098ff72ca
Author: Marat Gubaidullin <[email protected]>
AuthorDate: Wed Apr 20 00:26:49 2022 -0400
Fix CAMEL-17989 (#7464)
---
.../generator/openapi/RestDslYamlGenerator.java | 23 +++++++++
.../test/resources/OpenApiV3PetstoreSimpleYaml.txt | 3 +-
.../OpenApiV3PetstoreWithRestComponentYaml.txt | 60 ++++++++--------------
.../src/test/resources/OpenApiV3PetstoreYaml.txt | 60 ++++++++--------------
4 files changed, 64 insertions(+), 82 deletions(-)
diff --git
a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
index 0feffe59356..e7369b7e875 100644
---
a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
+++
b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
@@ -126,6 +126,7 @@ public class RestDslYamlGenerator extends
RestDslGenerator<RestDslYamlGenerator>
for (String v : VERBS) {
fixParamNodes(xmlMapper, node, v);
fixVerb(node, v);
+ fixToTags(xmlMapper, node, v);
}
// the root tag should be an array
node = fixRootNode(xmlMapper, node);
@@ -234,6 +235,28 @@ public class RestDslYamlGenerator extends
RestDslGenerator<RestDslYamlGenerator>
}
}
+ /**
+ * to tag should be in implicit mode, ex: to: "direct:directX"
+ */
+ private static void fixToTags(XmlMapper xmlMapper, JsonNode node, String
verb) {
+ JsonNode verbs = node.path("rest").path(verb);
+ if (verbs == null || verbs.isMissingNode()) {
+ return;
+ }
+ if (!verbs.isArray()) {
+ // the rest has only 1 verb so fool the code below and wrap in an
new array
+ ArrayNode arr = xmlMapper.createArrayNode();
+ arr.add(verbs);
+ verbs = arr;
+ }
+ for (JsonNode n : verbs) {
+ if (n.has("to")) {
+ ObjectNode on = (ObjectNode) n;
+ on.set("to", n.get("to").get("uri"));
+ }
+ }
+ }
+
private static int fieldOrderIndex(String field) {
// to should be last
if ("to".equals(field)) {
diff --git
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleYaml.txt
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleYaml.txt
index 1000b53f263..7df5fac8aff 100644
---
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleYaml.txt
+++
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleYaml.txt
@@ -7,5 +7,4 @@
- name: "body"
required: true
type: "body"
- to:
- uri: "direct:rest1"
+ to: "direct:rest1"
diff --git
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreWithRestComponentYaml.txt
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreWithRestComponentYaml.txt
index 60ae88d5f99..2e9859cf887 100644
---
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreWithRestComponentYaml.txt
+++
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreWithRestComponentYaml.txt
@@ -12,8 +12,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:updatePet"
+ to: "direct:updatePet"
- id: "updateUser"
path: "/user/{username}"
description: "This can only be done by the logged in user."
@@ -28,8 +27,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:updateUser"
+ to: "direct:updateUser"
post:
- id: "addPet"
path: "/pet"
@@ -45,8 +43,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:addPet"
+ to: "direct:addPet"
- id: "updatePetWithForm"
path: "/pet/{petId}"
consumes: "application/x-www-form-urlencoded"
@@ -66,8 +63,7 @@
name: "status"
required: true
type: "formData"
- to:
- uri: "direct:updatePetWithForm"
+ to: "direct:updatePetWithForm"
- id: "uploadFile"
path: "/pet/{petId}/uploadImage"
consumes: "multipart/form-data"
@@ -88,8 +84,7 @@
name: "file"
required: true
type: "formData"
- to:
- uri: "direct:uploadFile"
+ to: "direct:uploadFile"
- id: "placeOrder"
path: "/store/order"
consumes: "*/*"
@@ -99,8 +94,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:placeOrder"
+ to: "direct:placeOrder"
- id: "createUser"
path: "/user"
description: "This can only be done by the logged in user."
@@ -110,8 +104,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:createUser"
+ to: "direct:createUser"
- id: "createUsersWithArrayInput"
path: "/user/createWithArray"
consumes: "*/*"
@@ -120,8 +113,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:createUsersWithArrayInput"
+ to: "direct:createUsersWithArrayInput"
- id: "createUsersWithListInput"
path: "/user/createWithList"
consumes: "*/*"
@@ -130,8 +122,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:createUsersWithListInput"
+ to: "direct:createUsersWithListInput"
get:
- id: "findPetsByStatus"
path: "/pet/findByStatus"
@@ -145,8 +136,7 @@
name: "status"
required: true
type: "query"
- to:
- uri: "direct:findPetsByStatus"
+ to: "direct:findPetsByStatus"
- id: "findPetsByTags"
path: "/pet/findByTags"
description: "Muliple tags can be provided with comma separated strings.
Use\
@@ -160,8 +150,7 @@
name: "tags"
required: true
type: "query"
- to:
- uri: "direct:findPetsByTags"
+ to: "direct:findPetsByTags"
- id: "getPetById"
path: "/pet/{petId}"
description: "Returns a single pet"
@@ -172,14 +161,12 @@
name: "petId"
required: true
type: "path"
- to:
- uri: "direct:getPetById"
+ to: "direct:getPetById"
- id: "getInventory"
path: "/store/inventory"
description: "Returns a map of status codes to quantities"
produces: "application/json"
- to:
- uri: "direct:getInventory"
+ to: "direct:getInventory"
- id: "getOrderById"
path: "/store/order/{orderId}"
description: "For valid response try integer IDs with value >= 1 and <=
10.\
@@ -191,8 +178,7 @@
name: "orderId"
required: true
type: "path"
- to:
- uri: "direct:getOrderById"
+ to: "direct:getOrderById"
- id: "loginUser"
path: "/user/login"
produces: "application/xml,application/json"
@@ -207,12 +193,10 @@
name: "password"
required: true
type: "query"
- to:
- uri: "direct:loginUser"
+ to: "direct:loginUser"
- id: "logoutUser"
path: "/user/logout"
- to:
- uri: "direct:logoutUser"
+ to: "direct:logoutUser"
- id: "getUserByName"
path: "/user/{username}"
produces: "application/xml,application/json"
@@ -222,8 +206,7 @@
name: "username"
required: true
type: "path"
- to:
- uri: "direct:getUserByName"
+ to: "direct:getUserByName"
delete:
- id: "deletePet"
path: "/pet/{petId}"
@@ -237,8 +220,7 @@
name: "petId"
required: true
type: "path"
- to:
- uri: "direct:deletePet"
+ to: "direct:deletePet"
- id: "deleteOrder"
path: "/store/order/{orderId}"
description: "For valid response try integer IDs with positive integer
value.\
@@ -249,8 +231,7 @@
name: "orderId"
required: true
type: "path"
- to:
- uri: "direct:deleteOrder"
+ to: "direct:deleteOrder"
- id: "deleteUser"
path: "/user/{username}"
description: "This can only be done by the logged in user."
@@ -260,5 +241,4 @@
name: "username"
required: true
type: "path"
- to:
- uri: "direct:deleteUser"
+ to: "direct:deleteUser"
diff --git
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreYaml.txt
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreYaml.txt
index 04ab05c6dbb..c85aa775334 100644
---
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreYaml.txt
+++
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreYaml.txt
@@ -9,8 +9,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:updatePet"
+ to: "direct:updatePet"
- id: "updateUser"
path: "/user/{username}"
description: "This can only be done by the logged in user."
@@ -25,8 +24,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:updateUser"
+ to: "direct:updateUser"
post:
- id: "addPet"
path: "/pet"
@@ -42,8 +40,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:addPet"
+ to: "direct:addPet"
- id: "updatePetWithForm"
path: "/pet/{petId}"
consumes: "application/x-www-form-urlencoded"
@@ -63,8 +60,7 @@
name: "status"
required: true
type: "formData"
- to:
- uri: "direct:updatePetWithForm"
+ to: "direct:updatePetWithForm"
- id: "uploadFile"
path: "/pet/{petId}/uploadImage"
consumes: "multipart/form-data"
@@ -85,8 +81,7 @@
name: "file"
required: true
type: "formData"
- to:
- uri: "direct:uploadFile"
+ to: "direct:uploadFile"
- id: "placeOrder"
path: "/store/order"
consumes: "*/*"
@@ -96,8 +91,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:placeOrder"
+ to: "direct:placeOrder"
- id: "createUser"
path: "/user"
description: "This can only be done by the logged in user."
@@ -107,8 +101,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:createUser"
+ to: "direct:createUser"
- id: "createUsersWithArrayInput"
path: "/user/createWithArray"
consumes: "*/*"
@@ -117,8 +110,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:createUsersWithArrayInput"
+ to: "direct:createUsersWithArrayInput"
- id: "createUsersWithListInput"
path: "/user/createWithList"
consumes: "*/*"
@@ -127,8 +119,7 @@
name: "body"
required: true
type: "body"
- to:
- uri: "direct:createUsersWithListInput"
+ to: "direct:createUsersWithListInput"
get:
- id: "findPetsByStatus"
path: "/pet/findByStatus"
@@ -142,8 +133,7 @@
name: "status"
required: true
type: "query"
- to:
- uri: "direct:findPetsByStatus"
+ to: "direct:findPetsByStatus"
- id: "findPetsByTags"
path: "/pet/findByTags"
description: "Muliple tags can be provided with comma separated strings.
Use\
@@ -157,8 +147,7 @@
name: "tags"
required: true
type: "query"
- to:
- uri: "direct:findPetsByTags"
+ to: "direct:findPetsByTags"
- id: "getPetById"
path: "/pet/{petId}"
description: "Returns a single pet"
@@ -169,14 +158,12 @@
name: "petId"
required: true
type: "path"
- to:
- uri: "direct:getPetById"
+ to: "direct:getPetById"
- id: "getInventory"
path: "/store/inventory"
description: "Returns a map of status codes to quantities"
produces: "application/json"
- to:
- uri: "direct:getInventory"
+ to: "direct:getInventory"
- id: "getOrderById"
path: "/store/order/{orderId}"
description: "For valid response try integer IDs with value >= 1 and <=
10.\
@@ -188,8 +175,7 @@
name: "orderId"
required: true
type: "path"
- to:
- uri: "direct:getOrderById"
+ to: "direct:getOrderById"
- id: "loginUser"
path: "/user/login"
produces: "application/xml,application/json"
@@ -204,12 +190,10 @@
name: "password"
required: true
type: "query"
- to:
- uri: "direct:loginUser"
+ to: "direct:loginUser"
- id: "logoutUser"
path: "/user/logout"
- to:
- uri: "direct:logoutUser"
+ to: "direct:logoutUser"
- id: "getUserByName"
path: "/user/{username}"
produces: "application/xml,application/json"
@@ -219,8 +203,7 @@
name: "username"
required: true
type: "path"
- to:
- uri: "direct:getUserByName"
+ to: "direct:getUserByName"
delete:
- id: "deletePet"
path: "/pet/{petId}"
@@ -234,8 +217,7 @@
name: "petId"
required: true
type: "path"
- to:
- uri: "direct:deletePet"
+ to: "direct:deletePet"
- id: "deleteOrder"
path: "/store/order/{orderId}"
description: "For valid response try integer IDs with positive integer
value.\
@@ -246,8 +228,7 @@
name: "orderId"
required: true
type: "path"
- to:
- uri: "direct:deleteOrder"
+ to: "direct:deleteOrder"
- id: "deleteUser"
path: "/user/{username}"
description: "This can only be done by the logged in user."
@@ -257,5 +238,4 @@
name: "username"
required: true
type: "path"
- to:
- uri: "direct:deleteUser"
+ to: "direct:deleteUser"