Skip to content

Commit

Permalink
fix: use of dataReturnType to set res.data or res (#720)
Browse files Browse the repository at this point in the history
* fix: use of `dataReturnType` to set res.data or res

* chore: cleanup generics

* chore: regen examples

* chore: update snapshots
  • Loading branch information
stijnvanhulle authored Dec 13, 2023
1 parent 74e9864 commit 787365b
Show file tree
Hide file tree
Showing 207 changed files with 2,340 additions and 1,776 deletions.
7 changes: 7 additions & 0 deletions .changeset/mighty-months-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@kubb/swagger-tanstack-query": patch
"@kubb/swagger-client": patch
"@kubb/swagger-swr": patch
---

use of `dataReturnType` to set res.data or res
3 changes: 2 additions & 1 deletion examples/advanced/src/gen/clients/axios/petService/addPet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export async function addPet(
data: AddPetMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<AddPetMutationResponse>> {
return client<AddPetMutationResponse, AddPetMutationRequest>({
const res = await client<AddPetMutationResponse, AddPetMutationRequest>({
method: 'post',
url: `/pet`,
data,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export async function deletePet(
headers?: DeletePetHeaderParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<DeletePetMutationResponse>> {
return client<DeletePetMutationResponse>({
const res = await client<DeletePetMutationResponse>({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...options.headers },
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export async function findPetsByStatus(
params?: FindPetsByStatusQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<FindPetsByStatusQueryResponse>> {
return client<FindPetsByStatusQueryResponse>({
const res = await client<FindPetsByStatusQueryResponse>({
method: 'get',
url: `/pet/findByStatus`,
params,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ export async function findPetsByTags(
params?: FindPetsByTagsQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<FindPetsByTagsQueryResponse>> {
return client<FindPetsByTagsQueryResponse>({
const res = await client<FindPetsByTagsQueryResponse>({
method: 'get',
url: `/pet/findByTags`,
params,
headers: { ...headers, ...options.headers },
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export async function getPetById(
{ petId }: GetPetByIdPathParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<GetPetByIdQueryResponse>> {
return client<GetPetByIdQueryResponse>({
const res = await client<GetPetByIdQueryResponse>({
method: 'get',
url: `/pet/${petId}`,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export async function updatePet(
data: UpdatePetMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<UpdatePetMutationResponse>> {
return client<UpdatePetMutationResponse, UpdatePetMutationRequest>({
const res = await client<UpdatePetMutationResponse, UpdatePetMutationRequest>({
method: 'put',
url: `/pet`,
data,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ export async function updatePetWithForm(
params?: UpdatePetWithFormQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<UpdatePetWithFormMutationResponse>> {
return client<UpdatePetWithFormMutationResponse>({
const res = await client<UpdatePetWithFormMutationResponse>({
method: 'post',
url: `/pet/${petId}`,
params,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ export async function uploadFile(
params?: UploadFileQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<UploadFileMutationResponse>> {
return client<UploadFileMutationResponse, UploadFileMutationRequest>({
const res = await client<UploadFileMutationResponse, UploadFileMutationRequest>({
method: 'post',
url: `/pet/${petId}/uploadImage`,
params,
data,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ export async function createPets(
params?: CreatePetsQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<CreatePetsMutationResponse>> {
return client<CreatePetsMutationResponse, CreatePetsMutationRequest>({
const res = await client<CreatePetsMutationResponse, CreatePetsMutationRequest>({
method: 'post',
url: `/pets/${uuid}`,
params,
data,
headers: { ...headers, ...options.headers },
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export async function createUser(
data?: CreateUserMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<CreateUserMutationResponse>> {
return client<CreateUserMutationResponse, CreateUserMutationRequest>({
const res = await client<CreateUserMutationResponse, CreateUserMutationRequest>({
method: 'post',
url: `/user`,
data,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export async function createUsersWithListInput(
data?: CreateUsersWithListInputMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<CreateUsersWithListInputMutationResponse>> {
return client<CreateUsersWithListInputMutationResponse, CreateUsersWithListInputMutationRequest>({
const res = await client<CreateUsersWithListInputMutationResponse, CreateUsersWithListInputMutationRequest>({
method: 'post',
url: `/user/createWithList`,
data,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export async function deleteUser(
{ username }: DeleteUserPathParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<DeleteUserMutationResponse>> {
return client<DeleteUserMutationResponse>({
const res = await client<DeleteUserMutationResponse>({
method: 'delete',
url: `/user/${username}`,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export async function getUserByName(
{ username }: GetUserByNamePathParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<GetUserByNameQueryResponse>> {
return client<GetUserByNameQueryResponse>({
const res = await client<GetUserByNameQueryResponse>({
method: 'get',
url: `/user/${username}`,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export async function loginUser(
params?: LoginUserQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<LoginUserQueryResponse>> {
return client<LoginUserQueryResponse>({
const res = await client<LoginUserQueryResponse>({
method: 'get',
url: `/user/login`,
params,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import type { LogoutUserQueryResponse } from '../../../models/ts/userController/
* @summary Logs out current logged in user session
* @link /user/logout */
export async function logoutUser(options: Partial<Parameters<typeof client>[0]> = {}): Promise<ResponseConfig<LogoutUserQueryResponse>> {
return client<LogoutUserQueryResponse>({
const res = await client<LogoutUserQueryResponse>({
method: 'get',
url: `/user/logout`,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export async function updateUser(
data?: UpdateUserMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<UpdateUserMutationResponse>> {
return client<UpdateUserMutationResponse, UpdateUserMutationRequest>({
const res = await client<UpdateUserMutationResponse, UpdateUserMutationRequest>({
method: 'put',
url: `/user/${username}`,
data,
...options,
})
return res
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type AddPet = {
queryParams: never
headerParams: never
response: Awaited<ReturnType<AddPetClient>>
unionResponse: Awaited<ReturnType<AddPetClient>> | AddPetMutationResponse
client: {
paramaters: Partial<Parameters<AddPetClient>[0]>
return: Awaited<ReturnType<AddPetClient>>
Expand All @@ -22,19 +21,20 @@ type AddPet = {
* @description Add a new pet to the store
* @summary Add a new pet to the store
* @link /pet */
export function useAddPet<TData = AddPet['response'], TError = AddPet['error']>(options: {
mutation?: UseMutationOptions<TData, TError, AddPet['request']>
export function useAddPet(options: {
mutation?: UseMutationOptions<AddPet['response'], AddPet['error'], AddPet['request']>
client?: AddPet['client']['paramaters']
} = {}): UseMutationResult<TData, TError, AddPet['request']> {
} = {}): UseMutationResult<AddPet['response'], AddPet['error'], AddPet['request']> {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation<TData, TError, AddPet['request']>({
mutationFn: (data) => {
return client<AddPet['data'], TError, AddPet['request']>({
return useMutation<AddPet['response'], AddPet['error'], AddPet['request']>({
mutationFn: async (data) => {
const res = await client<AddPet['data'], AddPet['error'], AddPet['request']>({
method: 'post',
url: `/pet`,
data,
...clientOptions,
}).then(res => res as TData)
})
return res
},
...mutationOptions,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type DeletePet = {
queryParams: never
headerParams: DeletePetHeaderParams
response: Awaited<ReturnType<DeletePetClient>>
unionResponse: Awaited<ReturnType<DeletePetClient>> | DeletePetMutationResponse
client: {
paramaters: Partial<Parameters<DeletePetClient>[0]>
return: Awaited<ReturnType<DeletePetClient>>
Expand All @@ -22,23 +21,20 @@ type DeletePet = {
* @description delete a pet
* @summary Deletes a pet
* @link /pet/:petId */
export function useDeletePet<TData = DeletePet['response'], TError = DeletePet['error']>(
petId: DeletePetPathParams['petId'],
headers?: DeletePet['headerParams'],
options: {
mutation?: UseMutationOptions<TData, TError, void>
client?: DeletePet['client']['paramaters']
} = {},
): UseMutationResult<TData, TError, void> {
export function useDeletePet(petId: DeletePetPathParams['petId'], headers?: DeletePet['headerParams'], options: {
mutation?: UseMutationOptions<DeletePet['response'], DeletePet['error'], void>
client?: DeletePet['client']['paramaters']
} = {}): UseMutationResult<DeletePet['response'], DeletePet['error'], void> {
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
return useMutation<TData, TError, void>({
mutationFn: () => {
return client<DeletePet['data'], TError, void>({
return useMutation<DeletePet['response'], DeletePet['error'], void>({
mutationFn: async () => {
const res = await client<DeletePet['data'], DeletePet['error'], void>({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...clientOptions.headers },
...clientOptions,
}).then(res => res as TData)
})
return res
},
...mutationOptions,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type FindPetsByStatus = {
queryParams: FindPetsByStatusQueryParams
headerParams: never
response: Awaited<ReturnType<FindPetsByStatusClient>>
unionResponse: Awaited<ReturnType<FindPetsByStatusClient>> | FindPetsByStatusQueryResponse
client: {
paramaters: Partial<Parameters<FindPetsByStatusClient>[0]>
return: Awaited<ReturnType<FindPetsByStatusClient>>
Expand All @@ -28,17 +27,18 @@ export function findPetsByStatusQueryOptions<
>(
params?: FindPetsByStatus['queryParams'],
options: FindPetsByStatus['client']['paramaters'] = {},
): WithRequired<UseBaseQueryOptions<FindPetsByStatus['unionResponse'], TError, TData, TQueryData>, 'queryKey'> {
): WithRequired<UseBaseQueryOptions<FindPetsByStatus['response'], TError, TData, TQueryData>, 'queryKey'> {
const queryKey = findPetsByStatusQueryKey(params)
return {
queryKey,
queryFn: () => {
return client<TQueryFnData, TError>({
queryFn: async () => {
const res = await client<TQueryFnData, TError>({
method: 'get',
url: `/pet/findByStatus`,
params,
...options,
}).then(res => res?.data || res)
})
return res
},
}
}
Expand Down Expand Up @@ -81,12 +81,12 @@ export function findPetsByStatusInfiniteQueryOptions<
>(
params?: FindPetsByStatus['queryParams'],
options: FindPetsByStatus['client']['paramaters'] = {},
): WithRequired<UseInfiniteQueryOptions<FindPetsByStatus['unionResponse'], TError, TData, TQueryData>, 'queryKey'> {
): WithRequired<UseInfiniteQueryOptions<FindPetsByStatus['response'], TError, TData, TQueryData>, 'queryKey'> {
const queryKey = findPetsByStatusInfiniteQueryKey(params)
return {
queryKey,
queryFn: ({ pageParam }) => {
return client<TQueryFnData, TError>({
queryFn: async ({ pageParam }) => {
const res = await client<TQueryFnData, TError>({
method: 'get',
url: `/pet/findByStatus`,
...options,
Expand All @@ -95,7 +95,8 @@ export function findPetsByStatusInfiniteQueryOptions<
['test']: pageParam,
...(options.params || {}),
},
}).then(res => res?.data || res)
})
return res
},
}
}
Expand Down
Loading

1 comment on commit 787365b

@vercel
Copy link

@vercel vercel bot commented on 787365b Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kubb – ./

kubb-kubb.vercel.app
www.kubb.dev
kubb.dev
kubb-git-main-kubb.vercel.app

Please sign in to comment.