Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Group API Clients by Path Structure #1441

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/dirty-doors-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@kubb/plugin-svelte-query": minor
"@kubb/plugin-react-query": minor
"@kubb/plugin-solid-query": minor
"@kubb/plugin-vue-query": minor
"@kubb/plugin-client": minor
"@kubb/plugin-faker": minor
"@kubb/plugin-msw": minor
"@kubb/plugin-swr": minor
---

Group API clients by path structure
15 changes: 14 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ title: Changelog
# Changelog

## 3.1.0
- [`plugin-msw`](/plugins/plugin-msw): Support dynamic and customizable data in handlers
- [`plugin-react-query`](/plugins/plugin-react-query/): Group API clients by path structure
- [`plugin-svelte-query`](/plugins/plugin-svelte-query/): Group API clients by path structure
- [`plugin-vue-query`](/plugins/plugin-vue-query/): Group API clients by path structure
- [`plugin-solid-query`](/plugins/plugin-solid-query/): Group API clients by path structure
- [`plugin-msw`](/plugins/plugin-msw): Group API clients by path structure
```typescript
group: {
type: 'path',
name: ({ group }) => {
const firstSegment = group.split('/')[1];
return firstSegment;
}
}
```
```typescript
findPetsByStatusHandler((info) => {
const { params } = info
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { http } from 'msw'
import type { FindPetsByStatusQueryResponse } from '../../models/ts/petController/FindPetsByStatus.ts'
import { http } from 'msw'

export function findPetsByStatusHandler(data?: FindPetsByStatusQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response)) {
return http.get('*/pet/findByStatus/:step_id', function handler(info) {
Expand Down
12 changes: 12 additions & 0 deletions examples/client/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ export default defineConfig(() => {
pattern: 'store',
},
],
group: {
type: 'tag',
name({ group }) {
return `${group}Controller`
},
},
dataReturnType: 'full',
pathParamsType: 'object',
}),
Expand Down Expand Up @@ -111,6 +117,12 @@ export default defineConfig(() => {
pattern: 'store',
},
],
group: {
type: 'tag',
name({ group }) {
return `${group}Controller`
},
},
transformers: {
name(name, type) {
if (type === 'function') {
Expand Down
9 changes: 8 additions & 1 deletion examples/client/src/gen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,12 @@ export { addPetRequestStatusEnum } from './models/ts/AddPetRequest.js'
export { orderStatusEnum, orderHttpStatusEnum } from './models/ts/Order.js'
export { petStatusEnum } from './models/ts/Pet.js'
export { findPetsByStatusQueryParamsStatusEnum } from './models/ts/petController/FindPetsByStatus.js'
export { getInventoryController, placeOrderController, placeOrderPatchController, getOrderByIdController, deleteOrderController } from './tag.js'
export {
getInventoryController,
placeOrderController,
placeOrderPatchController,
getOrderByIdController,
deleteOrderController,
storeController,
} from './tag.js'
export { getInventory, placeOrder, placeOrderPatch, getOrderById, deleteOrder } from './tagObject.js'
4 changes: 4 additions & 0 deletions examples/client/src/gen/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ export async function deleteOrderController(orderId: DeleteOrderPathParams['orde
})
return res.data
}

export function storeController() {
return { getInventoryController, placeOrderController, placeOrderPatchController, getOrderByIdController, deleteOrderController }
}
3 changes: 3 additions & 0 deletions examples/react-query/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const config = {
output: {
path: './hooks',
},
group: {
type: 'path',
},
queryKey(props) {
const keys = QueryKey.getTransformer(props)
return ['"v5"', ...keys]
Expand Down
6 changes: 2 additions & 4 deletions examples/react-query/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { QueryClient, QueryClientProvider, useQueries } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { useState } from 'react'
import { findPetsByStatusQueryOptionsHook, useFindPetsByStatusHook } from './gen/hooks/useFindPetsByStatusHook.ts'
import { useFindPetsByTagsInfiniteHook } from './gen/hooks/useFindPetsByTagsInfiniteHook.ts'
import { useUpdatePetWithFormHook } from './gen/hooks/useUpdatePetWithFormHook.ts'
import type { FindPetsByStatusQueryParamsStatusEnum } from './gen/models/FindPetsByStatus.ts'
import { findPetsByStatusQueryOptionsHook, useFindPetsByStatusHook, useFindPetsByTagsInfiniteHook, useUpdatePetWithFormHook } from './gen/hooks/index.ts'
import type { FindPetsByStatusQueryParamsStatusEnum } from './gen/models'

const queryClient = new QueryClient()

Expand Down
128 changes: 60 additions & 68 deletions examples/react-query/src/gen/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,60 @@
export type { AddPetMutationKey } from './useAddPetHook.ts'
export type { CreateUserMutationKey } from './useCreateUserHook.ts'
export type { CreateUsersWithListInputMutationKey } from './useCreateUsersWithListInputHook.ts'
export type { DeleteOrderMutationKey } from './useDeleteOrderHook.ts'
export type { DeletePetMutationKey } from './useDeletePetHook.ts'
export type { DeleteUserMutationKey } from './useDeleteUserHook.ts'
export type { FindPetsByStatusQueryKey } from './useFindPetsByStatusHook.ts'
export type { FindPetsByStatusSuspenseQueryKey } from './useFindPetsByStatusSuspenseHook.ts'
export type { FindPetsByTagsQueryKey } from './useFindPetsByTagsHook.ts'
export type { FindPetsByTagsInfiniteQueryKey } from './useFindPetsByTagsInfiniteHook.ts'
export type { FindPetsByTagsSuspenseQueryKey } from './useFindPetsByTagsSuspenseHook.ts'
export type { GetInventoryQueryKey } from './useGetInventoryHook.ts'
export type { GetInventorySuspenseQueryKey } from './useGetInventorySuspenseHook.ts'
export type { GetOrderByIdQueryKey } from './useGetOrderByIdHook.ts'
export type { GetOrderByIdSuspenseQueryKey } from './useGetOrderByIdSuspenseHook.ts'
export type { GetPetByIdQueryKey } from './useGetPetByIdHook.ts'
export type { GetPetByIdSuspenseQueryKey } from './useGetPetByIdSuspenseHook.ts'
export type { GetUserByNameQueryKey } from './useGetUserByNameHook.ts'
export type { GetUserByNameSuspenseQueryKey } from './useGetUserByNameSuspenseHook.ts'
export type { LoginUserQueryKey } from './useLoginUserHook.ts'
export type { LoginUserSuspenseQueryKey } from './useLoginUserSuspenseHook.ts'
export type { LogoutUserQueryKey } from './useLogoutUserHook.ts'
export type { LogoutUserSuspenseQueryKey } from './useLogoutUserSuspenseHook.ts'
export type { PlaceOrderMutationKey } from './usePlaceOrderHook.ts'
export type { PlaceOrderPatchMutationKey } from './usePlaceOrderPatchHook.ts'
export type { UpdatePetMutationKey } from './useUpdatePetHook.ts'
export type { UpdatePetWithFormQueryKey } from './useUpdatePetWithFormHook.ts'
export type { UpdatePetWithFormSuspenseQueryKey } from './useUpdatePetWithFormSuspenseHook.ts'
export type { UpdateUserMutationKey } from './useUpdateUserHook.ts'
export type { UploadFileMutationKey } from './useUploadFileHook.ts'
export { addPetMutationKey, useAddPetHook } from './useAddPetHook.ts'
export { createUserMutationKey, useCreateUserHook } from './useCreateUserHook.ts'
export { createUsersWithListInputMutationKey, useCreateUsersWithListInputHook } from './useCreateUsersWithListInputHook.ts'
export { deleteOrderMutationKey, useDeleteOrderHook } from './useDeleteOrderHook.ts'
export { deletePetMutationKey, useDeletePetHook } from './useDeletePetHook.ts'
export { deleteUserMutationKey, useDeleteUserHook } from './useDeleteUserHook.ts'
export { findPetsByStatusQueryKey, findPetsByStatusQueryOptionsHook, useFindPetsByStatusHook } from './useFindPetsByStatusHook.ts'
export {
findPetsByStatusSuspenseQueryKey,
findPetsByStatusSuspenseQueryOptionsHook,
useFindPetsByStatusSuspenseHook,
} from './useFindPetsByStatusSuspenseHook.ts'
export { findPetsByTagsQueryKey, findPetsByTagsQueryOptionsHook, useFindPetsByTagsHook } from './useFindPetsByTagsHook.ts'
export { findPetsByTagsInfiniteQueryKey, findPetsByTagsInfiniteQueryOptionsHook, useFindPetsByTagsInfiniteHook } from './useFindPetsByTagsInfiniteHook.ts'
export { findPetsByTagsSuspenseQueryKey, findPetsByTagsSuspenseQueryOptionsHook, useFindPetsByTagsSuspenseHook } from './useFindPetsByTagsSuspenseHook.ts'
export { getInventoryQueryKey, getInventoryQueryOptionsHook } from './useGetInventoryHook.ts'
export { getInventorySuspenseQueryKey, getInventorySuspenseQueryOptionsHook, useGetInventorySuspenseHook } from './useGetInventorySuspenseHook.ts'
export { getOrderByIdQueryKey, getOrderByIdQueryOptionsHook, useGetOrderByIdHook } from './useGetOrderByIdHook.ts'
export { getOrderByIdSuspenseQueryKey, getOrderByIdSuspenseQueryOptionsHook, useGetOrderByIdSuspenseHook } from './useGetOrderByIdSuspenseHook.ts'
export { getPetByIdQueryKey, getPetByIdQueryOptionsHook, useGetPetByIdHook } from './useGetPetByIdHook.ts'
export { getPetByIdSuspenseQueryKey, getPetByIdSuspenseQueryOptionsHook, useGetPetByIdSuspenseHook } from './useGetPetByIdSuspenseHook.ts'
export { getUserByNameQueryKey, getUserByNameQueryOptionsHook, useGetUserByNameHook } from './useGetUserByNameHook.ts'
export { getUserByNameSuspenseQueryKey, getUserByNameSuspenseQueryOptionsHook, useGetUserByNameSuspenseHook } from './useGetUserByNameSuspenseHook.ts'
export { loginUserQueryKey, loginUserQueryOptionsHook, useLoginUserHook } from './useLoginUserHook.ts'
export { loginUserSuspenseQueryKey, loginUserSuspenseQueryOptionsHook, useLoginUserSuspenseHook } from './useLoginUserSuspenseHook.ts'
export { logoutUserQueryKey, logoutUserQueryOptionsHook, useLogoutUserHook } from './useLogoutUserHook.ts'
export { logoutUserSuspenseQueryKey, logoutUserSuspenseQueryOptionsHook, useLogoutUserSuspenseHook } from './useLogoutUserSuspenseHook.ts'
export { placeOrderMutationKey, usePlaceOrderHook } from './usePlaceOrderHook.ts'
export { placeOrderPatchMutationKey, usePlaceOrderPatchHook } from './usePlaceOrderPatchHook.ts'
export { updatePetMutationKey, useUpdatePetHook } from './useUpdatePetHook.ts'
export { updatePetWithFormQueryKey, updatePetWithFormQueryOptionsHook, useUpdatePetWithFormHook } from './useUpdatePetWithFormHook.ts'
export {
updatePetWithFormSuspenseQueryKey,
updatePetWithFormSuspenseQueryOptionsHook,
useUpdatePetWithFormSuspenseHook,
} from './useUpdatePetWithFormSuspenseHook.ts'
export { updateUserMutationKey, useUpdateUserHook } from './useUpdateUserHook.ts'
export { uploadFileMutationKey, useUploadFileHook } from './useUploadFileHook.ts'
export type { AddPetMutationKey } from "./pet/useAddPetHook";
export type { DeletePetMutationKey } from "./pet/useDeletePetHook";
export type { FindPetsByStatusQueryKey } from "./pet/useFindPetsByStatusHook";
export type { FindPetsByStatusSuspenseQueryKey } from "./pet/useFindPetsByStatusSuspenseHook";
export type { FindPetsByTagsQueryKey } from "./pet/useFindPetsByTagsHook";
export type { FindPetsByTagsInfiniteQueryKey } from "./pet/useFindPetsByTagsInfiniteHook";
export type { FindPetsByTagsSuspenseQueryKey } from "./pet/useFindPetsByTagsSuspenseHook";
export type { GetPetByIdQueryKey } from "./pet/useGetPetByIdHook";
export type { GetPetByIdSuspenseQueryKey } from "./pet/useGetPetByIdSuspenseHook";
export type { UpdatePetMutationKey } from "./pet/useUpdatePetHook";
export type { UpdatePetWithFormQueryKey } from "./pet/useUpdatePetWithFormHook";
export type { UpdatePetWithFormSuspenseQueryKey } from "./pet/useUpdatePetWithFormSuspenseHook";
export type { UploadFileMutationKey } from "./pet/useUploadFileHook";
export type { DeleteOrderMutationKey } from "./store/useDeleteOrderHook";
export type { GetInventoryQueryKey } from "./store/useGetInventoryHook";
export type { GetInventorySuspenseQueryKey } from "./store/useGetInventorySuspenseHook";
export type { GetOrderByIdQueryKey } from "./store/useGetOrderByIdHook";
export type { GetOrderByIdSuspenseQueryKey } from "./store/useGetOrderByIdSuspenseHook";
export type { PlaceOrderMutationKey } from "./store/usePlaceOrderHook";
export type { PlaceOrderPatchMutationKey } from "./store/usePlaceOrderPatchHook";
export type { CreateUserMutationKey } from "./user/useCreateUserHook";
export type { CreateUsersWithListInputMutationKey } from "./user/useCreateUsersWithListInputHook";
export type { DeleteUserMutationKey } from "./user/useDeleteUserHook";
export type { GetUserByNameQueryKey } from "./user/useGetUserByNameHook";
export type { GetUserByNameSuspenseQueryKey } from "./user/useGetUserByNameSuspenseHook";
export type { LoginUserQueryKey } from "./user/useLoginUserHook";
export type { LoginUserSuspenseQueryKey } from "./user/useLoginUserSuspenseHook";
export type { LogoutUserQueryKey } from "./user/useLogoutUserHook";
export type { LogoutUserSuspenseQueryKey } from "./user/useLogoutUserSuspenseHook";
export type { UpdateUserMutationKey } from "./user/useUpdateUserHook";
export { addPetMutationKey, useAddPetHook } from "./pet/useAddPetHook";
export { deletePetMutationKey, useDeletePetHook } from "./pet/useDeletePetHook";
export { findPetsByStatusQueryKey, findPetsByStatusQueryOptionsHook, useFindPetsByStatusHook } from "./pet/useFindPetsByStatusHook";
export { findPetsByStatusSuspenseQueryKey, findPetsByStatusSuspenseQueryOptionsHook, useFindPetsByStatusSuspenseHook } from "./pet/useFindPetsByStatusSuspenseHook";
export { findPetsByTagsQueryKey, findPetsByTagsQueryOptionsHook, useFindPetsByTagsHook } from "./pet/useFindPetsByTagsHook";
export { findPetsByTagsInfiniteQueryKey, findPetsByTagsInfiniteQueryOptionsHook, useFindPetsByTagsInfiniteHook } from "./pet/useFindPetsByTagsInfiniteHook";
export { findPetsByTagsSuspenseQueryKey, findPetsByTagsSuspenseQueryOptionsHook, useFindPetsByTagsSuspenseHook } from "./pet/useFindPetsByTagsSuspenseHook";
export { getPetByIdQueryKey, getPetByIdQueryOptionsHook, useGetPetByIdHook } from "./pet/useGetPetByIdHook";
export { getPetByIdSuspenseQueryKey, getPetByIdSuspenseQueryOptionsHook, useGetPetByIdSuspenseHook } from "./pet/useGetPetByIdSuspenseHook";
export { updatePetMutationKey, useUpdatePetHook } from "./pet/useUpdatePetHook";
export { updatePetWithFormQueryKey, updatePetWithFormQueryOptionsHook, useUpdatePetWithFormHook } from "./pet/useUpdatePetWithFormHook";
export { updatePetWithFormSuspenseQueryKey, updatePetWithFormSuspenseQueryOptionsHook, useUpdatePetWithFormSuspenseHook } from "./pet/useUpdatePetWithFormSuspenseHook";
export { uploadFileMutationKey, useUploadFileHook } from "./pet/useUploadFileHook";
export { deleteOrderMutationKey, useDeleteOrderHook } from "./store/useDeleteOrderHook";
export { getInventoryQueryKey, getInventoryQueryOptionsHook } from "./store/useGetInventoryHook";
export { getInventorySuspenseQueryKey, getInventorySuspenseQueryOptionsHook, useGetInventorySuspenseHook } from "./store/useGetInventorySuspenseHook";
export { getOrderByIdQueryKey, getOrderByIdQueryOptionsHook, useGetOrderByIdHook } from "./store/useGetOrderByIdHook";
export { getOrderByIdSuspenseQueryKey, getOrderByIdSuspenseQueryOptionsHook, useGetOrderByIdSuspenseHook } from "./store/useGetOrderByIdSuspenseHook";
export { placeOrderMutationKey, usePlaceOrderHook } from "./store/usePlaceOrderHook";
export { placeOrderPatchMutationKey, usePlaceOrderPatchHook } from "./store/usePlaceOrderPatchHook";
export { createUserMutationKey, useCreateUserHook } from "./user/useCreateUserHook";
export { createUsersWithListInputMutationKey, useCreateUsersWithListInputHook } from "./user/useCreateUsersWithListInputHook";
export { deleteUserMutationKey, useDeleteUserHook } from "./user/useDeleteUserHook";
export { getUserByNameQueryKey, getUserByNameQueryOptionsHook, useGetUserByNameHook } from "./user/useGetUserByNameHook";
export { getUserByNameSuspenseQueryKey, getUserByNameSuspenseQueryOptionsHook, useGetUserByNameSuspenseHook } from "./user/useGetUserByNameSuspenseHook";
export { loginUserQueryKey, loginUserQueryOptionsHook, useLoginUserHook } from "./user/useLoginUserHook";
export { loginUserSuspenseQueryKey, loginUserSuspenseQueryOptionsHook, useLoginUserSuspenseHook } from "./user/useLoginUserSuspenseHook";
export { logoutUserQueryKey, logoutUserQueryOptionsHook, useLogoutUserHook } from "./user/useLogoutUserHook";
export { logoutUserSuspenseQueryKey, logoutUserSuspenseQueryOptionsHook, useLogoutUserSuspenseHook } from "./user/useLogoutUserSuspenseHook";
export { updateUserMutationKey, useUpdateUserHook } from "./user/useUpdateUserHook";
26 changes: 26 additions & 0 deletions examples/react-query/src/gen/hooks/pet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type { AddPetMutationKey } from "./useAddPetHook";
export type { DeletePetMutationKey } from "./useDeletePetHook";
export type { FindPetsByStatusQueryKey } from "./useFindPetsByStatusHook";
export type { FindPetsByStatusSuspenseQueryKey } from "./useFindPetsByStatusSuspenseHook";
export type { FindPetsByTagsQueryKey } from "./useFindPetsByTagsHook";
export type { FindPetsByTagsInfiniteQueryKey } from "./useFindPetsByTagsInfiniteHook";
export type { FindPetsByTagsSuspenseQueryKey } from "./useFindPetsByTagsSuspenseHook";
export type { GetPetByIdQueryKey } from "./useGetPetByIdHook";
export type { GetPetByIdSuspenseQueryKey } from "./useGetPetByIdSuspenseHook";
export type { UpdatePetMutationKey } from "./useUpdatePetHook";
export type { UpdatePetWithFormQueryKey } from "./useUpdatePetWithFormHook";
export type { UpdatePetWithFormSuspenseQueryKey } from "./useUpdatePetWithFormSuspenseHook";
export type { UploadFileMutationKey } from "./useUploadFileHook";
export { addPetMutationKey, useAddPetHook } from "./useAddPetHook";
export { deletePetMutationKey, useDeletePetHook } from "./useDeletePetHook";
export { findPetsByStatusQueryKey, findPetsByStatusQueryOptionsHook, useFindPetsByStatusHook } from "./useFindPetsByStatusHook";
export { findPetsByStatusSuspenseQueryKey, findPetsByStatusSuspenseQueryOptionsHook, useFindPetsByStatusSuspenseHook } from "./useFindPetsByStatusSuspenseHook";
export { findPetsByTagsQueryKey, findPetsByTagsQueryOptionsHook, useFindPetsByTagsHook } from "./useFindPetsByTagsHook";
export { findPetsByTagsInfiniteQueryKey, findPetsByTagsInfiniteQueryOptionsHook, useFindPetsByTagsInfiniteHook } from "./useFindPetsByTagsInfiniteHook";
export { findPetsByTagsSuspenseQueryKey, findPetsByTagsSuspenseQueryOptionsHook, useFindPetsByTagsSuspenseHook } from "./useFindPetsByTagsSuspenseHook";
export { getPetByIdQueryKey, getPetByIdQueryOptionsHook, useGetPetByIdHook } from "./useGetPetByIdHook";
export { getPetByIdSuspenseQueryKey, getPetByIdSuspenseQueryOptionsHook, useGetPetByIdSuspenseHook } from "./useGetPetByIdSuspenseHook";
export { updatePetMutationKey, useUpdatePetHook } from "./useUpdatePetHook";
export { updatePetWithFormQueryKey, updatePetWithFormQueryOptionsHook, useUpdatePetWithFormHook } from "./useUpdatePetWithFormHook";
export { updatePetWithFormSuspenseQueryKey, updatePetWithFormSuspenseQueryOptionsHook, useUpdatePetWithFormSuspenseHook } from "./useUpdatePetWithFormSuspenseHook";
export { uploadFileMutationKey, useUploadFileHook } from "./useUploadFileHook";
Loading
Loading