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.

57 lines (50 loc) 1.88 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import fetch from 'axios' import useSWRMutation from 'swr/mutation' import type { RequestConfig, ResponseErrorConfig } from 'axios' export const updatePetWithFormMutationKey = () => [{ url: '/pet/{petId}' }] as const export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey> /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export async function updatePetWithForm( 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 } /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export function useUpdatePetWithForm( petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithFormQueryParams, options: { mutation?: Parameters<typeof useSWRMutation<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationKey>>[2] client?: Partial<RequestConfig> & { client?: typeof fetch } shouldFetch?: boolean } = {}, ) { const { mutation: mutationOptions, client: config = {}, shouldFetch = true } = options ?? {} const mutationKey = updatePetWithFormMutationKey() return useSWRMutation<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationKey | null>( shouldFetch ? mutationKey : null, async (_url) => { return updatePetWithForm(petId, params, config) }, mutationOptions, ) }