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

Add a way to export a mapped type of all operationId => path

Open ghoullier opened this issue 2 years ago • 0 comments

Description

API entry points are associated to operationId in OpenAPI schema. Path Enum was a solution in openapi-typescript@<6 to get a map of all operations register in the API. This option was removed in v6+ due to an incompatibility with --path-params-as-types option.

Proposal

We can add a cli flag --export-operation-id-paths (name can be improved)

According to the generated code is pure TypeScript it's fully compatible with --path-params-as-types

export type OperationIdPaths = {
  getStuff: `/api/v0/stuff/${string}`
}

Without --path-params-as-types

export type OperationIdPaths = {
  getStuff: `/api/v0/stuff/:uuid`
}

This approach allow developers to easily generate a variable implementing the type using TypeScript refactoring capabilities (see video below)

https://user-images.githubusercontent.com/2315749/206891181-ff53a095-38ee-41dd-af28-b823e6195d44.mov

Checklist

ghoullier avatar Dec 11 '22 07:12 ghoullier