Skip to content

[BUG] Incorrect enum values for typescript clients #7369

@epidemia

Description

@epidemia

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issuue still exists?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Enum values are generated incorrectly for PascalCase enum property naming type when the source enum values are in uppercase with underscores.
For example, original enum values:

"BookType": {
        "type": "string",
        "description": "Book Type",
        "example": "SCIENCE",
        "enum": [
          "SCIENCE",
          "SCIENCE_FICTION"
        ]
      }

Expected enum values:

export enum BookType {
  Science = 'SCIENCE',
  ScienceFiction = 'SCIENCE_FICTION'
}

Actual enum values:

export enum BookType {
  SCIENCE = 'SCIENCE',
  SCIENCEFICTION = 'SCIENCE_FICTION'
}
openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "OpenAPI definition",
    "version": "v0"
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/books/{id}": {
      "get": {
        "tags": [
          "controller"
        ],
        "description": "Get book by ID",
        "operationId": "getBookById",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/Book"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Book": {
        "required": [
          "id",
          "type"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "ID",
            "format": "uuid"
          },
          "type": {
            "type": "string",
            "description": "Book type",
            "enum": [
              "SCIENCE",
              "SCIENCE_FICTION"
            ]
          }
        },
        "description": "Book"
      }
    },
    "securitySchemes": {
      "basicScheme": {
        "type": "http",
        "scheme": "basic"
      }
    }
  }
}
Generation Details

Generator: typescript-axios
Config options:

<configOptions>
   <enumPropertyNaming>PascalCase</enumPropertyNaming>
</configOptions>
Steps to reproduce

This issue can be reproduced by using the typescript-axios generator with the OpenAPI declaration & config from above.

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions