@kubb/plugin-swr
Version:
SWR hooks generator plugin for Kubb, creating type-safe data fetching hooks from OpenAPI specifications for React and Next.js applications.
35 lines (30 loc) • 1.65 kB
text/typescript
import client from "@kubb/plugin-client/clients/axios";
import useSWRMutation from "custom-swr/mutation";
import type { RequestConfig } from "@kubb/plugin-client/clients/axios";
export const findPetsByTagsMutationKey = () => [{ "url": "/pet/findByTags" }] as const;
export type FindPetsByTagsMutationKey = ReturnType<typeof findPetsByTagsMutationKey>;
/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
* @link /pet/findByTags
*/
async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, ...config });
return res.data;
}
/**
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @summary Finds Pets by tags
* @link /pet/findByTags
*/
export function useFindPetsByTags(params?: FindPetsByTagsQueryParams, options: {
mutation?: Parameters<typeof useSWRMutation<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsMutationKey>>[2];
client?: Partial<RequestConfig>;
shouldFetch?: boolean;
} = {}) {
const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {};
const mutationKey = findPetsByTagsMutationKey();
return useSWRMutation<FindPetsByTagsQueryResponse, FindPetsByTags400, FindPetsByTagsMutationKey | null>(shouldFetch ? mutationKey : null, async (_url) => {
return findPetsByTags(params, config);
}, mutationOptions);
}