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.

63 lines (56 loc) 2 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import fetch from 'axios' import useSWRMutation from 'swr/mutation' import type { Client, RequestConfig, ResponseErrorConfig } from 'axios' import type { SWRMutationConfiguration } from 'swr/mutation' 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?: Client } = {}, ) { 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?: SWRMutationConfiguration< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationKey | null, never > & { throwOnError?: boolean } client?: Partial<RequestConfig> & { client?: Client } 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, ) }