Skip to content

Commit

Permalink
feat: mapper and schemaTransformer (#676)
Browse files Browse the repository at this point in the history
* feat: mapper and schemaTransformer

* feat: use of Query and Mutation omponent for swagger-faker

* feat: add 'root' to KubbFile.Import

* chore: update ts and zod package with React components

* chore: update examples

* chore: camelcase/pascalcase transformers

* chore: fixes

* chore: pack updates

* feat: transformers subpackage

* chore: cleanup

* chore: jsdoc with tsFactory

* chore: fix snap

* chore(zod): example for mapper
  • Loading branch information
stijnvanhulle authored Nov 24, 2023
1 parent e127632 commit d729470
Show file tree
Hide file tree
Showing 794 changed files with 3,689 additions and 4,684 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-needles-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/swagger-faker": patch
---

feat: use of Query and Mutation omponent for swagger-faker
5 changes: 5 additions & 0 deletions .changeset/khaki-crews-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/swagger-faker": patch
---

mapper and transformers.schema to override default fakerParser
5 changes: 5 additions & 0 deletions .changeset/large-melons-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/core": major
---

transformers subpackage
5 changes: 5 additions & 0 deletions .changeset/lucky-moles-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/core": patch
---

add 'root' to KubbFile.Import
2 changes: 1 addition & 1 deletion .changeset/old-pandas-teach.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@kubb/core": major
"@kubb/core": patch
---

pluginSorter to sort based on pre and post
6 changes: 6 additions & 0 deletions .changeset/swift-eagles-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kubb/react": major
"@kubb/parser": major
---

jsdoc with tsFactory
1 change: 1 addition & 0 deletions configs/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
'@kubb/eslint-config': 'packages/config/eslint/src/index.ts',
'@kubb/tsup-config': 'packages/config/tsup/src/index.ts',
'@kubb/core/utils': 'packages/core/src/utils/index.ts',
'@kubb/core/transformers': 'packages/core/src/transformers/index.ts',
'@kubb/core': 'packages/core/src/index.ts',
'@kubb/swagger/utils': 'packages/swagger/src/utils/index.ts',
'@kubb/swagger/hooks': 'packages/swagger/src/hooks/index.ts',
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Kubb is trying to resolve that with a plugin system where we already provide you

Kubb has the following features:

- **Easy to Configure**: One of the goals of Kubb is to provide out-of-the-box plugins and utils for converting your Swagger/OpenAPI file to generated code.<br/><br/>You want to use a Swagger/OpenAPI file or URL, you want to split up the generated code based on a tag in the file, you want to use multiple Swagger/OpenApi files, we have you covered!
- **Easy to Configure**: One of the goals of Kubb is to provide out-of-the-box plugins and utils for converting your Swagger/OpenAPI file to generated code.<br/><br/>You want to use a Swagger/OpenAPI file or URL, you want to split up the generated code based on a tag in the file, you want to use multiple Swagger/OpenAPI files, we have you covered!
- **Generate SDK's**: Convert your Swagger/OpenAPI file to TypeScript, React-Query, Zod, Zodios, Faker.js, MSW and Axios.
- **Templates**: Override/change the generated output of a plugin with the help of [JSX templates(React)](/reference/templates).
- **Plugin Ecosystem**: Kubb has a [plugin system](/plugins/introdution) that makes it possible to change or add functionalities based on your needs.
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"dependencies": {
"@vercel/analytics": "^1.1.1",
"sitemap": "^7.1.1",
"vitepress": "^1.0.0-rc.29",
"vitepress": "^1.0.0-rc.30",
"vue": "^3.3.8"
},
"devDependencies": {
"@types/node": "^20.9.4"
"@types/node": "^20.10.0"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default [
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'unused-imports/no-unused-vars': 'off',
},
},
Expand Down
3 changes: 1 addition & 2 deletions examples/advanced/src/gen/clients/axios/petService/addPet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { AddPetMutationRequest, AddPetMutationResponse } from '../../../mod
/**
* @description Add a new pet to the store
* @summary Add a new pet to the store
* @link /pet
*/
* @link /pet */
export async function addPet(
data: AddPetMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderPar
/**
* @description delete a pet
* @summary Deletes a pet
* @link /pet/:petId
*/
* @link /pet/:petId */
export async function deletePet(
{ petId }: DeletePetPathParams,
headers?: DeletePetHeaderParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams } from
/**
* @description Multiple status values can be provided with comma separated strings
* @summary Finds Pets by status
* @link /pet/findByStatus
*/
* @link /pet/findByStatus */
export async function findPetsByStatus(
params?: FindPetsByStatusQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { FindPetsByTagsQueryResponse, FindPetsByTagsQueryParams, FindPetsBy
/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
* @link /pet/findByTags
*/
* @link /pet/findByTags */
export async function findPetsByTags(
headers: FindPetsByTagsHeaderParams,
params?: FindPetsByTagsQueryParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { GetPetByIdQueryResponse, GetPetByIdPathParams } from '../../../mod
/**
* @description Returns a single pet
* @summary Find pet by ID
* @link /pet/:petId
*/
* @link /pet/:petId */
export async function getPetById(
{ petId }: GetPetByIdPathParams,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { UpdatePetMutationRequest, UpdatePetMutationResponse } from '../../
/**
* @description Update an existing pet by Id
* @summary Update an existing pet
* @link /pet
*/
* @link /pet */
export async function updatePet(
data: UpdatePetMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import type {

/**
* @summary Updates a pet in the store with form data
* @link /pet/:petId
*/
* @link /pet/:petId */
export async function updatePetWithForm(
{ petId }: UpdatePetWithFormPathParams,
params?: UpdatePetWithFormQueryParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import type {

/**
* @summary uploads an image
* @link /pet/:petId/uploadImage
*/
* @link /pet/:petId/uploadImage */
export async function uploadFile(
{ petId }: UploadFilePathParams,
data?: UploadFileMutationRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import type {

/**
* @summary Create a pet
* @link /pets/:uuid
*/
* @link /pets/:uuid */
export async function createPets(
{ uuid }: CreatePetsPathParams,
data: CreatePetsMutationRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../.
/**
* @description This can only be done by the logged in user.
* @summary Create user
* @link /user
*/
* @link /user */
export async function createUser(
data?: CreateUserMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import type {
/**
* @description Creates list of users with given input array
* @summary Creates list of users with given input array
* @link /user/createWithList
*/
* @link /user/createWithList */
export async function createUsersWithListInput(
data?: CreateUsersWithListInputMutationRequest,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { DeleteUserMutationResponse, DeleteUserPathParams } from '../../../
/**
* @description This can only be done by the logged in user.
* @summary Delete user
* @link /user/:username
*/
* @link /user/:username */
export async function deleteUser(
{ username }: DeleteUserPathParams,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type { GetUserByNameQueryResponse, GetUserByNamePathParams } from '../../

/**
* @summary Get user by user name
* @link /user/:username
*/
* @link /user/:username */
export async function getUserByName(
{ username }: GetUserByNamePathParams,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type { LoginUserQueryResponse, LoginUserQueryParams } from '../../../mode

/**
* @summary Logs user into the system
* @link /user/login
*/
* @link /user/login */
export async function loginUser(
params?: LoginUserQueryParams,
options: Partial<Parameters<typeof client>[0]> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type { LogoutUserQueryResponse } from '../../../models/ts/userController/

/**
* @summary Logs out current logged in user session
* @link /user/logout
*/
* @link /user/logout */
export async function logoutUser(options: Partial<Parameters<typeof client>[0]> = {}): Promise<ResponseConfig<LogoutUserQueryResponse>> {
return client<LogoutUserQueryResponse>({
method: 'get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserP
/**
* @description This can only be done by the logged in user.
* @summary Update user
* @link /user/:username
*/
* @link /user/:username */
export async function updateUser(
{ username }: UpdateUserPathParams,
data?: UpdateUserMutationRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ type AddPet = {
/**
* @description Add a new pet to the store
* @summary Add a new pet to the store
* @link /pet
*/
* @link /pet */
export function useAddPet<TData = AddPet['response'], TError = AddPet['error']>(options: {
mutation?: UseMutationOptions<TData, TError, AddPet['request']>
client?: AddPet['client']['paramaters']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ type DeletePet = {
/**
* @description delete a pet
* @summary Deletes a pet
* @link /pet/:petId
*/
* @link /pet/:petId */
export function useDeletePet<TData = DeletePet['response'], TError = DeletePet['error']>(
petId: DeletePetPathParams['petId'],
headers?: DeletePet['headerParams'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ export function findPetsByStatusQueryOptions<
}).then(res => res?.data || res)
},
}
} /**
}
/**
* @description Multiple status values can be provided with comma separated strings
* @summary Finds Pets by status
* @link /pet/findByStatus
*/

* @link /pet/findByStatus */
export function useFindPetsByStatus<
TQueryFnData extends FindPetsByStatus['data'] = FindPetsByStatus['data'],
TError = FindPetsByStatus['error'],
Expand All @@ -71,7 +70,6 @@ export function useFindPetsByStatus<
query.queryKey = queryKey as TQueryKey
return query
}

export const findPetsByStatusInfiniteQueryKey = (params?: FindPetsByStatus['queryParams']) =>
[{ url: '/pet/findByStatus' }, ...(params ? [params] : [])] as const
export type FindPetsByStatusInfiniteQueryKey = ReturnType<typeof findPetsByStatusInfiniteQueryKey>
Expand Down Expand Up @@ -100,12 +98,11 @@ export function findPetsByStatusInfiniteQueryOptions<
}).then(res => res?.data || res)
},
}
} /**
}
/**
* @description Multiple status values can be provided with comma separated strings
* @summary Finds Pets by status
* @link /pet/findByStatus
*/

* @link /pet/findByStatus */
export function useFindPetsByStatusInfinite<
TQueryFnData extends FindPetsByStatus['data'] = FindPetsByStatus['data'],
TError = FindPetsByStatus['error'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ export function findPetsByTagsQueryOptions<
}).then(res => res?.data || res)
},
}
} /**
}
/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
* @link /pet/findByTags
*/

* @link /pet/findByTags */
export function useFindPetsByTags<
TQueryFnData extends FindPetsByTags['data'] = FindPetsByTags['data'],
TError = FindPetsByTags['error'],
Expand All @@ -78,7 +77,6 @@ export function useFindPetsByTags<
query.queryKey = queryKey as TQueryKey
return query
}

export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTags['queryParams']) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
export type FindPetsByTagsInfiniteQueryKey = ReturnType<typeof findPetsByTagsInfiniteQueryKey>
export function findPetsByTagsInfiniteQueryOptions<
Expand Down Expand Up @@ -108,12 +106,11 @@ export function findPetsByTagsInfiniteQueryOptions<
}).then(res => res?.data || res)
},
}
} /**
}
/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
* @link /pet/findByTags
*/

* @link /pet/findByTags */
export function useFindPetsByTagsInfinite<
TQueryFnData extends FindPetsByTags['data'] = FindPetsByTags['data'],
TError = FindPetsByTags['error'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ export function getPetByIdQueryOptions<
}).then(res => res?.data || res)
},
}
} /**
}
/**
* @description Returns a single pet
* @summary Find pet by ID
* @link /pet/:petId
*/

* @link /pet/:petId */
export function useGetPetById<
TQueryFnData extends GetPetById['data'] = GetPetById['data'],
TError = GetPetById['error'],
Expand All @@ -70,7 +69,6 @@ export function useGetPetById<
query.queryKey = queryKey as TQueryKey
return query
}

export const getPetByIdInfiniteQueryKey = (petId: GetPetByIdPathParams['petId']) => [{ url: '/pet/:petId', params: { petId: petId } }] as const
export type GetPetByIdInfiniteQueryKey = ReturnType<typeof getPetByIdInfiniteQueryKey>
export function getPetByIdInfiniteQueryOptions<
Expand All @@ -93,12 +91,11 @@ export function getPetByIdInfiniteQueryOptions<
}).then(res => res?.data || res)
},
}
} /**
}
/**
* @description Returns a single pet
* @summary Find pet by ID
* @link /pet/:petId
*/

* @link /pet/:petId */
export function useGetPetByIdInfinite<
TQueryFnData extends GetPetById['data'] = GetPetById['data'],
TError = GetPetById['error'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ type UpdatePet = {
/**
* @description Update an existing pet by Id
* @summary Update an existing pet
* @link /pet
*/
* @link /pet */
export function useUpdatePet<TData = UpdatePet['response'], TError = UpdatePet['error']>(options: {
mutation?: UseMutationOptions<TData, TError, UpdatePet['request']>
client?: UpdatePet['client']['paramaters']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ type UpdatePetWithForm = {
}
/**
* @summary Updates a pet in the store with form data
* @link /pet/:petId
*/
* @link /pet/:petId */
export function useUpdatePetWithForm<TData = UpdatePetWithForm['response'], TError = UpdatePetWithForm['error']>(
petId: UpdatePetWithFormPathParams['petId'],
params?: UpdatePetWithForm['queryParams'],
Expand Down
Loading

0 comments on commit d729470

Please sign in to comment.