Skip to content

Commit 47e4b5e

Browse files
authored
fix(openapi-typescript): --make-paths-enum renames the paths URL (#2152)
* [transform/paths] Remove parameters replacing * fix tests * Create little-meals-hide.md * Update paths-enum.ts * Update little-meals-hide.md
1 parent 58a2c91 commit 47e4b5e

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

.changeset/little-meals-hide.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-typescript": patch
3+
---
4+
5+
- Fixed --make-paths-enum option transforming the paths URL (`:id` instead of `{id}`)

packages/openapi-typescript/src/transform/paths-enum.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ export default function makeApiPathsEnum(pathsObject: PathsObject): ts.EnumDecla
3030
})
3131
.join("");
3232
}
33-
34-
// Replace {parameters} with :parameters
35-
const adaptedUrl = url.replace(/{(\w+)}/g, ":$1");
36-
37-
enumKeys.push(adaptedUrl);
33+
enumKeys.push(url);
3834
enumMetaData.push({
3935
name: pathName,
4036
});

packages/openapi-typescript/test/transform/paths-enum.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("transformPathsObjectToEnum", () => {
3838
},
3939
},
4040
want: `export enum ApiPaths {
41-
GetApiV1User = "/api/v1/user/:user_id"
41+
GetApiV1User = "/api/v1/user/{user_id}"
4242
}`,
4343
},
4444
],
@@ -62,7 +62,7 @@ describe("transformPathsObjectToEnum", () => {
6262
},
6363
},
6464
want: `export enum ApiPaths {
65-
GetUserById = "/api/v1/user/:user_id"
65+
GetUserById = "/api/v1/user/{user_id}"
6666
}`,
6767
},
6868
],
@@ -89,8 +89,8 @@ describe("transformPathsObjectToEnum", () => {
8989
},
9090
},
9191
want: `export enum ApiPaths {
92-
GetUserById = "/api/v1/user/:user_id",
93-
PostApiV1User = "/api/v1/user/:user_id"
92+
GetUserById = "/api/v1/user/{user_id}",
93+
PostApiV1User = "/api/v1/user/{user_id}"
9494
}`,
9595
},
9696
],

0 commit comments

Comments
 (0)