UNPKG

@kubb/plugin-vue-query

Version:

Vue Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for Vue.js applications.

77 lines (70 loc) 2.65 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import fetch from 'axios' import type { MutationObserverOptions, QueryClient } from '@tanstack/vue-query' import type { RequestConfig, ResponseErrorConfig } from 'axios' import type { MaybeRefOrGetter } from 'vue' import { useMutation } from '@tanstack/vue-query' 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'], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {}, ) { const { client: request = fetch, ...requestConfig } = config const requestData = updatePetWithFormMutationRequest.parse(data) const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationRequest>({ method: 'POST', url: `/pet/${petId}`, params, data: requestData, ...requestConfig, }) return updatePetWithFormMutationResponse.parse(res.data) } /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export function useUpdatePetWithForm<TContext>( options: { mutation?: MutationObserverOptions< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: MaybeRefOrGetter<UpdatePetWithFormPathParams['petId']> data?: MaybeRefOrGetter<UpdatePetWithFormMutationRequest> params?: MaybeRefOrGetter<UpdatePetWithFormQueryParams> }, TContext > & { client?: QueryClient } client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } } = {}, ) { const { mutation = {}, client: config = {} } = options ?? {} const { client: queryClient, ...mutationOptions } = mutation const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey() return useMutation< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext >( { mutationFn: async ({ petId, data, params }) => { return updatePetWithForm(petId, data, params, config) }, mutationKey, ...mutationOptions, }, queryClient, ) }