You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/05/04 10:56:13 UTC
[camel] 03/04: CAMEL-18052: openapi-rest-dsl-generator - Fix sorted output
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
commit 0233e15e7eacb4a96b2ef289ae9b6fcd18b546dd
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed May 4 12:48:37 2022 +0200
CAMEL-18052: openapi-rest-dsl-generator - Fix sorted output
---
.../apache/camel/generator/openapi/RestDslYamlGenerator.java | 10 ++++------
.../test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt | 4 ++--
.../src/test/resources/OpenApiV3PetstoreSimpleYaml.txt | 4 ++--
3 files changed, 8 insertions(+), 10 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 fb6fed9ac8d..cb7f7771d8b 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
@@ -132,13 +132,11 @@ public class RestDslYamlGenerator extends RestDslGenerator<RestDslYamlGenerator>
List<String> toTagUris = new ArrayList<>();
for (String v : VERBS) {
+ fixVerbNodes(xmlMapper, node, v);
fixParamNodes(xmlMapper, node, v);
- fixVerb(node, v);
+ sortVerb(node, v);
toTagUris.addAll(fixToTags(xmlMapper, node, v));
}
- for (String v : VERBS) {
- fixVerbNodes(xmlMapper, node, v);
- }
// the root tag should be an array
node = fixRootNode(xmlMapper, node);
@@ -178,7 +176,7 @@ public class RestDslYamlGenerator extends RestDslGenerator<RestDslYamlGenerator>
* we want verbs to have its children sorted in a specific order so the generated rest-dsl is always the same
* structure and that we have id, uri, ... in the top
*/
- private static void fixVerb(JsonNode node, String verb) {
+ private static void sortVerb(JsonNode node, String verb) {
JsonNode verbs = node.path("rest").path(verb);
if (verbs == null || verbs.isMissingNode()) {
return;
@@ -187,7 +185,7 @@ public class RestDslYamlGenerator extends RestDslGenerator<RestDslYamlGenerator>
List<String> names = new ArrayList<>();
if (n.isObject()) {
ObjectNode on = (ObjectNode) n;
- // sort the elements: id, uri, description, consumes, produces, type, outType, param
+ // sort the elements: id, path, description, consumes, produces, type, outType, param
Iterator<String> it = on.fieldNames();
while (it.hasNext()) {
names.add(it.next());
diff --git a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt
index 244f27d9eed..9b47def1f45 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt
+++ b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt
@@ -1,7 +1,7 @@
- rest:
put:
- - consumes: "application/json,text/xml"
- path: "/pet"
+ - path: "/pet"
+ consumes: "application/json,text/xml"
produces: "application/json,text/xml"
param:
- name: "body"
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 0f5e6f22186..7d9e6d2ff21 100644
--- a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleYaml.txt
+++ b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleYaml.txt
@@ -1,7 +1,7 @@
- rest:
put:
- - consumes: "application/json,text/xml"
- path: "/pet"
+ - path: "/pet"
+ consumes: "application/json,text/xml"
produces: "application/json,text/xml"
param:
- name: "body"