UNPKG

@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.

73 lines (64 loc) 2.56 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import fetch from '@kubb/plugin-client/clients/axios' import useSWR from 'custom-swr' import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' export const updatePetWithFormQueryKey = (petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithFormQueryParams) => [{ url: '/pet/:petId', params: { petId: petId } }, ...(params ? [params] : [])] as const export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey> /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export async function updatePetWithForm( { petId, params }: { petId: UpdatePetWithFormPathParams['petId']; params?: UpdatePetWithFormQueryParams }, config: Partial<RequestConfig> & { client?: typeof fetch } = {}, ) { const { client: request = fetch, ...requestConfig } = config const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, unknown>({ method: 'POST', url: `/pet/${petId}`, params, ...requestConfig, }) return res.data } export function updatePetWithFormQueryOptions( { petId, params }: { petId: UpdatePetWithFormPathParams['petId']; params?: UpdatePetWithFormQueryParams }, config: Partial<RequestConfig> & { client?: typeof fetch } = {}, ) { return { fetcher: async () => { return updatePetWithForm({ petId, params }, config) }, } } /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export function useUpdatePetWithForm( { petId, params }: { petId: UpdatePetWithFormPathParams['petId']; params?: UpdatePetWithFormQueryParams }, options: { query?: Parameters<typeof useSWR<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>>>[2] client?: Partial<RequestConfig> & { client?: typeof fetch } shouldFetch?: boolean immutable?: boolean } = {}, ) { const { query: queryOptions, client: config = {}, shouldFetch = true, immutable } = options ?? {} const queryKey = updatePetWithFormQueryKey(petId, params) return useSWR<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormQueryKey | null>(shouldFetch ? queryKey : null, { ...updatePetWithFormQueryOptions({ petId, params }, config), ...(immutable ? { revalidateIfStale: false, revalidateOnFocus: false, revalidateOnReconnect: false, } : {}), ...queryOptions, }) }