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

Incorrect enum ApiPaths members when parametrized paths

Open wgebczyk opened this issue 8 months ago • 0 comments

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

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

Extra

wgebczyk avatar Mar 09 '25 10:03 wgebczyk