Skip to content

Incorrect enum ApiPaths members when parametrized paths #2194

Open
@wgebczyk

Description

@wgebczyk

openapi-typescript version

7.6.1

Node.js version

23.9.0

OS + version

win11

Description

Hey!

It seems that code that generates ApiPath enum incorrectly tries to deduplicate enum identifiers when paths differs on params. This is as well visible when path has multple params of various level of reusing parameter names.

Reproduction

Small open ap spec

{
  "openapi": "3.0.4",
  "info": { "title": "some api", "version": "1" },
  "servers": [ { "url": "uri:some-api" } ],
  "paths": {
    "/api/block": {
      "get": {
        "summary": "whatever",
        "tags": [ "Block" ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": { "schema": { "type": "string" } }
            }
          }
        }
      }
    },
    "/api/block/{blockId}": {
      "get": {
        "summary": "whatever",
        "tags": [ "Block" ],
        "parameters": [
          { "name": "blockId", "in": "path", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": { "schema": { "type": "string" } }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "awesome": {
        "type": "oauth2",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://example.com/oauth2/authorize",
            "scopes": { "awesome": "Awesome scope" }
          }
        }
      }
    }
  },
  "security": [ { "awesome": [ "awesome" ] } ]
}

command line:

npx openapi-typescript "C:\...\repro.json" -o ./repro.schema.d.ts --make-paths-enum

output:

(...)
export enum ApiPaths {
    GetApiBlock = "/api/block",
    GetApiBlock = "/api/block/:blockId"
}

Expected result

not have same enum member identifiers

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions