|
| 1 | +/** |
| 2 | + * Generated by orval v8.11.0 🍺 |
| 3 | + * Do not edit manually. |
| 4 | + * Issue 1026 - Vue Query header parameters |
| 5 | + * OpenAPI spec version: 1.0.0 |
| 6 | + */ |
| 7 | +import { useQuery } from '@tanstack/vue-query'; |
| 8 | +import type { |
| 9 | + DataTag, |
| 10 | + QueryClient, |
| 11 | + QueryFunction, |
| 12 | + QueryKey, |
| 13 | + UseQueryOptions, |
| 14 | + UseQueryReturnType, |
| 15 | +} from '@tanstack/vue-query'; |
| 16 | + |
| 17 | +import axios from 'axios'; |
| 18 | +import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'; |
| 19 | + |
| 20 | +import { unref } from 'vue'; |
| 21 | +import type { MaybeRef } from 'vue'; |
| 22 | + |
| 23 | +import type { GetSomeEndpointHeaders, SomeEndpointResult } from './model'; |
| 24 | + |
| 25 | +/** |
| 26 | + * @summary Get something with header parameters |
| 27 | + */ |
| 28 | +export const getSomeEndpoint = ( |
| 29 | + headers?: MaybeRef<GetSomeEndpointHeaders>, |
| 30 | + options?: AxiosRequestConfig, |
| 31 | +): Promise<AxiosResponse<SomeEndpointResult>> => { |
| 32 | + headers = unref(headers); |
| 33 | + |
| 34 | + return axios.get(`/api/v1/someEndPoint`, { |
| 35 | + ...options, |
| 36 | + headers: { ...headers, ...options?.headers }, |
| 37 | + }); |
| 38 | +}; |
| 39 | + |
| 40 | +export const getGetSomeEndpointQueryKey = () => { |
| 41 | + return ['api', 'v1', 'someEndPoint'] as const; |
| 42 | +}; |
| 43 | + |
| 44 | +export const getGetSomeEndpointQueryOptions = < |
| 45 | + TData = Awaited<ReturnType<typeof getSomeEndpoint>>, |
| 46 | + TError = AxiosError<unknown>, |
| 47 | +>( |
| 48 | + headers?: MaybeRef<GetSomeEndpointHeaders>, |
| 49 | + options?: { |
| 50 | + query?: Partial< |
| 51 | + UseQueryOptions< |
| 52 | + Awaited<ReturnType<typeof getSomeEndpoint>>, |
| 53 | + TError, |
| 54 | + TData |
| 55 | + > |
| 56 | + >; |
| 57 | + axios?: AxiosRequestConfig; |
| 58 | + }, |
| 59 | +) => { |
| 60 | + const { query: queryOptions, axios: axiosOptions } = options ?? {}; |
| 61 | + |
| 62 | + const queryKey = getGetSomeEndpointQueryKey(); |
| 63 | + |
| 64 | + const queryFn: QueryFunction<Awaited<ReturnType<typeof getSomeEndpoint>>> = ({ |
| 65 | + signal, |
| 66 | + }) => getSomeEndpoint(headers, { signal, ...axiosOptions }); |
| 67 | + |
| 68 | + return { queryKey, queryFn, ...queryOptions } as UseQueryOptions< |
| 69 | + Awaited<ReturnType<typeof getSomeEndpoint>>, |
| 70 | + TError, |
| 71 | + TData |
| 72 | + >; |
| 73 | +}; |
| 74 | + |
| 75 | +export type GetSomeEndpointQueryResult = NonNullable< |
| 76 | + Awaited<ReturnType<typeof getSomeEndpoint>> |
| 77 | +>; |
| 78 | +export type GetSomeEndpointQueryError = AxiosError<unknown>; |
| 79 | + |
| 80 | +/** |
| 81 | + * @summary Get something with header parameters |
| 82 | + */ |
| 83 | + |
| 84 | +export function useGetSomeEndpoint< |
| 85 | + TData = Awaited<ReturnType<typeof getSomeEndpoint>>, |
| 86 | + TError = AxiosError<unknown>, |
| 87 | +>( |
| 88 | + headers?: MaybeRef<GetSomeEndpointHeaders>, |
| 89 | + options?: { |
| 90 | + query?: Partial< |
| 91 | + UseQueryOptions< |
| 92 | + Awaited<ReturnType<typeof getSomeEndpoint>>, |
| 93 | + TError, |
| 94 | + TData |
| 95 | + > |
| 96 | + >; |
| 97 | + axios?: AxiosRequestConfig; |
| 98 | + }, |
| 99 | + queryClient?: QueryClient, |
| 100 | +): UseQueryReturnType<TData, TError> & { |
| 101 | + queryKey: DataTag<QueryKey, TData, TError>; |
| 102 | +} { |
| 103 | + const queryOptions = getGetSomeEndpointQueryOptions(headers, options); |
| 104 | + |
| 105 | + const query = useQuery(queryOptions, queryClient) as UseQueryReturnType< |
| 106 | + TData, |
| 107 | + TError |
| 108 | + > & { queryKey: DataTag<QueryKey, TData, TError> }; |
| 109 | + |
| 110 | + query.queryKey = unref(queryOptions).queryKey as DataTag< |
| 111 | + QueryKey, |
| 112 | + TData, |
| 113 | + TError |
| 114 | + >; |
| 115 | + |
| 116 | + return query; |
| 117 | +} |
0 commit comments