Skip to content

Commit

Permalink
Merge branch 'main' into feat/1436-paramsCasing
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/plugin-react-query/src/plugin.ts
#	packages/plugin-solid-query/src/plugin.ts
#	packages/plugin-svelte-query/src/plugin.ts
#	packages/plugin-swr/src/plugin.ts
#	packages/plugin-vue-query/src/plugin.ts
  • Loading branch information
stijnvanhulle committed Dec 7, 2024
2 parents d9c16d0 + 37e96ba commit 3eed735
Show file tree
Hide file tree
Showing 247 changed files with 4,129 additions and 4,647 deletions.
5 changes: 0 additions & 5 deletions .changeset/clean-wasps-rush.md

This file was deleted.

15 changes: 14 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ title: Changelog
- [`plugin-client`](/plugins/plugin-client): `paramsCasing` to define casing for params

## 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
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";
43 changes: 43 additions & 0 deletions examples/react-query/src/gen/hooks/pet/useAddPetHook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import client from "@kubb/plugin-client/client";
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from "../../models/AddPet";
import type { RequestConfig } from "@kubb/plugin-client/client";
import type { UseMutationOptions } from "@tanstack/react-query";
import { useMutation } from "@tanstack/react-query";

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

export type AddPetMutationKey = ReturnType<typeof addPetMutationKey>;

/**
* @description Add a new pet to the store
* @summary Add a new pet to the store
* {@link /pet}
*/
async function addPetHook(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> = {}) {
const res = await client<AddPetMutationResponse, AddPet405, AddPetMutationRequest>({ method: "POST", url: `/pet`, data, ...config });
return res.data;
}

/**
* @description Add a new pet to the store
* @summary Add a new pet to the store
* {@link /pet}
*/
export function useAddPetHook(options: {
mutation?: UseMutationOptions<AddPetMutationResponse, AddPet405, {
data: AddPetMutationRequest;
}>;
client?: Partial<RequestConfig<AddPetMutationRequest>>;
} = {}) {
const { mutation: mutationOptions, client: config = {} } = options ?? {};
const mutationKey = mutationOptions?.mutationKey ?? addPetMutationKey();
return useMutation<AddPetMutationResponse, AddPet405, {
data: AddPetMutationRequest;
}>({
mutationFn: async ({ data }) => {
return addPetHook(data, config);
},
mutationKey,
...mutationOptions
});
}
Loading

0 comments on commit 3eed735

Please sign in to comment.