[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
This commit is contained in:
Kevin Liddle
2025-09-03 12:36:26 -05:00
committed by GitHub
parent 2ebda09b9f
commit 86f107047e
4 changed files with 31 additions and 10 deletions

View File

@@ -450,7 +450,15 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
String underscoredOperationId = underscore(op.operationId);
ArrayList<MethodOperation> pathMethods = pathMethodOpMap.get(path);
String axumPath = op.path;
for (CodegenParameter param : op.pathParams) {
// Replace {baseName} with {paramName} for format string
String paramSearch = "{" + param.baseName + "}";
String paramReplace = "{" + param.paramName + "}";
axumPath = axumPath.replace(paramSearch, paramReplace);
}
ArrayList<MethodOperation> pathMethods = pathMethodOpMap.get(axumPath);
// Prevent multiple declarations of the same operation
if (pathMethods != null && pathMethods.stream().anyMatch(pathMethod ->
@@ -463,14 +471,6 @@ public class RustAxumServerCodegen extends AbstractRustCodegen implements Codege
if (!op.isCallbackRequest) {
// group route by path
String axumPath = op.path;
for (CodegenParameter param : op.pathParams) {
// Replace {baseName} with {paramName} for format string
String paramSearch = "{" + param.baseName + "}";
String paramReplace = "{" + param.paramName + "}";
axumPath = axumPath.replace(paramSearch, paramReplace);
}
pathMethodOpMap
.computeIfAbsent(axumPath, (key) -> new ArrayList<>())
.add(new MethodOperation(

View File

@@ -28,6 +28,8 @@ public class RustAxumServerCodegenTest {
String routerSpec = linearize("Router::new() " +
".route(\"/api/test\", " +
"delete(test_delete::<I, A, E, C>).post(test_post::<I, A, E, C>) ) " +
".route(\"/api/test/{test_id}\", " +
"get(test_get::<I, A, E, C>) ) " +
".with_state(api_impl)");
TestUtils.assertFileExists(outputPath);
TestUtils.assertFileContains(outputPath, routerSpec);

View File

@@ -25,6 +25,25 @@ paths:
description: "post"
security:
- apiKey: []
/api/test/{testId}:
get:
tags:
- firsttag
- secondtag
- thirdtag
operationId: "testGet"
description: "Get method"
parameters:
- name: testId
in: path
required: true
schema:
type: string
responses:
200:
description: "get"
security:
- apiKey: [ ]
components:
securitySchemes:
apiKey:

View File

@@ -87,7 +87,7 @@ where
post(create_repo::<I, A, E>)
)
.route("/repos/{repo_id}",
get(get_repo_info::<I, A, E>).get(get_repo_info::<I, A, E>)
get(get_repo_info::<I, A, E>)
)
.route("/required_octet_stream",
put(required_octet_stream_put::<I, A, E>)