Skip to content

Commit c6888de

Browse files
committed
chore: humanize swr output
1 parent ad15f45 commit c6888de

File tree

103 files changed

+873
-879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+873
-879
lines changed

docs/knowledge-base/how-tos/fetch.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export type RequestConfig<TData = unknown> = {
5858
url?: string
5959
method: 'get' | 'put' | 'patch' | 'post' | 'delete'
6060
params?: object
61-
data?: TData
61+
data?: TData | FormData
6262
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
6363
signal?: AbortSignal
6464
headers?: HeadersInit

e2e/src/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type RequestConfig<TData = unknown> = {
1212
url?: string
1313
method: 'get' | 'put' | 'patch' | 'post' | 'delete'
1414
params?: unknown
15-
data?: TData
15+
data?: TData | FormData
1616
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
1717
signal?: AbortSignal
1818
headers?: AxiosRequestConfig['headers']

examples/advanced/configs/kubb.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default defineConfig(() => {
105105
group: { type: 'tag' },
106106
client: {
107107
importPath: '../../../../swr-client.ts',
108-
dataReturnType: 'full',
108+
dataReturnType: 'data',
109109
},
110110
parser: 'zod',
111111
}),

examples/advanced/src/axios-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type RequestConfig<TData = unknown> = {
1313
url?: string
1414
method: 'get' | 'put' | 'patch' | 'post' | 'delete'
1515
params?: unknown
16-
data?: TData
16+
data?: TData | FormData
1717
responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
1818
signal?: AbortSignal
1919
headers?: AxiosRequestConfig['headers']

examples/advanced/src/gen/clients/axios/petService/addPet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { AddPetMutationRequest, AddPetMutationResponse } from '../../../models/ts/petController/AddPet.ts'
3+
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../../../models/ts/petController/AddPet.ts'
44

55
/**
66
* @description Add a new pet to the store
77
* @summary Add a new pet to the store
88
* @link /pet
99
*/
10-
export async function addPet(data: AddPetMutationRequest, config: Partial<RequestConfig> = {}) {
11-
const res = await client<AddPetMutationResponse, AddPetMutationRequest>({
10+
export async function addPet(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> = {}) {
11+
const res = await client<AddPetMutationResponse, AddPet405, AddPetMutationRequest>({
1212
method: 'post',
1313
url: '/pet',
1414
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/petService/deletePet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams } from '../../../models/ts/petController/DeletePet.ts'
3+
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../../../models/ts/petController/DeletePet.ts'
44

55
/**
66
* @description delete a pet
@@ -16,7 +16,7 @@ export async function deletePet(
1616
headers?: DeletePetHeaderParams,
1717
config: Partial<RequestConfig> = {},
1818
) {
19-
const res = await client<DeletePetMutationResponse>({
19+
const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({
2020
method: 'delete',
2121
url: `/pet/${petId}`,
2222
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/petService/findPetsByStatus.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams } from '../../../models/ts/petController/FindPetsByStatus.ts'
3+
import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from '../../../models/ts/petController/FindPetsByStatus.ts'
44

55
/**
66
* @description Multiple status values can be provided with comma separated strings
77
* @summary Finds Pets by status
88
* @link /pet/findByStatus
99
*/
1010
export async function findPetsByStatus(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> = {}) {
11-
const res = await client<FindPetsByStatusQueryResponse>({
11+
const res = await client<FindPetsByStatusQueryResponse, FindPetsByStatus400, unknown>({
1212
method: 'get',
1313
url: '/pet/findByStatus',
1414
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/petService/findPetsByTags.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsByTagsHeaderParams } from '../../../models/ts/petController/FindPetsByTags.ts'
3+
import type {
4+
FindPetsByTagsQueryResponse,
5+
FindPetsByTagsQueryParams,
6+
FindPetsByTagsHeaderParams,
7+
FindPetsByTags400,
8+
} from '../../../models/ts/petController/FindPetsByTags.ts'
49

510
/**
611
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
712
* @summary Finds Pets by tags
813
* @link /pet/findByTags
914
*/
1015
export async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
11-
const res = await client<FindPetsByTagsQueryResponse>({
16+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({
1217
method: 'get',
1318
url: '/pet/findByTags',
1419
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/petService/getPetById.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { GetPetByIdQueryResponse, GetPetByIdPathParams } from '../../../models/ts/petController/GetPetById.ts'
3+
import type { GetPetByIdQueryResponse, GetPetByIdPathParams, GetPetById400, GetPetById404 } from '../../../models/ts/petController/GetPetById.ts'
44

55
/**
66
* @description Returns a single pet
@@ -15,6 +15,11 @@ export async function getPetById(
1515
},
1616
config: Partial<RequestConfig> = {},
1717
) {
18-
const res = await client<GetPetByIdQueryResponse>({ method: 'get', url: `/pet/${petId}`, baseURL: 'https://petstore3.swagger.io/api/v3', ...config })
18+
const res = await client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, unknown>({
19+
method: 'get',
20+
url: `/pet/${petId}`,
21+
baseURL: 'https://petstore3.swagger.io/api/v3',
22+
...config,
23+
})
1924
return res
2025
}

examples/advanced/src/gen/clients/axios/petService/updatePet.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { UpdatePetMutationRequest, UpdatePetMutationResponse } from '../../../models/ts/petController/UpdatePet.ts'
3+
import type {
4+
UpdatePetMutationRequest,
5+
UpdatePetMutationResponse,
6+
UpdatePet400,
7+
UpdatePet404,
8+
UpdatePet405,
9+
} from '../../../models/ts/petController/UpdatePet.ts'
410

511
/**
612
* @description Update an existing pet by Id
713
* @summary Update an existing pet
814
* @link /pet
915
*/
10-
export async function updatePet(data: UpdatePetMutationRequest, config: Partial<RequestConfig> = {}) {
11-
const res = await client<UpdatePetMutationResponse, UpdatePetMutationRequest>({
16+
export async function updatePet(data: UpdatePetMutationRequest, config: Partial<RequestConfig<UpdatePetMutationRequest>> = {}) {
17+
const res = await client<UpdatePetMutationResponse, UpdatePet400 | UpdatePet404 | UpdatePet405, UpdatePetMutationRequest>({
1218
method: 'put',
1319
url: '/pet',
1420
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/petService/updatePetWithForm.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
UpdatePetWithFormMutationResponse,
55
UpdatePetWithFormPathParams,
66
UpdatePetWithFormQueryParams,
7+
UpdatePetWithForm405,
78
} from '../../../models/ts/petController/UpdatePetWithForm.ts'
89

910
/**
@@ -19,7 +20,7 @@ export async function updatePetWithForm(
1920
params?: UpdatePetWithFormQueryParams,
2021
config: Partial<RequestConfig> = {},
2122
) {
22-
const res = await client<UpdatePetWithFormMutationResponse>({
23+
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({
2324
method: 'post',
2425
url: `/pet/${petId}`,
2526
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/petService/uploadFile.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export async function uploadFile(
1919
},
2020
data?: UploadFileMutationRequest,
2121
params?: UploadFileQueryParams,
22-
config: Partial<RequestConfig> = {},
22+
config: Partial<RequestConfig<UploadFileMutationRequest>> = {},
2323
) {
24-
const res = await client<UploadFileMutationResponse, UploadFileMutationRequest>({
24+
const res = await client<UploadFileMutationResponse, unknown, UploadFileMutationRequest>({
2525
method: 'post',
2626
url: `/pet/${petId}/uploadImage`,
2727
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/petsService/createPets.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export async function createPets(
2121
data: CreatePetsMutationRequest,
2222
headers: CreatePetsHeaderParams,
2323
params?: CreatePetsQueryParams,
24-
config: Partial<RequestConfig> = {},
24+
config: Partial<RequestConfig<CreatePetsMutationRequest>> = {},
2525
) {
26-
const res = await client<CreatePetsMutationResponse, CreatePetsMutationRequest>({
26+
const res = await client<CreatePetsMutationResponse, unknown, CreatePetsMutationRequest>({
2727
method: 'post',
2828
url: `/pets/${uuid}`,
2929
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/userService/createUser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../.
77
* @summary Create user
88
* @link /user
99
*/
10-
export async function createUser(data?: CreateUserMutationRequest, config: Partial<RequestConfig> = {}) {
11-
const res = await client<CreateUserMutationResponse, CreateUserMutationRequest>({
10+
export async function createUser(data?: CreateUserMutationRequest, config: Partial<RequestConfig<CreateUserMutationRequest>> = {}) {
11+
const res = await client<CreateUserMutationResponse, unknown, CreateUserMutationRequest>({
1212
method: 'post',
1313
url: '/user',
1414
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/userService/createUsersWithListInput.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import type {
1010
* @summary Creates list of users with given input array
1111
* @link /user/createWithList
1212
*/
13-
export async function createUsersWithListInput(data?: CreateUsersWithListInputMutationRequest, config: Partial<RequestConfig> = {}) {
14-
const res = await client<CreateUsersWithListInputMutationResponse, CreateUsersWithListInputMutationRequest>({
13+
export async function createUsersWithListInput(
14+
data?: CreateUsersWithListInputMutationRequest,
15+
config: Partial<RequestConfig<CreateUsersWithListInputMutationRequest>> = {},
16+
) {
17+
const res = await client<CreateUsersWithListInputMutationResponse, unknown, CreateUsersWithListInputMutationRequest>({
1518
method: 'post',
1619
url: '/user/createWithList',
1720
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/userService/deleteUser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { DeleteUserMutationResponse, DeleteUserPathParams } from '../../../models/ts/userController/DeleteUser.ts'
3+
import type { DeleteUserMutationResponse, DeleteUserPathParams, DeleteUser400, DeleteUser404 } from '../../../models/ts/userController/DeleteUser.ts'
44

55
/**
66
* @description This can only be done by the logged in user.
@@ -15,7 +15,7 @@ export async function deleteUser(
1515
},
1616
config: Partial<RequestConfig> = {},
1717
) {
18-
const res = await client<DeleteUserMutationResponse>({
18+
const res = await client<DeleteUserMutationResponse, DeleteUser400 | DeleteUser404, unknown>({
1919
method: 'delete',
2020
url: `/user/${username}`,
2121
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/axios/userService/getUserByName.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { GetUserByNameQueryResponse, GetUserByNamePathParams } from '../../../models/ts/userController/GetUserByName.ts'
3+
import type {
4+
GetUserByNameQueryResponse,
5+
GetUserByNamePathParams,
6+
GetUserByName400,
7+
GetUserByName404,
8+
} from '../../../models/ts/userController/GetUserByName.ts'
49

510
/**
611
* @summary Get user by user name
@@ -14,6 +19,11 @@ export async function getUserByName(
1419
},
1520
config: Partial<RequestConfig> = {},
1621
) {
17-
const res = await client<GetUserByNameQueryResponse>({ method: 'get', url: `/user/${username}`, baseURL: 'https://petstore3.swagger.io/api/v3', ...config })
22+
const res = await client<GetUserByNameQueryResponse, GetUserByName400 | GetUserByName404, unknown>({
23+
method: 'get',
24+
url: `/user/${username}`,
25+
baseURL: 'https://petstore3.swagger.io/api/v3',
26+
...config,
27+
})
1828
return res
1929
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import client from '../../../../axios-client.ts'
22
import type { RequestConfig } from '../../../../axios-client.ts'
3-
import type { LoginUserQueryResponse, LoginUserQueryParams } from '../../../models/ts/userController/LoginUser.ts'
3+
import type { LoginUserQueryResponse, LoginUserQueryParams, LoginUser400 } from '../../../models/ts/userController/LoginUser.ts'
44

55
/**
66
* @summary Logs user into the system
77
* @link /user/login
88
*/
99
export async function loginUser(params?: LoginUserQueryParams, config: Partial<RequestConfig> = {}) {
10-
const res = await client<LoginUserQueryResponse>({ method: 'get', url: '/user/login', baseURL: 'https://petstore3.swagger.io/api/v3', params, ...config })
10+
const res = await client<LoginUserQueryResponse, LoginUser400, unknown>({
11+
method: 'get',
12+
url: '/user/login',
13+
baseURL: 'https://petstore3.swagger.io/api/v3',
14+
params,
15+
...config,
16+
})
1117
return res
1218
}

examples/advanced/src/gen/clients/axios/userService/logoutUser.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import type { LogoutUserQueryResponse } from '../../../models/ts/userController/
77
* @link /user/logout
88
*/
99
export async function logoutUser(config: Partial<RequestConfig> = {}) {
10-
const res = await client<LogoutUserQueryResponse>({ method: 'get', url: '/user/logout', baseURL: 'https://petstore3.swagger.io/api/v3', ...config })
10+
const res = await client<LogoutUserQueryResponse, unknown, unknown>({
11+
method: 'get',
12+
url: '/user/logout',
13+
baseURL: 'https://petstore3.swagger.io/api/v3',
14+
...config,
15+
})
1116
return res
1217
}

examples/advanced/src/gen/clients/axios/userService/updateUser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export async function updateUser(
1414
username: UpdateUserPathParams['username']
1515
},
1616
data?: UpdateUserMutationRequest,
17-
config: Partial<RequestConfig> = {},
17+
config: Partial<RequestConfig<UpdateUserMutationRequest>> = {},
1818
) {
19-
const res = await client<UpdateUserMutationResponse, UpdateUserMutationRequest>({
19+
const res = await client<UpdateUserMutationResponse, unknown, UpdateUserMutationRequest>({
2020
method: 'put',
2121
url: `/user/${username}`,
2222
baseURL: 'https://petstore3.swagger.io/api/v3',

examples/advanced/src/gen/clients/swr/petSWRController/useAddPet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type AddPet = {
1313
pathParams: never
1414
queryParams: never
1515
headerParams: never
16-
response: Awaited<ReturnType<AddPetClient>>
16+
response: AddPetMutationResponse
1717
client: {
1818
parameters: Partial<Parameters<AddPetClient>[0]>
1919
return: Awaited<ReturnType<AddPetClient>>
@@ -41,7 +41,7 @@ export function useAddPet(options?: {
4141
data,
4242
...clientOptions,
4343
})
44-
return res
44+
return res.data
4545
},
4646
mutationOptions,
4747
)

examples/advanced/src/gen/clients/swr/petSWRController/useDeletePet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type DeletePet = {
1313
pathParams: DeletePetPathParams
1414
queryParams: never
1515
headerParams: DeletePetHeaderParams
16-
response: Awaited<ReturnType<DeletePetClient>>
16+
response: DeletePetMutationResponse
1717
client: {
1818
parameters: Partial<Parameters<DeletePetClient>[0]>
1919
return: Awaited<ReturnType<DeletePetClient>>
@@ -45,7 +45,7 @@ export function useDeletePet(
4545
headers: { ...headers, ...clientOptions.headers },
4646
...clientOptions,
4747
})
48-
return res
48+
return res.data
4949
},
5050
mutationOptions,
5151
)

0 commit comments

Comments
 (0)