Skip to content

Commit d99ff4e

Browse files
davsclausclaude
andauthored
CAMEL-24004: Generated REST DSL always emits type on param definitions
The XML model writer skips attributes matching their default value, so type="path" (the default for ParamDefinition) was omitted from the generated output. The YAML and XML generators now ensure the type attribute is always present via post-processing. Closes #24602 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9a67216 commit d99ff4e

9 files changed

Lines changed: 75 additions & 23 deletions

File tree

tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslXmlGenerator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public String generate(final CamelContext context) throws Exception {
8080
element.removeAttribute("customId");
8181
}
8282

83+
// ensure param elements always have the type attribute
84+
// (the XML writer omits it when the value is the default "path")
85+
final NodeList params = document.getElementsByTagName("param");
86+
for (int i = 0; i < params.getLength(); i++) {
87+
final Element param = (Element) params.item(i);
88+
if (!param.hasAttribute("type")) {
89+
param.setAttribute("type", "path");
90+
}
91+
}
92+
8393
boolean restConfig = restComponent != null || restContextPath != null || clientRequestValidation;
8494
if (restConfig) {
8595
final Element configuration = document.createElement("restConfiguration");

tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,27 @@ private static void fixParamNodes(XmlMapper xmlMapper, JsonNode node, String ver
260260
on.set("param", arr);
261261
p = arr;
262262
}
263-
// fix required to be boolean type
264263
if (p != null) {
265264
for (JsonNode pc : p) {
266-
JsonNode r = pc.get("required");
265+
ObjectNode on = (ObjectNode) pc;
266+
// ensure type is always present (XML writer omits the default "path")
267+
if (on.get("type") == null) {
268+
on.put("type", "path");
269+
}
270+
// fix required to be boolean type
271+
JsonNode r = on.get("required");
267272
if (r != null) {
268273
String t = r.textValue();
269274
boolean b = Boolean.parseBoolean(t);
270-
ObjectNode on = (ObjectNode) pc;
271275
BooleanNode bn = xmlMapper.createObjectNode().booleanNode(b);
272276
on.set("required", bn);
273277
}
274278
String k = "allowableValues";
275-
r = pc.get(k);
279+
r = on.get(k);
276280
if (r != null) {
277281
// remove value node
278282
JsonNode v = r.get("value");
279283
if (v.isArray()) {
280-
ObjectNode on = (ObjectNode) pc;
281284
on.set(k, v);
282285
on.remove("value");
283286
}

tooling/openapi-rest-dsl-generator/src/test/resources/GreetingsYaml.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
produces: "*/*"
77
param:
88
- name: "name"
9+
type: "path"
910
to: "direct:greeting-api"
1011
post:
1112
- id: "post-greeting-api"
1213
path: "/greetings/{name}"
1314
produces: "*/*"
1415
param:
1516
- name: "name"
17+
type: "path"
1618
to: "direct:post-greeting-api"
1719
- id: "bye-api"
1820
path: "/bye/{name}"
1921
produces: "*/*"
2022
param:
2123
- name: "name"
24+
type: "path"
2225
to: "direct:bye-api"

tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV302PetstoreYaml.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
param:
1919
- description: "name that need to be deleted"
2020
name: "username"
21+
type: "path"
2122
- description: "Update an existent user in the store"
2223
name: "body"
2324
type: "body"
@@ -39,6 +40,7 @@
3940
- dataType: "integer"
4041
description: "ID of pet that needs to be updated"
4142
name: "petId"
43+
type: "path"
4244
- collectionFormat: "multi"
4345
description: "Name of pet that needs to be updated"
4446
name: "name"
@@ -58,6 +60,7 @@
5860
- dataType: "integer"
5961
description: "ID of pet to update"
6062
name: "petId"
63+
type: "path"
6164
- collectionFormat: "multi"
6265
description: "Additional Metadata"
6366
name: "additionalMetadata"
@@ -132,6 +135,7 @@
132135
- dataType: "integer"
133136
description: "ID of pet to return"
134137
name: "petId"
138+
type: "path"
135139
to: "direct:getPetById"
136140
- id: "getInventory"
137141
path: "/store/inventory"
@@ -147,6 +151,7 @@
147151
- dataType: "integer"
148152
description: "ID of order that needs to be fetched"
149153
name: "orderId"
154+
type: "path"
150155
to: "direct:getOrderById"
151156
- id: "loginUser"
152157
path: "/user/login"
@@ -172,6 +177,7 @@
172177
param:
173178
- description: "The name that needs to be fetched. Use user1 for testing. "
174179
name: "username"
180+
type: "path"
175181
to: "direct:getUserByName"
176182
delete:
177183
- id: "deletePet"
@@ -183,6 +189,7 @@
183189
- dataType: "integer"
184190
description: "Pet id to delete"
185191
name: "petId"
192+
type: "path"
186193
to: "direct:deletePet"
187194
- id: "deleteOrder"
188195
path: "/store/order/{orderId}"
@@ -192,11 +199,13 @@
192199
- dataType: "integer"
193200
description: "ID of the order that needs to be deleted"
194201
name: "orderId"
202+
type: "path"
195203
to: "direct:deleteOrder"
196204
- id: "deleteUser"
197205
path: "/user/{username}"
198206
description: "This can only be done by the logged in user."
199207
param:
200208
- description: "The name that needs to be deleted"
201209
name: "username"
210+
type: "path"
202211
to: "direct:deleteUser"

tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreWithModelYaml.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
param:
1919
- description: "name that need to be updated"
2020
name: "username"
21+
type: "path"
2122
- description: "Updated user object"
2223
name: "body"
2324
type: "body"
@@ -46,6 +47,7 @@
4647
- dataType: "integer"
4748
description: "ID of pet that needs to be updated"
4849
name: "petId"
50+
type: "path"
4951
- description: "Updated name of the pet"
5052
name: "name"
5153
type: "formData"
@@ -62,6 +64,7 @@
6264
- dataType: "integer"
6365
description: "ID of pet to update"
6466
name: "petId"
67+
type: "path"
6568
- description: "Additional data to pass to server"
6669
name: "additionalMetadata"
6770
type: "formData"
@@ -143,6 +146,7 @@
143146
- dataType: "integer"
144147
description: "ID of pet to return"
145148
name: "petId"
149+
type: "path"
146150
to: "direct:getPetById"
147151
- id: "getInventory"
148152
path: "/store/inventory"
@@ -159,6 +163,7 @@
159163
- dataType: "integer"
160164
description: "ID of pet that needs to be fetched"
161165
name: "orderId"
166+
type: "path"
162167
to: "direct:getOrderById"
163168
- id: "loginUser"
164169
path: "/user/login"
@@ -183,6 +188,7 @@
183188
param:
184189
- description: "The name that needs to be fetched. Use user1 for testing. "
185190
name: "username"
191+
type: "path"
186192
to: "direct:getUserByName"
187193
delete:
188194
- id: "deletePet"
@@ -194,6 +200,7 @@
194200
- dataType: "integer"
195201
description: "Pet id to delete"
196202
name: "petId"
203+
type: "path"
197204
to: "direct:deletePet"
198205
- id: "deleteOrder"
199206
path: "/store/order/{orderId}"
@@ -203,11 +210,13 @@
203210
- dataType: "integer"
204211
description: "ID of the order that needs to be deleted"
205212
name: "orderId"
213+
type: "path"
206214
to: "direct:deleteOrder"
207215
- id: "deleteUser"
208216
path: "/user/{username}"
209217
description: "This can only be done by the logged in user."
210218
param:
211219
- description: "The name that needs to be deleted"
212220
name: "username"
221+
type: "path"
213222
to: "direct:deleteUser"

tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreWithRestComponentXml.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@
2020
<to uri="direct:findPetsByTags"/>
2121
</get>
2222
<get description="Returns a single pet" id="getPetById" path="/pet/{petId}" produces="application/xml,application/json">
23-
<param dataType="integer" description="ID of pet to return" name="petId"/>
23+
<param dataType="integer" description="ID of pet to return" name="petId" type="path"/>
2424
<to uri="direct:getPetById"/>
2525
</get>
2626
<post consumes="application/x-www-form-urlencoded" id="updatePetWithForm" path="/pet/{petId}">
27-
<param dataType="integer" description="ID of pet that needs to be updated" name="petId"/>
27+
<param dataType="integer" description="ID of pet that needs to be updated" name="petId" type="path"/>
2828
<param description="Updated name of the pet" name="name" type="formData"/>
2929
<param description="Updated status of the pet" name="status" type="formData"/>
3030
<to uri="direct:updatePetWithForm"/>
3131
</post>
3232
<delete id="deletePet" path="/pet/{petId}">
3333
<param name="api_key" required="false" type="header"/>
34-
<param dataType="integer" description="Pet id to delete" name="petId"/>
34+
<param dataType="integer" description="Pet id to delete" name="petId" type="path"/>
3535
<to uri="direct:deletePet"/>
3636
</delete>
3737
<post consumes="multipart/form-data" id="uploadFile" path="/pet/{petId}/uploadImage" produces="application/json">
38-
<param dataType="integer" description="ID of pet to update" name="petId"/>
38+
<param dataType="integer" description="ID of pet to update" name="petId" type="path"/>
3939
<param description="Additional data to pass to server" name="additionalMetadata" type="formData"/>
4040
<param description="file to upload" name="file" type="formData"/>
4141
<to uri="direct:uploadFile"/>
@@ -48,11 +48,11 @@
4848
<to uri="direct:placeOrder"/>
4949
</post>
5050
<get description="For valid response try integer IDs with value &gt;= 1 and &lt;= 10. Other values will generated exceptions" id="getOrderById" path="/store/order/{orderId}" produces="application/xml,application/json">
51-
<param dataType="integer" description="ID of pet that needs to be fetched" name="orderId"/>
51+
<param dataType="integer" description="ID of pet that needs to be fetched" name="orderId" type="path"/>
5252
<to uri="direct:getOrderById"/>
5353
</get>
5454
<delete description="For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors" id="deleteOrder" path="/store/order/{orderId}">
55-
<param dataType="integer" description="ID of the order that needs to be deleted" name="orderId"/>
55+
<param dataType="integer" description="ID of the order that needs to be deleted" name="orderId" type="path"/>
5656
<to uri="direct:deleteOrder"/>
5757
</delete>
5858
<post consumes="*/*" description="This can only be done by the logged in user." id="createUser" path="/user">
@@ -76,16 +76,16 @@
7676
<to uri="direct:logoutUser"/>
7777
</get>
7878
<get id="getUserByName" path="/user/{username}" produces="application/xml,application/json">
79-
<param description="The name that needs to be fetched. Use user1 for testing. " name="username"/>
79+
<param description="The name that needs to be fetched. Use user1 for testing. " name="username" type="path"/>
8080
<to uri="direct:getUserByName"/>
8181
</get>
8282
<put consumes="*/*" description="This can only be done by the logged in user." id="updateUser" path="/user/{username}">
83-
<param description="name that need to be updated" name="username"/>
83+
<param description="name that need to be updated" name="username" type="path"/>
8484
<param description="Updated user object" name="body" type="body"/>
8585
<to uri="direct:updateUser"/>
8686
</put>
8787
<delete description="This can only be done by the logged in user." id="deleteUser" path="/user/{username}">
88-
<param description="The name that needs to be deleted" name="username"/>
88+
<param description="The name that needs to be deleted" name="username" type="path"/>
8989
<to uri="direct:deleteUser"/>
9090
</delete>
9191
</rest>

tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreWithRestComponentYaml.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
param:
2020
- description: "name that need to be updated"
2121
name: "username"
22+
type: "path"
2223
- description: "Updated user object"
2324
name: "body"
2425
type: "body"
@@ -46,6 +47,7 @@
4647
- dataType: "integer"
4748
description: "ID of pet that needs to be updated"
4849
name: "petId"
50+
type: "path"
4951
- description: "Updated name of the pet"
5052
name: "name"
5153
type: "formData"
@@ -61,6 +63,7 @@
6163
- dataType: "integer"
6264
description: "ID of pet to update"
6365
name: "petId"
66+
type: "path"
6467
- description: "Additional data to pass to server"
6568
name: "additionalMetadata"
6669
type: "formData"
@@ -134,6 +137,7 @@
134137
- dataType: "integer"
135138
description: "ID of pet to return"
136139
name: "petId"
140+
type: "path"
137141
to: "direct:getPetById"
138142
- id: "getInventory"
139143
path: "/store/inventory"
@@ -149,6 +153,7 @@
149153
- dataType: "integer"
150154
description: "ID of pet that needs to be fetched"
151155
name: "orderId"
156+
type: "path"
152157
to: "direct:getOrderById"
153158
- id: "loginUser"
154159
path: "/user/login"
@@ -172,6 +177,7 @@
172177
param:
173178
- description: "The name that needs to be fetched. Use user1 for testing. "
174179
name: "username"
180+
type: "path"
175181
to: "direct:getUserByName"
176182
delete:
177183
- id: "deletePet"
@@ -183,6 +189,7 @@
183189
- dataType: "integer"
184190
description: "Pet id to delete"
185191
name: "petId"
192+
type: "path"
186193
to: "direct:deletePet"
187194
- id: "deleteOrder"
188195
path: "/store/order/{orderId}"
@@ -192,11 +199,13 @@
192199
- dataType: "integer"
193200
description: "ID of the order that needs to be deleted"
194201
name: "orderId"
202+
type: "path"
195203
to: "direct:deleteOrder"
196204
- id: "deleteUser"
197205
path: "/user/{username}"
198206
description: "This can only be done by the logged in user."
199207
param:
200208
- description: "The name that needs to be deleted"
201209
name: "username"
210+
type: "path"
202211
to: "direct:deleteUser"

0 commit comments

Comments
 (0)