Skip to content

Commit

Permalink
fix: path parameters are not encoded #679
Browse files Browse the repository at this point in the history
(cherry picked from commit 1c8a2ed)
  • Loading branch information
Maxim-Mazurok committed Jul 13, 2023
1 parent b361cb9 commit df2d4ba
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const listPets = (
signal?: AbortSignal,
) => {
return customInstance<Pets>({
url: `/v${version}/pets`,
url: `/v${encodeURIComponent(String(version))}/pets`,
method: 'get',
params,
signal,
Expand Down Expand Up @@ -214,7 +214,7 @@ export const useListPets = <
*/
export const createPets = (createPetsBody: CreatePetsBody, version = 1) => {
return customInstance<Pet>({
url: `/v${version}/pets`,
url: `/v${encodeURIComponent(String(version))}/pets`,
method: 'post',
headers: { 'Content-Type': 'application/json' },
data: createPetsBody,
Expand Down Expand Up @@ -281,7 +281,7 @@ export const useCreatePets = <
*/
export const updatePets = (pet: NonReadonly<Pet>, version = 1) => {
return customInstance<Pet>({
url: `/v${version}/pets`,
url: `/v${encodeURIComponent(String(version))}/pets`,
method: 'put',
headers: { 'Content-Type': 'application/json' },
data: pet,
Expand Down Expand Up @@ -352,7 +352,9 @@ export const showPetById = (
signal?: AbortSignal,
) => {
return customInstance<Pet>({
url: `/v${version}/pets/${petId}`,
url: `/v${encodeURIComponent(String(version))}/pets/${encodeURIComponent(
String(petId),
)}`,
method: 'get',
signal,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useListPetsHook = () => {

return (params?: ListPetsParams, version = 1, signal?: AbortSignal) => {
return listPets({
url: `/v${version}/pets`,
url: `/v${encodeURIComponent(String(version))}/pets`,
method: 'get',
params,
signal,
Expand Down Expand Up @@ -119,7 +119,7 @@ export const useCreatePetsHook = () => {

return (createPetsBody: BodyType<CreatePetsBody>, version = 1) => {
return createPets({
url: `/v${version}/pets`,
url: `/v${encodeURIComponent(String(version))}/pets`,
method: 'post',
headers: { 'Content-Type': 'application/json' },
data: createPetsBody,
Expand Down Expand Up @@ -192,7 +192,9 @@ export const useShowPetByIdHook = () => {

return (petId: string, version = 1, signal?: AbortSignal) => {
return showPetById({
url: `/v${version}/pets/${petId}`,
url: `/v${encodeURIComponent(String(version))}/pets/${encodeURIComponent(
String(petId),
)}`,
method: 'get',
signal,
});
Expand Down
6 changes: 5 additions & 1 deletion samples/react-query/hook-mutator/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ export const useShowPetByIdHook = () => {
const showPetById = useCustomInstance<Pet>();

return (petId: string, signal?: AbortSignal) => {
return showPetById({ url: `/pets/${petId}`, method: 'get', signal });
return showPetById({
url: `/pets/${encodeURIComponent(String(petId))}`,
method: 'get',
signal,
});
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const listPets = (
signal?: AbortSignal,
) => {
return customInstance<Pets>({
url: `/v${version}/pets`,
url: `/v${encodeURIComponent(String(version))}/pets`,
method: 'get',
params,
signal,
Expand Down Expand Up @@ -108,7 +108,7 @@ export const createListPets = <
*/
export const createPets = (createPetsBody: CreatePetsBody, version = 1) => {
return customInstance<void>({
url: `/v${version}/pets`,
url: `/v${encodeURIComponent(String(version))}/pets`,
method: 'post',
headers: { 'Content-Type': 'application/json' },
data: createPetsBody,
Expand Down Expand Up @@ -176,7 +176,9 @@ export const showPetById = (
signal?: AbortSignal,
) => {
return customInstance<Pet>({
url: `/v${version}/pets/${petId}`,
url: `/v${encodeURIComponent(String(version))}/pets/${encodeURIComponent(
String(petId),
)}`,
method: 'get',
signal,
});
Expand Down
2 changes: 1 addition & 1 deletion samples/vue-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@faker-js/faker": "^7.3.0",
"@tanstack/vue-query": "4.29.5",
"axios": "^0.26.1",
"vue": "3.2.36"
"vue": "^3.3.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.2.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
UseInfiniteQueryReturnType,
} from '@tanstack/vue-query';
import { unref } from 'vue';
import type { MaybeRef } from '@tanstack/vue-query/build/lib/types';
import type { MaybeRef } from 'vue';
import type {
Pets,
Error,
Expand All @@ -39,7 +39,7 @@ export const listPets = (
signal?: AbortSignal,
) => {
return customInstance<Pets>({
url: `/v${unref(version)}/pets`,
url: `/v${encodeURIComponent(String(unref(version)))}/pets`,
method: 'get',
params,
signal,
Expand Down Expand Up @@ -185,7 +185,7 @@ export const createPets = (
version = 1,
) => {
return customInstance<Pet>({
url: `/v${unref(version)}/pets`,
url: `/v${encodeURIComponent(String(unref(version)))}/pets`,
method: 'post',
headers: { 'Content-Type': 'application/json' },
data: createPetsBody,
Expand Down Expand Up @@ -253,7 +253,9 @@ export const showPetById = (
signal?: AbortSignal,
) => {
return customInstance<Pet>({
url: `/v${unref(version)}/pets/${unref(petId)}`,
url: `/v${encodeURIComponent(
String(unref(version)),
)}/pets/${encodeURIComponent(String(unref(petId)))}`,
method: 'get',
signal,
});
Expand Down
2 changes: 1 addition & 1 deletion samples/vue-query/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler", // as per default in node_modules/@vue/tsconfig/tsconfig.json
"strict": true,
"jsx": "preserve",
"sourceMap": true,
Expand Down
Loading

0 comments on commit df2d4ba

Please sign in to comment.