@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.
68 lines (59 loc) • 2.35 kB
text/typescript
/**
* Generated by Kubb (https://kubb.dev/).
* Do not edit manually.
*/
import fetch from 'axios'
import useSWR from 'swr'
import type { Client, RequestConfig, ResponseErrorConfig } from 'axios'
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>
/**
* @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 async function findPetsByTags({ params }: { params?: FindPetsByTagsQueryParams } = {}, config: Partial<RequestConfig> & { client?: Client } = {}) {
const { client: request = fetch, ...requestConfig } = config
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
method: 'GET',
url: `/pet/findByTags`,
params,
...requestConfig,
})
return res.data
}
export function findPetsByTagsQueryOptions({ params }: { params?: FindPetsByTagsQueryParams }, config: Partial<RequestConfig> & { client?: Client } = {}) {
return {
fetcher: async () => {
return findPetsByTags({ params }, config)
},
}
}
/**
* @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 }: { params?: FindPetsByTagsQueryParams } = {},
options: {
query?: Parameters<typeof useSWR<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>>>[2]
client?: Partial<RequestConfig> & { client?: Client }
shouldFetch?: boolean
immutable?: boolean
} = {},
) {
const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {}
const queryKey = findPetsByTagsQueryKey(params)
return useSWR<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, FindPetsByTagsQueryKey | null>(shouldFetch ? queryKey : null, {
...findPetsByTagsQueryOptions({ params }, config),
...(immutable
? {
revalidateIfStale: false,
revalidateOnFocus: false,
revalidateOnReconnect: false,
}
: {}),
...queryOptions,
})
}