@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.06 kB
text/typescript
/**
* Generated by Kubb (https://kubb.dev/).
* Do not edit manually.
*/
import useSWRMutation from 'swr/mutation'
import type { Client, RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
import type { SWRMutationConfiguration } from 'swr/mutation'
import { fetch } from './test/.kubb/fetch'
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 }: { 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 }: { 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,
)
}