Skip to content

Commit

Permalink
Merge pull request #457 from kubb-project/feat/dataReturnType
Browse files Browse the repository at this point in the history
feat: `dataReturnType` for @kubb/swagger-tanstack-query, @kubb/swagger-client and @kubb/swagger-swr
  • Loading branch information
stijnvanhulle authored Oct 8, 2023
2 parents d628687 + 9e5b124 commit 151ea18
Show file tree
Hide file tree
Showing 48 changed files with 280 additions and 207 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default defineConfig({
},
{
text: '@kubb/react-templates <span class="beta">under construction</span>',
link: '/plugins/react-templates',
link: '/plugins/react-template',
},
{
text: 'Swagger plugins',
Expand Down
3 changes: 3 additions & 0 deletions docs/plugins/react-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ outline: deep
---
# @kubb/react-template <Badge type="warning" text="under construction" />

Use React to create templates/variants for any plugin.

<hr/>


## Installation

::: code-group
Expand Down
10 changes: 10 additions & 0 deletions docs/plugins/swagger-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ Relative to the root
Type: `string` <br/>
Default: `"@kubb/swagger-client/ts-client"`

### dataReturnType <Badge type="warning" text="experimental" />
ReturnType that needs to be used when calling client().

`Data` will return ResponseConfig[data]. <br/>
`Full` will return ResponseConfig.

Type: `string` <br/>
Default: `"data"`

### skipBy
Array containing skipBy paramaters to exclude/skip tags/operations/methods/paths.

Expand All @@ -86,6 +95,7 @@ Override the name of the client that is getting generated, this will also overri
Type: `(name: string) => string` <br/>



## Depended

- [`@kubb/swagger`](/plugins/swagger)
Expand Down
10 changes: 9 additions & 1 deletion docs/plugins/swagger-swr.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ yarn add @kubb/swagger-swr

:::


## Options


Expand Down Expand Up @@ -70,6 +69,15 @@ Relative to the root
Type: `string` <br/>
Default: `"@kubb/swagger-client/ts-client"`

### dataReturnType <Badge type="warning" text="experimental" />
ReturnType that needs to be used when calling client().

`Data` will return ResponseConfig[data]. <br/>
`Full` will return ResponseConfig.

Type: `string` <br/>
Default: `"data"`

### skipBy
Array containing skipBy paramaters to exclude/skip tags/operations/methods/paths.

Expand Down
9 changes: 9 additions & 0 deletions docs/plugins/swagger-tanstack-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ Relative to the root
Type: `string` <br/>
Default: `"@kubb/swagger-client/ts-client"`

### dataReturnType <Badge type="warning" text="experimental" />
ReturnType that needs to be used when calling client().

`Data` will return ResponseConfig[data]. <br/>
`Full` will return ResponseConfig.

Type: `string` <br/>
Default: `"data"`

### framework
Framework to be generated for.

Expand Down
1 change: 0 additions & 1 deletion docs/plugins/swagger-ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ date: Date
Type: `'string' | 'date'` <br/>
Default: `'string'`


### optionalType
Choose what to use as mode for an optional value.<br/>

Expand Down
3 changes: 3 additions & 0 deletions examples/advanced/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default defineConfig(async () => {
groupBy: { type: 'tag' },
client: './src/client.ts',
infinite: {},
dataReturnType: 'full',
},
],
[
Expand All @@ -60,6 +61,7 @@ export default defineConfig(async () => {
],
groupBy: { type: 'tag' },
client: './src/client.ts',
dataReturnType: 'full',
},
],
[
Expand All @@ -74,6 +76,7 @@ export default defineConfig(async () => {
],
groupBy: { type: 'tag', output: './clients/axios/{{tag}}Service' },
client: './src/client.ts',
dataReturnType: 'full',
},
],
[
Expand Down
6 changes: 2 additions & 4 deletions examples/advanced/src/gen/clients/axios/petService/addPet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import type { AddPetMutationRequest, AddPetMutationResponse } from '../../../mod
export async function addPet<TData = AddPetMutationResponse, TVariables = AddPetMutationRequest>(
data: TVariables,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData, TVariables>({
): Promise<ResponseConfig<TData>> {
return client<TData, TVariables>({
method: 'post',
url: `/pet`,
data,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ export async function deletePet<TData = DeletePetMutationResponse>(
petId: DeletePetPathParams['petId'],
headers?: DeletePetHeaderParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'delete',
url: `/pet/${petId}`,
headers: { ...headers, ...options.headers },
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams } from
export async function findPetsByStatus<TData = FindPetsByStatusQueryResponse>(
params?: FindPetsByStatusQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'get',
url: `/pet/findByStatus`,
params,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ export async function findPetsByTags<TData = FindPetsByTagsQueryResponse>(
headers: FindPetsByTagsHeaderParams,
params?: FindPetsByTagsQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'get',
url: `/pet/findByTags`,
params,
headers: { ...headers, ...options.headers },
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import type { GetPetByIdQueryResponse, GetPetByIdPathParams } from '../../../mod
export async function getPetById<TData = GetPetByIdQueryResponse>(
petId: GetPetByIdPathParams['petId'],
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'get',
url: `/pet/${petId}`,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import type { UpdatePetMutationRequest, UpdatePetMutationResponse } from '../../
export async function updatePet<TData = UpdatePetMutationResponse, TVariables = UpdatePetMutationRequest>(
data: TVariables,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData, TVariables>({
): Promise<ResponseConfig<TData>> {
return client<TData, TVariables>({
method: 'put',
url: `/pet`,
data,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ export async function updatePetWithForm<TData = UpdatePetWithFormMutationRespons
petId: UpdatePetWithFormPathParams['petId'],
params?: UpdatePetWithFormQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'post',
url: `/pet/${petId}`,
params,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ export async function uploadFile<TData = UploadFileMutationResponse, TVariables
data?: TVariables,
params?: UploadFileQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData, TVariables>({
): Promise<ResponseConfig<TData>> {
return client<TData, TVariables>({
method: 'post',
url: `/pet/${petId}/uploadImage`,
params,
data,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ export async function createPets<TData = CreatePetsMutationResponse, TVariables
headers: CreatePetsHeaderParams,
params?: CreatePetsQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData, TVariables>({
): Promise<ResponseConfig<TData>> {
return client<TData, TVariables>({
method: 'post',
url: `/pets/${uuid}`,
params,
data,
headers: { ...headers, ...options.headers },
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../.
export async function createUser<TData = CreateUserMutationResponse, TVariables = CreateUserMutationRequest>(
data?: TVariables,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData, TVariables>({
): Promise<ResponseConfig<TData>> {
return client<TData, TVariables>({
method: 'post',
url: `/user`,
data,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import type {
export async function createUsersWithListInput<TData = CreateUsersWithListInputMutationResponse, TVariables = CreateUsersWithListInputMutationRequest>(
data?: TVariables,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData, TVariables>({
): Promise<ResponseConfig<TData>> {
return client<TData, TVariables>({
method: 'post',
url: `/user/createWithList`,
data,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import type { DeleteUserMutationResponse, DeleteUserPathParams } from '../../../
export async function deleteUser<TData = DeleteUserMutationResponse>(
username: DeleteUserPathParams['username'],
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'delete',
url: `/user/${username}`,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import type { GetUserByNameQueryResponse, GetUserByNamePathParams } from '../../
export async function getUserByName<TData = GetUserByNameQueryResponse>(
username: GetUserByNamePathParams['username'],
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'get',
url: `/user/${username}`,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import type { LoginUserQueryResponse, LoginUserQueryParams } from '../../../mode
export async function loginUser<TData = LoginUserQueryResponse>(
params?: LoginUserQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'get',
url: `/user/login`,
params,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import type { LogoutUserQueryResponse } from '../../../models/ts/userController/
* @summary Logs out current logged in user session
* @link /user/logout
*/
export async function logoutUser<TData = LogoutUserQueryResponse>(options: Partial<Parameters<typeof client>[0]> = {}): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData>({
export async function logoutUser<TData = LogoutUserQueryResponse>(options: Partial<Parameters<typeof client>[0]> = {}): Promise<ResponseConfig<TData>> {
return client<TData>({
method: 'get',
url: `/user/logout`,
...options,
})

return resData
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ export async function updateUser<TData = UpdateUserMutationResponse, TVariables
username: UpdateUserPathParams['username'],
data?: TVariables,
options: Partial<Parameters<typeof client>[0]> = {},
): Promise<ResponseConfig<TData>['data']> {
const { data: resData } = await client<TData, TVariables>({
): Promise<ResponseConfig<TData>> {
return client<TData, TVariables>({
method: 'put',
url: `/user/${username}`,
data,
...options,
})

return resData
}
Loading

1 comment on commit 151ea18

@vercel
Copy link

@vercel vercel bot commented on 151ea18 Oct 8, 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-git-main-kubb.vercel.app
kubb-kubb.vercel.app
www.kubb.dev
kubb.dev

Please sign in to comment.