Skip to content

Commit

Permalink
Chore/refactor barrel types (#1274)
Browse files Browse the repository at this point in the history
* feat: refactor barrelFiles export + `extension` to override import/export extname

* chore: cleanup
  • Loading branch information
stijnvanhulle authored Sep 29, 2024
1 parent e426320 commit 39072a9
Show file tree
Hide file tree
Showing 268 changed files with 3,525 additions and 3,621 deletions.
20 changes: 20 additions & 0 deletions .changeset/flat-scissors-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@kubb/plugin-svelte-query": major
"@kubb/plugin-react-query": major
"@kubb/plugin-solid-query": major
"@kubb/plugin-vue-query": major
"@kubb/plugin-client": major
"@kubb/plugin-faker": major
"@kubb/plugin-redoc": major
"@kubb/plugin-msw": major
"@kubb/plugin-oas": major
"@kubb/plugin-swr": major
"@kubb/plugin-zod": major
"@kubb/plugin-ts": major
"@kubb/react": major
"@kubb/core": major
"@kubb/cli": major
"@kubb/fs": major
---

Removal of `extName` in every plugin in favour of one `output.extension`
18 changes: 18 additions & 0 deletions docs/blog/v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ import { pluginTanstackQuery } from '@kubb/plugin-tanstack-query'
- Removal of support for Tanstack-Query v4
- Removal of support for Msw v1
- Minimal Node 20
- Removal of `output.exportType`
- Rename of `exportType` with `barrelType` for `output.barrelType` and every plugin
- Removal of `extName` in every plugin in favour of one `output.extension`
````
root: '.',
input: {
path: './petStore.yaml',
},
output: {
path: './src/gen',
clean: true,
extension() {
return {
'.ts': '.js',
}
},
},
````

## Thanks

Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ title: Changelog

# Changelog

## 3.0.0-alpha.30
- [`plugin-core`](/plugins/core/): Removal of `output.extName` in favour of `output.extension`
- [`plugin-core`](/plugins/core/): Removal of `exportType` in favour of `barrelType`


## 3.0.0-alpha.29
- [`plugin-react-query`](/plugins/plugin-react-query/): Support for cancellation of queries with the help of `signal`
- [`plugin-svelte-query`](/plugins/plugin-svelte-query/): Support for cancellation of queries with the help of `signal`
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"serve": "vitepress serve"
},
"dependencies": {
"@shikijs/vitepress-twoslash": "^1.20.0",
"@shikijs/vitepress-twoslash": "^1.21.0",
"sitemap": "^8.0.0",
"vitepress": "^1.3.4",
"vitepress-plugin-group-icons": "^1.2.4",
Expand Down
8 changes: 4 additions & 4 deletions e2e/kubb.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const baseConfig = {
pluginTs({
output: {
path: 'models/ts',
exportType: false,
barrelType: false,
},
group: {
type: 'tag',
Expand All @@ -77,7 +77,7 @@ const baseConfig = {
pluginSwr({
output: {
path: './clients/swr',
exportType: false,
barrelType: false,
},
group: { type: 'tag' },
}),
Expand All @@ -90,7 +90,7 @@ const baseConfig = {
pluginZod({
output: {
path: './zod',
exportType: false,
barrelType: false,
},
group: { type: 'tag' },
inferred: true,
Expand All @@ -100,7 +100,7 @@ const baseConfig = {
pluginFaker({
output: {
path: 'mocks',
exportType: false,
barrelType: false,
},
group: { type: 'tag' },
transformers: {
Expand Down
15 changes: 11 additions & 4 deletions examples/advanced/configs/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default defineConfig(() => {
output: {
path: './src/gen',
clean: true,
barrelType: 'named',
},
hooks: {
done: ['npm run typecheck', 'biome format --write ./', 'biome lint --apply-unsafe ./src'],
Expand All @@ -36,7 +37,6 @@ export default defineConfig(() => {
pluginTs({
output: {
path: 'models/ts',
extName: '.js',
},
group: {
type: 'tag',
Expand Down Expand Up @@ -99,7 +99,6 @@ export default defineConfig(() => {
pluginSwr({
output: {
path: './clients/swr',
exportType: false,
},
exclude: [
{
Expand All @@ -113,6 +112,11 @@ export default defineConfig(() => {
dataReturnType: 'data',
},
parser: 'zod',
transformers: {
name(name, type) {
return `${name}SWR`
},
},
}),
pluginClient({
output: {
Expand Down Expand Up @@ -148,7 +152,6 @@ export default defineConfig(() => {
pluginFaker({
output: {
path: 'mocks',
exportType: false,
},
exclude: [
{
Expand All @@ -161,11 +164,15 @@ export default defineConfig(() => {
mapper: {
status: `faker.helpers.arrayElement(['working', 'idle']) as any`,
},
transformers: {
name(name, type) {
return `${name}Faker`
},
},
}),
pluginMsw({
output: {
path: 'msw',
exportType: false,
},
handlers: true,
exclude: [
Expand Down
32 changes: 32 additions & 0 deletions examples/advanced/src/gen/clients/swr/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export type { CreatePetsMutationKeySWR } from './petsSWRController/useCreatePetsSWR.ts'
export type { AddPetMutationKeySWR } from './petSWRController/useAddPetSWR.ts'
export type { DeletePetMutationKeySWR } from './petSWRController/useDeletePetSWR.ts'
export type { FindPetsByStatusQueryKeySWR } from './petSWRController/useFindPetsByStatusSWR.ts'
export type { FindPetsByTagsQueryKeySWR } from './petSWRController/useFindPetsByTagsSWR.ts'
export type { GetPetByIdQueryKeySWR } from './petSWRController/useGetPetByIdSWR.ts'
export type { UpdatePetMutationKeySWR } from './petSWRController/useUpdatePetSWR.ts'
export type { UpdatePetWithFormMutationKeySWR } from './petSWRController/useUpdatePetWithFormSWR.ts'
export type { UploadFileMutationKeySWR } from './petSWRController/useUploadFileSWR.ts'
export type { CreateUsersWithListInputMutationKeySWR } from './userSWRController/useCreateUsersWithListInputSWR.ts'
export type { CreateUserMutationKeySWR } from './userSWRController/useCreateUserSWR.ts'
export type { DeleteUserMutationKeySWR } from './userSWRController/useDeleteUserSWR.ts'
export type { GetUserByNameQueryKeySWR } from './userSWRController/useGetUserByNameSWR.ts'
export type { LoginUserQueryKeySWR } from './userSWRController/useLoginUserSWR.ts'
export type { LogoutUserQueryKeySWR } from './userSWRController/useLogoutUserSWR.ts'
export type { UpdateUserMutationKeySWR } from './userSWRController/useUpdateUserSWR.ts'
export { createPetsMutationKeySWR, useCreatePetsSWR } from './petsSWRController/useCreatePetsSWR.ts'
export { addPetMutationKeySWR, useAddPetSWR } from './petSWRController/useAddPetSWR.ts'
export { deletePetMutationKeySWR, useDeletePetSWR } from './petSWRController/useDeletePetSWR.ts'
export { findPetsByStatusQueryKeySWR, findPetsByStatusQueryOptionsSWR, useFindPetsByStatusSWR } from './petSWRController/useFindPetsByStatusSWR.ts'
export { findPetsByTagsQueryKeySWR, findPetsByTagsQueryOptionsSWR, useFindPetsByTagsSWR } from './petSWRController/useFindPetsByTagsSWR.ts'
export { getPetByIdQueryKeySWR, getPetByIdQueryOptionsSWR, useGetPetByIdSWR } from './petSWRController/useGetPetByIdSWR.ts'
export { updatePetMutationKeySWR, useUpdatePetSWR } from './petSWRController/useUpdatePetSWR.ts'
export { updatePetWithFormMutationKeySWR, useUpdatePetWithFormSWR } from './petSWRController/useUpdatePetWithFormSWR.ts'
export { uploadFileMutationKeySWR, useUploadFileSWR } from './petSWRController/useUploadFileSWR.ts'
export { createUsersWithListInputMutationKeySWR, useCreateUsersWithListInputSWR } from './userSWRController/useCreateUsersWithListInputSWR.ts'
export { createUserMutationKeySWR, useCreateUserSWR } from './userSWRController/useCreateUserSWR.ts'
export { deleteUserMutationKeySWR, useDeleteUserSWR } from './userSWRController/useDeleteUserSWR.ts'
export { getUserByNameQueryKeySWR, getUserByNameQueryOptionsSWR, useGetUserByNameSWR } from './userSWRController/useGetUserByNameSWR.ts'
export { loginUserQueryKeySWR, loginUserQueryOptionsSWR, useLoginUserSWR } from './userSWRController/useLoginUserSWR.ts'
export { logoutUserQueryKeySWR, logoutUserQueryOptionsSWR, useLogoutUserSWR } from './userSWRController/useLogoutUserSWR.ts'
export { updateUserMutationKeySWR, useUpdateUserSWR } from './userSWRController/useUpdateUserSWR.ts'
16 changes: 16 additions & 0 deletions examples/advanced/src/gen/clients/swr/petSWRController/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type { AddPetMutationKeySWR } from './useAddPetSWR.ts'
export type { DeletePetMutationKeySWR } from './useDeletePetSWR.ts'
export type { FindPetsByStatusQueryKeySWR } from './useFindPetsByStatusSWR.ts'
export type { FindPetsByTagsQueryKeySWR } from './useFindPetsByTagsSWR.ts'
export type { GetPetByIdQueryKeySWR } from './useGetPetByIdSWR.ts'
export type { UpdatePetMutationKeySWR } from './useUpdatePetSWR.ts'
export type { UpdatePetWithFormMutationKeySWR } from './useUpdatePetWithFormSWR.ts'
export type { UploadFileMutationKeySWR } from './useUploadFileSWR.ts'
export { addPetMutationKeySWR, useAddPetSWR } from './useAddPetSWR.ts'
export { deletePetMutationKeySWR, useDeletePetSWR } from './useDeletePetSWR.ts'
export { findPetsByStatusQueryKeySWR, findPetsByStatusQueryOptionsSWR, useFindPetsByStatusSWR } from './useFindPetsByStatusSWR.ts'
export { findPetsByTagsQueryKeySWR, findPetsByTagsQueryOptionsSWR, useFindPetsByTagsSWR } from './useFindPetsByTagsSWR.ts'
export { getPetByIdQueryKeySWR, getPetByIdQueryOptionsSWR, useGetPetByIdSWR } from './useGetPetByIdSWR.ts'
export { updatePetMutationKeySWR, useUpdatePetSWR } from './useUpdatePetSWR.ts'
export { updatePetWithFormMutationKeySWR, useUpdatePetWithFormSWR } from './useUpdatePetWithFormSWR.ts'
export { uploadFileMutationKeySWR, useUploadFileSWR } from './useUploadFileSWR.ts'
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { RequestConfig } from '../../../../swr-client.ts'
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../../../models/ts/petController/AddPet.ts'
import { addPetMutationResponseSchema } from '../../../zod/petController/addPetSchema.ts'

export const addPetMutationKey = () => [{ url: '/pet' }] as const
export const addPetMutationKeySWR = () => [{ url: '/pet' }] as const

export type AddPetMutationKey = ReturnType<typeof addPetMutationKey>
export type AddPetMutationKeySWR = ReturnType<typeof addPetMutationKeySWR>

/**
* @description Add a new pet to the store
Expand All @@ -29,16 +29,16 @@ async function addPet(data: AddPetMutationRequest, config: Partial<RequestConfig
* @summary Add a new pet to the store
* @link /pet
*/
export function useAddPet(
export function useAddPetSWR(
options: {
mutation?: Parameters<typeof useSWRMutation<AddPetMutationResponse, AddPet405, AddPetMutationKey, AddPetMutationRequest>>[2]
mutation?: Parameters<typeof useSWRMutation<AddPetMutationResponse, AddPet405, AddPetMutationKeySWR, AddPetMutationRequest>>[2]
client?: Partial<RequestConfig<AddPetMutationRequest>>
shouldFetch?: boolean
} = {},
) {
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
const mutationKey = addPetMutationKey()
return useSWRMutation<AddPetMutationResponse, AddPet405, AddPetMutationKey | null, AddPetMutationRequest>(
const mutationKey = addPetMutationKeySWR()
return useSWRMutation<AddPetMutationResponse, AddPet405, AddPetMutationKeySWR | null, AddPetMutationRequest>(
shouldFetch ? mutationKey : null,
async (_url, { arg: data }) => {
return addPet(data, config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { RequestConfig } from '../../../../swr-client.ts'
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../../../models/ts/petController/DeletePet.ts'
import { deletePetMutationResponseSchema } from '../../../zod/petController/deletePetSchema.ts'

export const deletePetMutationKey = () => [{ url: '/pet/{petId}' }] as const
export const deletePetMutationKeySWR = () => [{ url: '/pet/{petId}' }] as const

export type DeletePetMutationKey = ReturnType<typeof deletePetMutationKey>
export type DeletePetMutationKeySWR = ReturnType<typeof deletePetMutationKeySWR>

/**
* @description delete a pet
Expand All @@ -29,18 +29,18 @@ async function deletePet(petId: DeletePetPathParams['petId'], headers?: DeletePe
* @summary Deletes a pet
* @link /pet/:petId
*/
export function useDeletePet(
export function useDeletePetSWR(
petId: DeletePetPathParams['petId'],
headers?: DeletePetHeaderParams,
options: {
mutation?: Parameters<typeof useSWRMutation<DeletePetMutationResponse, DeletePet400, DeletePetMutationKey>>[2]
mutation?: Parameters<typeof useSWRMutation<DeletePetMutationResponse, DeletePet400, DeletePetMutationKeySWR>>[2]
client?: Partial<RequestConfig>
shouldFetch?: boolean
} = {},
) {
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {}
const mutationKey = deletePetMutationKey()
return useSWRMutation<DeletePetMutationResponse, DeletePet400, DeletePetMutationKey | null>(
const mutationKey = deletePetMutationKeySWR()
return useSWRMutation<DeletePetMutationResponse, DeletePet400, DeletePetMutationKeySWR | null>(
shouldFetch ? mutationKey : null,
async (_url) => {
return deletePet(petId, headers, config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { RequestConfig } from '../../../../swr-client.ts'
import type { FindPetsByStatusQueryResponse, FindPetsByStatusQueryParams, FindPetsByStatus400 } from '../../../models/ts/petController/FindPetsByStatus.ts'
import { findPetsByStatusQueryResponseSchema } from '../../../zod/petController/findPetsByStatusSchema.ts'

export const findPetsByStatusQueryKey = (params?: FindPetsByStatusQueryParams) => [{ url: '/pet/findByStatus' }, ...(params ? [params] : [])] as const
export const findPetsByStatusQueryKeySWR = (params?: FindPetsByStatusQueryParams) => [{ url: '/pet/findByStatus' }, ...(params ? [params] : [])] as const

export type FindPetsByStatusQueryKey = ReturnType<typeof findPetsByStatusQueryKey>
export type FindPetsByStatusQueryKeySWR = ReturnType<typeof findPetsByStatusQueryKeySWR>

/**
* @description Multiple status values can be provided with comma separated strings
Expand All @@ -24,7 +24,7 @@ async function findPetsByStatus(params?: FindPetsByStatusQueryParams, config: Pa
return findPetsByStatusQueryResponseSchema.parse(res.data)
}

export function findPetsByStatusQueryOptions(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> = {}) {
export function findPetsByStatusQueryOptionsSWR(params?: FindPetsByStatusQueryParams, config: Partial<RequestConfig> = {}) {
return {
fetcher: async () => {
return findPetsByStatus(params, config)
Expand All @@ -37,18 +37,18 @@ export function findPetsByStatusQueryOptions(params?: FindPetsByStatusQueryParam
* @summary Finds Pets by status
* @link /pet/findByStatus
*/
export function useFindPetsByStatus(
export function useFindPetsByStatusSWR(
params?: FindPetsByStatusQueryParams,
options: {
query?: Parameters<typeof useSWR<FindPetsByStatusQueryResponse, FindPetsByStatus400, FindPetsByStatusQueryKey | null, any>>[2]
query?: Parameters<typeof useSWR<FindPetsByStatusQueryResponse, FindPetsByStatus400, FindPetsByStatusQueryKeySWR | null, any>>[2]
client?: Partial<RequestConfig>
shouldFetch?: boolean
} = {},
) {
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {}
const queryKey = findPetsByStatusQueryKey(params)
return useSWR<FindPetsByStatusQueryResponse, FindPetsByStatus400, FindPetsByStatusQueryKey | null>(shouldFetch ? queryKey : null, {
...findPetsByStatusQueryOptions(params, config),
const queryKey = findPetsByStatusQueryKeySWR(params)
return useSWR<FindPetsByStatusQueryResponse, FindPetsByStatus400, FindPetsByStatusQueryKeySWR | null>(shouldFetch ? queryKey : null, {
...findPetsByStatusQueryOptionsSWR(params, config),
...queryOptions,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type {
} from '../../../models/ts/petController/FindPetsByTags.ts'
import { findPetsByTagsQueryResponseSchema } from '../../../zod/petController/findPetsByTagsSchema.ts'

export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
export const findPetsByTagsQueryKeySWR = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const

export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>
export type FindPetsByTagsQueryKeySWR = ReturnType<typeof findPetsByTagsQueryKeySWR>

/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
Expand All @@ -30,7 +30,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find
return findPetsByTagsQueryResponseSchema.parse(res.data)
}

export function findPetsByTagsQueryOptions(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
export function findPetsByTagsQueryOptionsSWR(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
return {
fetcher: async () => {
return findPetsByTags(headers, params, config)
Expand All @@ -43,19 +43,19 @@ export function findPetsByTagsQueryOptions(headers: FindPetsByTagsHeaderParams,
* @summary Finds Pets by tags
* @link /pet/findByTags
*/
export function useFindPetsByTags(
export function useFindPetsByTagsSWR(
headers: FindPetsByTagsHeaderParams,
params?: FindPetsByTagsQueryParams,
options: {
query?: Parameters<typeof useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null, any>>[2]
query?: Parameters<typeof useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKeySWR | null, any>>[2]
client?: Partial<RequestConfig>
shouldFetch?: boolean
} = {},
) {
const { query: queryOptions, client: config = {}, shouldFetch = true } = options ?? {}
const queryKey = findPetsByTagsQueryKey(params)
return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKey | null>(shouldFetch ? queryKey : null, {
...findPetsByTagsQueryOptions(headers, params, config),
const queryKey = findPetsByTagsQueryKeySWR(params)
return useSWR<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsQueryKeySWR | null>(shouldFetch ? queryKey : null, {
...findPetsByTagsQueryOptionsSWR(headers, params, config),
...queryOptions,
})
}
Loading

0 comments on commit 39072a9

Please sign in to comment.