Skip to content

Duplicate typename error when generating for Jira Cloud API #1878

Open

Description

I'm getting this error:

$ curl -sSfL 'https://dac-static.atlassian.com/cloud/jira/platform/swagger.v3.json?_v=1.7651.0-0.1317.0' | go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v2.4.1 /dev/stdin
error generating code: error generating type definitions: error generating code for type definitions: duplicate typename 'ApprovalConfigurationExclude' detected, can't auto-rename, please use x-go-name to specify your own name for one of them
exit status 1

I've tried virtually all compatibility and output options, but nothing fixes the problem. Inspecting the input JSON file, things look legit: the type is defined, plus 2 references. My guess is that the enum is being generated with duplicated names. This may be the same as #1449, and may be a bug.

Activity

  1. paulmach commented on Jan 9, 2025

    @paulmach
    Contributor

    This is due to a couple of issues in the schema:

    components:
       schemas:
         "ApprovalConfiguration": {
             "properties": {
                 ....
                 "exclude": {
                     "enum": [ <-- enum for an array type?
                         "assignee",
                         "reporter"
                      ],
                      "items": {
                          "enum": [
                              "assignee",
                              "reporter"
                          ],
                          "nullable": true,
                          "type": "string"
                      },
                      "nullable": true,
                      "type": "array"
                 },
    

    I left out some bits but the first enum creates the ApprovalConfigurationExclude type. Then the second enum creates another enum type with the same name. This I believe is fixable by ignoring enums for array types, or auto assigning it to the items.

    The second issues is more complicated.

    components:
       schemas:
           "ProjectFeature": {
               "properties": {
                   ....
                   "state": {
                       "enum": [
                           "ENABLED",
                           "DISABLED",
                            "COMING_SOON"
                       ],
                   "type": "string"
               },
    

    and

    components:
       schemas:
          "ProjectFeatureState": {
               "additionalProperties": false,
               "description": "Details of the feature state.",
                "properties": {
                    "state": {
                        "description": "The feature state.",
                        "enum": [
                            "ENABLED",
                            "DISABLED",
                            "COMING_SOON"
                        ],
                        "type": "string"
                    }
                },
                "type": "object"
           },
    

    These will generate the same ProjectFeatureStateState enum. Might need to deduplicate or rename somehow.

    Not exactly sure of the fixes, but those are the causes.

  2. paulmach commented on Jan 11, 2025

    @paulmach
    Contributor

    Other generators append a number, so one would be ProjectFeatureStateState and the other ProjectFeatureStateState0. I think this is the enhancement that oapi-codegen needs. I tried adding this but ran into issues.

    As for getting it to work for you right now, you can try using an OpenAPI Overlay https://github.com/oapi-codegen/oapi-codegen?tab=readme-ov-file#modifying-the-input-openapi-specification I've never used it but you could use it to add the x-go-name extensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions