Skip to content

Commit 59bae62

Browse files
authored
fix: Fix path param regex (#166)
* fix: Fix path param regex * Add bug reports to @antoniel
1 parent 6e2aa7b commit 59bae62

File tree

4 files changed

+127
-19
lines changed

4 files changed

+127
-19
lines changed

.all-contributorsrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"avatar_url": "https://avatars.githubusercontent.com/u/17225358?v=4",
7272
"profile": "https://github.com/antoniel",
7373
"contributions": [
74-
"example"
74+
"example",
75+
"bug"
7576
]
7677
},
7778
{

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,20 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
269269
<!-- prettier-ignore-start -->
270270
<!-- markdownlint-disable -->
271271
<table>
272-
<tbody>
273-
<tr>
274-
<td align="center" valign="top" width="14.28%"><a href="https://fabien0102.com/"><img src="https://avatars.githubusercontent.com/u/1761469?v=4?s=100" width="100px;" alt="Fabien BERNARD"/><br /><sub><b>Fabien BERNARD</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=fabien0102" title="Code">💻</a> <a href="#design-fabien0102" title="Design">🎨</a> <a href="https://github.com/fabien0102/openapi-codegen/commits?author=fabien0102" title="Documentation">📖</a> <a href="#ideas-fabien0102" title="Ideas, Planning, & Feedback">🤔</a> <a href="#projectManagement-fabien0102" title="Project Management">📆</a> <a href="https://github.com/fabien0102/openapi-codegen/pulls?q=is%3Apr+reviewed-by%3Afabien0102" title="Reviewed Pull Requests">👀</a></td>
275-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mpotomin"><img src="https://avatars.githubusercontent.com/u/639406?v=4?s=100" width="100px;" alt="mpotomin"/><br /><sub><b>mpotomin</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=mpotomin" title="Code">💻</a> <a href="#ideas-mpotomin" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/fabien0102/openapi-codegen/pulls?q=is%3Apr+reviewed-by%3Ampotomin" title="Reviewed Pull Requests">👀</a></td>
276-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/micha-f"><img src="https://avatars.githubusercontent.com/u/200647?v=4?s=100" width="100px;" alt="Michael Franzkowiak"/><br /><sub><b>Michael Franzkowiak</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=micha-f" title="Documentation">📖</a></td>
277-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/SferaDev"><img src="https://avatars.githubusercontent.com/u/2181866?v=4?s=100" width="100px;" alt="Alexis Rico"/><br /><sub><b>Alexis Rico</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=SferaDev" title="Code">💻</a> <a href="#ideas-SferaDev" title="Ideas, Planning, & Feedback">🤔</a></td>
278-
<td align="center" valign="top" width="14.28%"><a href="https://ned.im/"><img src="https://avatars.githubusercontent.com/u/271912?v=4?s=100" width="100px;" alt="Nedim Arabacı"/><br /><sub><b>Nedim Arabacı</b></sub></a><br /><a href="#question-needim" title="Answering Questions">💬</a> <a href="https://github.com/fabien0102/openapi-codegen/commits?author=needim" title="Code">💻</a> <a href="#ideas-needim" title="Ideas, Planning, & Feedback">🤔</a></td>
279-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/antoniel"><img src="https://avatars.githubusercontent.com/u/17225358?v=4?s=100" width="100px;" alt="Antoniel Magalhães"/><br /><sub><b>Antoniel Magalhães</b></sub></a><br /><a href="#example-antoniel" title="Examples">💡</a></td>
280-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/DreierF"><img src="https://avatars.githubusercontent.com/u/5631865?v=4?s=100" width="100px;" alt="Florian Dreier"/><br /><sub><b>Florian Dreier</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=DreierF" title="Code">💻</a></td>
281-
</tr>
282-
<tr>
283-
<td align="center" valign="top" width="14.28%"><a href="http://fabianalthaus.de"><img src="https://avatars.githubusercontent.com/u/2795534?v=4?s=100" width="100px;" alt="Fabian Althaus"/><br /><sub><b>Fabian Althaus</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=el-j" title="Code">💻</a></td>
284-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ci-vamp"><img src="https://avatars.githubusercontent.com/u/116516277?v=4?s=100" width="100px;" alt="ci-vamp"/><br /><sub><b>ci-vamp</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/issues?q=author%3Aci-vamp" title="Bug reports">🐛</a> <a href="https://github.com/fabien0102/openapi-codegen/commits?author=ci-vamp" title="Code">💻</a></td>
285-
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/oalanoliv"><img src="https://avatars.githubusercontent.com/u/4368481?v=4?s=100" width="100px;" alt="Alan Oliveira"/><br /><sub><b>Alan Oliveira</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=alan-oliv" title="Code">💻</a></td>
286-
</tr>
287-
</tbody>
272+
<tr>
273+
<td align="center"><a href="https://fabien0102.com/"><img src="https://avatars.githubusercontent.com/u/1761469?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fabien BERNARD</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=fabien0102" title="Code">💻</a> <a href="#design-fabien0102" title="Design">🎨</a> <a href="https://github.com/fabien0102/openapi-codegen/commits?author=fabien0102" title="Documentation">📖</a> <a href="#ideas-fabien0102" title="Ideas, Planning, & Feedback">🤔</a> <a href="#projectManagement-fabien0102" title="Project Management">📆</a> <a href="https://github.com/fabien0102/openapi-codegen/pulls?q=is%3Apr+reviewed-by%3Afabien0102" title="Reviewed Pull Requests">👀</a></td>
274+
<td align="center"><a href="https://github.com/mpotomin"><img src="https://avatars.githubusercontent.com/u/639406?v=4?s=100" width="100px;" alt=""/><br /><sub><b>mpotomin</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=mpotomin" title="Code">💻</a> <a href="#ideas-mpotomin" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/fabien0102/openapi-codegen/pulls?q=is%3Apr+reviewed-by%3Ampotomin" title="Reviewed Pull Requests">👀</a></td>
275+
<td align="center"><a href="https://github.com/micha-f"><img src="https://avatars.githubusercontent.com/u/200647?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michael Franzkowiak</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=micha-f" title="Documentation">📖</a></td>
276+
<td align="center"><a href="https://github.com/SferaDev"><img src="https://avatars.githubusercontent.com/u/2181866?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alexis Rico</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=SferaDev" title="Code">💻</a> <a href="#ideas-SferaDev" title="Ideas, Planning, & Feedback">🤔</a></td>
277+
<td align="center"><a href="https://ned.im/"><img src="https://avatars.githubusercontent.com/u/271912?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nedim Arabacı</b></sub></a><br /><a href="#question-needim" title="Answering Questions">💬</a> <a href="https://github.com/fabien0102/openapi-codegen/commits?author=needim" title="Code">💻</a> <a href="#ideas-needim" title="Ideas, Planning, & Feedback">🤔</a></td>
278+
<td align="center"><a href="https://github.com/antoniel"><img src="https://avatars.githubusercontent.com/u/17225358?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Antoniel Magalhães</b></sub></a><br /><a href="#example-antoniel" title="Examples">💡</a> <a href="https://github.com/fabien0102/openapi-codegen/issues?q=author%3Aantoniel" title="Bug reports">🐛</a></td>
279+
<td align="center"><a href="https://github.com/DreierF"><img src="https://avatars.githubusercontent.com/u/5631865?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Florian Dreier</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=DreierF" title="Code">💻</a></td>
280+
</tr>
281+
<tr>
282+
<td align="center"><a href="http://fabianalthaus.de"><img src="https://avatars.githubusercontent.com/u/2795534?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fabian Althaus</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=el-j" title="Code">💻</a></td>
283+
<td align="center"><a href="https://github.com/ci-vamp"><img src="https://avatars.githubusercontent.com/u/116516277?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ci-vamp</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/issues?q=author%3Aci-vamp" title="Bug reports">🐛</a> <a href="https://github.com/fabien0102/openapi-codegen/commits?author=ci-vamp" title="Code">💻</a></td>
284+
<td align="center"><a href="https://twitter.com/oalanoliv"><img src="https://avatars.githubusercontent.com/u/4368481?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alan Oliveira</b></sub></a><br /><a href="https://github.com/fabien0102/openapi-codegen/commits?author=alan-oliv" title="Code">💻</a></td>
285+
</tr>
288286
</table>
289287
290288
<!-- markdownlint-restore -->

plugins/typescript/src/core/createOperationFetcherFnNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ export const createOperationFetcherFnNodes = ({
141141
* `pet/{pet_id}` -> `pet/{petId}`
142142
*/
143143
const camelizedPathParams = (url: string) =>
144-
url.replace(/\{\w*\}/g, (match) => `{${camel(match)}}`);
144+
url.replace(/\{.*\}/g, (match) => `{${camel(match)}}`);

plugins/typescript/src/generators/generateReactQueryComponents.test.ts

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ describe("generateReactQueryComponents", () => {
860860
`);
861861
});
862862

863-
it("should deal with pathParams", async () => {
863+
it("should deal with pathParams (snake case)", async () => {
864864
const writeFile = jest.fn();
865865
const openAPIDocument: OpenAPIObject = {
866866
openapi: "3.0.0",
@@ -969,6 +969,115 @@ describe("generateReactQueryComponents", () => {
969969
`);
970970
});
971971

972+
it("should deal with pathParams (kebab case)", async () => {
973+
const writeFile = jest.fn();
974+
const openAPIDocument: OpenAPIObject = {
975+
openapi: "3.0.0",
976+
info: {
977+
title: "petshop",
978+
version: "1.0.0",
979+
},
980+
components: {
981+
requestBodies: {
982+
UpdatePetRequestBody: {
983+
content: {
984+
"application/json": {
985+
schema: {
986+
type: "object",
987+
properties: {
988+
name: {
989+
type: "string",
990+
},
991+
},
992+
},
993+
},
994+
},
995+
},
996+
},
997+
},
998+
paths: {
999+
"/pet/{pet-id}": {
1000+
parameters: [
1001+
{
1002+
in: "path",
1003+
name: "pet-id",
1004+
schema: {
1005+
type: "string",
1006+
},
1007+
required: true,
1008+
},
1009+
],
1010+
put: {
1011+
operationId: "updatePet",
1012+
requestBody: {
1013+
$ref: "#/components/requestBodies/UpdatePetRequestBody",
1014+
},
1015+
responses: {
1016+
200: {
1017+
content: {
1018+
"application/json": {
1019+
description: "Successful response",
1020+
schema: {
1021+
type: "string",
1022+
},
1023+
},
1024+
},
1025+
},
1026+
},
1027+
},
1028+
},
1029+
},
1030+
};
1031+
await generateReactQueryComponents(
1032+
{
1033+
openAPIDocument,
1034+
writeFile,
1035+
existsFile: () => true,
1036+
readFile: async () => "",
1037+
},
1038+
config
1039+
);
1040+
1041+
expect(writeFile.mock.calls[0][0]).toBe("petstoreComponents.ts");
1042+
expect(writeFile.mock.calls[0][1]).toMatchInlineSnapshot(`
1043+
"/**
1044+
* Generated by @openapi-codegen
1045+
*
1046+
* @version 1.0.0
1047+
*/
1048+
import * as reactQuery from \\"@tanstack/react-query\\";
1049+
import { usePetstoreContext, PetstoreContext } from \\"./petstoreContext\\";
1050+
import type * as Fetcher from \\"./petstoreFetcher\\";
1051+
import { petstoreFetch } from \\"./petstoreFetcher\\";
1052+
import type * as RequestBodies from \\"./petstoreRequestBodies\\";
1053+
1054+
export type UpdatePetPathParams = {
1055+
petId: string;
1056+
};
1057+
1058+
export type UpdatePetError = Fetcher.ErrorWrapper<undefined>;
1059+
1060+
export type UpdatePetVariables = {
1061+
body?: RequestBodies.UpdatePetRequestBody;
1062+
pathParams: UpdatePetPathParams;
1063+
} & PetstoreContext[\\"fetcherOptions\\"];
1064+
1065+
export const fetchUpdatePet = (variables: UpdatePetVariables, signal?: AbortSignal) => petstoreFetch<string, UpdatePetError, RequestBodies.UpdatePetRequestBody, {}, {}, UpdatePetPathParams>({ url: \\"/pet/{petId}\\", method: \\"put\\", ...variables, signal });
1066+
1067+
export const useUpdatePet = (options?: Omit<reactQuery.UseMutationOptions<string, UpdatePetError, UpdatePetVariables>, \\"mutationFn\\">) => {
1068+
const { fetcherOptions } = usePetstoreContext();
1069+
return reactQuery.useMutation<string, UpdatePetError, UpdatePetVariables>((variables: UpdatePetVariables) => fetchUpdatePet({ ...fetcherOptions, ...variables }), options);
1070+
};
1071+
1072+
export type QueryOperation = {
1073+
path: string;
1074+
operationId: never;
1075+
variables: unknown;
1076+
};
1077+
"
1078+
`);
1079+
});
1080+
9721081
it("should build components without prefix", async () => {
9731082
const writeFile = jest.fn();
9741083
const openAPIDocument: OpenAPIObject = {

0 commit comments

Comments
 (0)