diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java index 69282a23e0cc..1c883774d85e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java @@ -450,7 +450,15 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers); String underscoredOperationId = underscore(op.operationId); - ArrayList 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 pathMethods = pathMethodOpMap.get(axumPath); // Prevent multiple declarations of the same operation if (pathMethods != null && pathMethods.stream().anyMatch(pathMethod -> @@ -463,14 +471,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation 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( diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustAxumServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustAxumServerCodegenTest.java index 83c94e44d0ed..bb4150d38089 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustAxumServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/RustAxumServerCodegenTest.java @@ -28,6 +28,8 @@ public void testPreventDuplicateOperationDeclaration() throws IOException { String routerSpec = linearize("Router::new() " + ".route(\"/api/test\", " + "delete(test_delete::).post(test_post::) ) " + + ".route(\"/api/test/{test_id}\", " + + "get(test_get::) ) " + ".with_state(api_impl)"); TestUtils.assertFileExists(outputPath); TestUtils.assertFileContains(outputPath, routerSpec); diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_21144.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_21144.yaml index 749cc5ab38f1..a071edabff71 100644 --- a/modules/openapi-generator/src/test/resources/3_1/issue_21144.yaml +++ b/modules/openapi-generator/src/test/resources/3_1/issue_21144.yaml @@ -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: diff --git a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs index dc11ffb48867..0273bbe4ca35 100644 --- a/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs +++ b/samples/server/petstore/rust-axum/output/openapi-v3/src/server/mod.rs @@ -87,7 +87,7 @@ where post(create_repo::) ) .route("/repos/{repo_id}", - get(get_repo_info::).get(get_repo_info::) + get(get_repo_info::) ) .route("/required_octet_stream", put(required_octet_stream_put::)