mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-04-24 19:19:11 +00:00
[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:
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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>)
|
||||
|
||||
Reference in New Issue
Block a user