openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][typescript-angular] Multiple tags and `useSingleRequestParameter` cause duplicate export

Open snebjorn opened this issue 3 years ago • 2 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
    • Issue is still present in master https://github.com/snebjorn/openapi-gen-bug/tree/master/output-master/export-bug
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Defining operations with multiple tags leads to duplicate export.

https://github.com/snebjorn/openapi-gen-bug/blob/ad3851d72b3a9bfe8bc49604730d013e03813b73/export-bug.json#L19

Module './tag1.service' has already exported a member named 'FoosParam1BarsGetRequestParams'. Consider explicitly re-exporting to resolve the ambiguity. ts(2308)

FoosParam1BarsGetRequestParams is declared in both these places:

  • https://github.com/snebjorn/openapi-gen-bug/blob/ad3851d72b3a9bfe8bc49604730d013e03813b73/output-6.0.1/export-bug/api/tag1.service.ts#L27
  • https://github.com/snebjorn/openapi-gen-bug/blob/ad3851d72b3a9bfe8bc49604730d013e03813b73/output-6.0.1/export-bug/api/tag2.service.ts#L27
openapi-generator version

6.0.1

OpenAPI declaration file content or url

https://raw.githubusercontent.com/snebjorn/openapi-gen-bug/master/export-bug.json

{
  "openapi": "3.0.0",
  "info": {
    "title": "",
    "version": ""
  },
  "paths": {
    "/Foos/{Param1}/Bars": {
      "parameters": [
        {
          "name": "Param1",
          "in": "path",
          "required": true,
          "description": "",
          "schema": { "type": "string" }
        }
      ],
      "get": {
        "tags": ["Tag1", "Tag2"],
        "responses": {
          "200": {
            "description": ""
          }
        }
      }
    }
  }
}
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://raw.githubusercontent.com/snebjorn/openapi-gen-bug/master/export-bug.json \
   -g typescript-angular \
   -o output-master/export-bug \
   -p=useSingleRequestParameter=true
Steps to reproduce
  1. Clone https://github.com/snebjorn/openapi-gen-bug
  2. Run yarn install
  3. Run yarn gen
  4. Observe export error in https://github.com/snebjorn/openapi-gen-bug/blob/master/output-6.0.1/export-bug/api/api.ts
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/7519

Suggest a fix

Prefix with their tag as to avoid duplicate exports.

snebjorn avatar Aug 16 '22 14:08 snebjorn

    "tags": ["Tag1", "Tag2"],

In your case, you want only "Tag1" to be used for code generation, right?

wing328 avatar Sep 20 '22 03:09 wing328

Personally I don't need a the same service duplicated across multiple tags. So yes only using Tag1 would work in my scenario. But I can't speak for all scenarios, someone might need that.

snebjorn avatar Sep 20 '22 05:09 snebjorn

We've added a rule in openapi-normalizer to use only the first tag: KEEP_ONLY_FIRST_TAG_IN_OPERATION

https://openapi-generator.tech/docs/customization/#openapi-normalizer

Please give it a try when you've time.

Closing this for the time being

wing328 avatar Aug 19 '23 05:08 wing328