From 38dfed41048e6cfe5a2b646fd5f57cad7a9c1733 Mon Sep 17 00:00:00 2001 From: "Andy.Yang.cn" Date: Thu, 23 Apr 2020 01:00:21 +0800 Subject: [PATCH] [Rust Server] Fix #5947 multi tag generate multi method issue. (#5928) * [Rust Server] Fix issue with multiple tags on an operation generating duplicate methods. * [Rust Server] Add test case yaml with multiple tags on a single operation. --- .../codegen/languages/RustServerCodegen.java | 21 +++++++++++++++++++ .../resources/3_0/rust-server/openapi-v3.yaml | 2 +- .../output/openapi-v3/api/openapi.yaml | 1 + .../output/openapi-v3/docs/info_api.md | 8 +++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 samples/server/petstore/rust-server/output/openapi-v3/docs/info_api.md diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index ebc90e9f921..59cb70612ae 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -1111,6 +1111,27 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { return dataType != null && dataType.equals(typeMapping.get("File").toString()); } + /** + * Add operation to group + * + * @param tag name of the tag + * @param resourcePath path of the resource + * @param operation OAS Operation object + * @param co Codegen Operation object + * @param operations map of Codegen operations + */ + @SuppressWarnings("static-method") + @Override + public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation + co, Map> operations) { + // only generate operation for the first tag of the tags + if (tag != null && co.tags.size() > 1 && !tag.equals(co.tags.get(0).getName())) { + LOGGER.info("generated skip additional tag `" + tag + "` with operationId=" + co.operationId); + return; + } + super.addOperationToGroup(tag, resourcePath, operation, co, operations); + } + // This is a really terrible hack. We're working around the fact that the // base version of `fromRequestBody` checks to see whether the body is a // ref. If so, it unwraps the reference and replaces it with its inner diff --git a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml index 0fe69a95d45..c0a90d8e521 100644 --- a/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/rust-server/openapi-v3.yaml @@ -362,7 +362,7 @@ paths: type: string required: true get: - tags: [Repo] + tags: [Repo, Info] operationId: GetRepoInfo responses: "200": diff --git a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml index 10f0ea0cc18..ad1c605bb9e 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/openapi-v3/api/openapi.yaml @@ -384,6 +384,7 @@ paths: description: OK tags: - Repo + - Info components: schemas: EnumWithStarObject: diff --git a/samples/server/petstore/rust-server/output/openapi-v3/docs/info_api.md b/samples/server/petstore/rust-server/output/openapi-v3/docs/info_api.md new file mode 100644 index 00000000000..a1477c469f9 --- /dev/null +++ b/samples/server/petstore/rust-server/output/openapi-v3/docs/info_api.md @@ -0,0 +1,8 @@ +# info_api + +All URIs are relative to *http://localhost* + +Method | HTTP request | Description +------------- | ------------- | ------------- + +