diff --git a/.changeset/little-meals-hide.md b/.changeset/little-meals-hide.md new file mode 100644 index 000000000..db4647f59 --- /dev/null +++ b/.changeset/little-meals-hide.md @@ -0,0 +1,5 @@ +--- +"openapi-typescript": patch +--- + +- Fixed --make-paths-enum option transforming the paths URL (`:id` instead of `{id}`) diff --git a/packages/openapi-typescript/src/transform/paths-enum.ts b/packages/openapi-typescript/src/transform/paths-enum.ts index 78d33b313..ea2fbdb43 100644 --- a/packages/openapi-typescript/src/transform/paths-enum.ts +++ b/packages/openapi-typescript/src/transform/paths-enum.ts @@ -30,11 +30,7 @@ export default function makeApiPathsEnum(pathsObject: PathsObject): ts.EnumDecla }) .join(""); } - - // Replace {parameters} with :parameters - const adaptedUrl = url.replace(/{(\w+)}/g, ":$1"); - - enumKeys.push(adaptedUrl); + enumKeys.push(url); enumMetaData.push({ name: pathName, }); diff --git a/packages/openapi-typescript/test/transform/paths-enum.test.ts b/packages/openapi-typescript/test/transform/paths-enum.test.ts index 37ee91e23..191540a97 100644 --- a/packages/openapi-typescript/test/transform/paths-enum.test.ts +++ b/packages/openapi-typescript/test/transform/paths-enum.test.ts @@ -38,7 +38,7 @@ describe("transformPathsObjectToEnum", () => { }, }, want: `export enum ApiPaths { - GetApiV1User = "/api/v1/user/:user_id" + GetApiV1User = "/api/v1/user/{user_id}" }`, }, ], @@ -62,7 +62,7 @@ describe("transformPathsObjectToEnum", () => { }, }, want: `export enum ApiPaths { - GetUserById = "/api/v1/user/:user_id" + GetUserById = "/api/v1/user/{user_id}" }`, }, ], @@ -89,8 +89,8 @@ describe("transformPathsObjectToEnum", () => { }, }, want: `export enum ApiPaths { - GetUserById = "/api/v1/user/:user_id", - PostApiV1User = "/api/v1/user/:user_id" + GetUserById = "/api/v1/user/{user_id}", + PostApiV1User = "/api/v1/user/{user_id}" }`, }, ],