Skip to content

Commit 86f1070

Browse files
authored
[BUG][rust-axum] Fix duplicate route operations when supplying multiple tags on a path with a camelCase param (#21873)
* [BUG][rust-axum] Fix duplicate route operations when supplying multiple tags on a path with a camelCase param * Update rust-axum sample
1 parent 2ebda09 commit 86f1070

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,15 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
450450
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
451451

452452
String underscoredOperationId = underscore(op.operationId);
453-
ArrayList<MethodOperation> pathMethods = pathMethodOpMap.get(path);
453+
String axumPath = op.path;
454+
for (CodegenParameter param : op.pathParams) {
455+
// Replace {baseName} with {paramName} for format string
456+
String paramSearch = "{" + param.baseName + "}";
457+
String paramReplace = "{" + param.paramName + "}";
458+
459+
axumPath = axumPath.replace(paramSearch, paramReplace);
460+
}
461+
ArrayList<MethodOperation> pathMethods = pathMethodOpMap.get(axumPath);
454462

455463
// Prevent multiple declarations of the same operation
456464
if (pathMethods != null && pathMethods.stream().anyMatch(pathMethod ->
@@ -463,14 +471,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
463471

464472
if (!op.isCallbackRequest) {
465473
// group route by path
466-
String axumPath = op.path;
467-
for (CodegenParameter param : op.pathParams) {
468-
// Replace {baseName} with {paramName} for format string
469-
String paramSearch = "{" + param.baseName + "}";
470-
String paramReplace = "{" + param.paramName + "}";
471-
472-
axumPath = axumPath.replace(paramSearch, paramReplace);
473-
}
474474
pathMethodOpMap
475475
.computeIfAbsent(axumPath, (key) -> new ArrayList<>())
476476
.add(new MethodOperation(

modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustAxumServerCodegenTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public void testPreventDuplicateOperationDeclaration() throws IOException {
2828
String routerSpec = linearize("Router::new() " +
2929
".route(\"/api/test\", " +
3030
"delete(test_delete::<I, A, E, C>).post(test_post::<I, A, E, C>) ) " +
31+
".route(\"/api/test/{test_id}\", " +
32+
"get(test_get::<I, A, E, C>) ) " +
3133
".with_state(api_impl)");
3234
TestUtils.assertFileExists(outputPath);
3335
TestUtils.assertFileContains(outputPath, routerSpec);

modules/openapi-generator/src/test/resources/3_1/issue_21144.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ paths:
2525
description: "post"
2626
security:
2727
- apiKey: []
28+
/api/test/{testId}:
29+
get:
30+
tags:
31+
- firsttag
32+
- secondtag
33+
- thirdtag
34+
operationId: "testGet"
35+
description: "Get method"
36+
parameters:
37+
- name: testId
38+
in: path
39+
required: true
40+
schema:
41+
type: string
42+
responses:
43+
200:
44+
description: "get"
45+
security:
46+
- apiKey: [ ]
2847
components:
2948
securitySchemes:
3049
apiKey:

samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ where
8787
post(create_repo::<I, A, E>)
8888
)
8989
.route("/repos/{repo_id}",
90-
get(get_repo_info::<I, A, E>).get(get_repo_info::<I, A, E>)
90+
get(get_repo_info::<I, A, E>)
9191
)
9292
.route("/required_octet_stream",
9393
put(required_octet_stream_put::<I, A, E>)

0 commit comments

Comments
 (0)