orval
orval copied to clipboard
Generating more than one `useShowPetById` function, bugs or feature?
Hello,
I am new in this awesome library.
I just follow the config from this docs with the same api specs.
It's generating 4 useShowPetById function. 1 the correct function (in my opinion) and another 3 are just signature without body. See the generated code below.
Is this something expected, if yes why? or just a bug?
/**
* @summary Info for a specific pet
*/
export const showPetById = (petId: string, options?: AxiosRequestConfig): Promise<AxiosResponse<Pet>> => {
return axios.default.get(`/pets/${petId}`, options);
};
export const getShowPetByIdQueryKey = (petId: string) => {
return [`/pets/${petId}`] as const;
};
export const getShowPetByIdQueryOptions = <TData = Awaited<ReturnType<typeof showPetById>>, TError = AxiosError<Error>>(
petId: string,
options?: { query?: Partial<UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData>>; axios?: AxiosRequestConfig },
) => {
const { query: queryOptions, axios: axiosOptions } = options ?? {};
const queryKey = queryOptions?.queryKey ?? getShowPetByIdQueryKey(petId);
const queryFn: QueryFunction<Awaited<ReturnType<typeof showPetById>>> = ({ signal }) => showPetById(petId, { signal, ...axiosOptions });
return { queryKey, queryFn, enabled: !!petId, ...queryOptions } as UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData> & {
queryKey: DataTag<QueryKey, TData, TError>;
};
};
export type ShowPetByIdQueryResult = NonNullable<Awaited<ReturnType<typeof showPetById>>>;
export type ShowPetByIdQueryError = AxiosError<Error>;
export function useShowPetById<TData = Awaited<ReturnType<typeof showPetById>>, TError = AxiosError<Error>>(
petId: string,
options: {
query: Partial<UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData>> &
Pick<DefinedInitialDataOptions<Awaited<ReturnType<typeof showPetById>>, TError, Awaited<ReturnType<typeof showPetById>>>, 'initialData'>;
axios?: AxiosRequestConfig;
},
queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
export function useShowPetById<TData = Awaited<ReturnType<typeof showPetById>>, TError = AxiosError<Error>>(
petId: string,
options?: {
query?: Partial<UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData>> &
Pick<UndefinedInitialDataOptions<Awaited<ReturnType<typeof showPetById>>, TError, Awaited<ReturnType<typeof showPetById>>>, 'initialData'>;
axios?: AxiosRequestConfig;
},
queryClient?: QueryClient,
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
export function useShowPetById<TData = Awaited<ReturnType<typeof showPetById>>, TError = AxiosError<Error>>(
petId: string,
options?: { query?: Partial<UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData>>; axios?: AxiosRequestConfig },
queryClient?: QueryClient,
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
/**
* @summary Info for a specific pet
*/
export function useShowPetById<TData = Awaited<ReturnType<typeof showPetById>>, TError = AxiosError<Error>>(
petId: string,
options?: { query?: Partial<UseQueryOptions<Awaited<ReturnType<typeof showPetById>>, TError, TData>>; axios?: AxiosRequestConfig },
queryClient?: QueryClient,
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getShowPetByIdQueryOptions(petId, options);
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey;
return query;
}
Is there an issue? I think all the code is correct
They are overloaded depending on your usage and use case
I am just curious. in the documentation, with the same config, it has no overloading.
Is the example in the documentation outdated?
@anymaniax @AllieJonsson @soartec-lab do any of you know the answer to this?
I think the documentation is outdated
Good first issue if you want to submit a PR @efriandika