Skip to content

Generating more than one useShowPetById function, bugs or feature? #2086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
efriandika opened this issue May 13, 2025 · 5 comments
Open

Generating more than one useShowPetById function, bugs or feature? #2086

efriandika opened this issue May 13, 2025 · 5 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@efriandika
Copy link

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;
}

@melloware
Copy link
Collaborator

melloware commented May 17, 2025

Is there an issue? I think all the code is correct

They are overloaded depending on your usage and use case

@melloware melloware added the question Further information is requested label May 17, 2025
@efriandika
Copy link
Author

I am just curious. in the documentation, with the same config, it has no overloading.

Is the example in the documentation outdated?

@melloware
Copy link
Collaborator

@anymaniax @AllieJonsson @soartec-lab do any of you know the answer to this?

@AllieJonsson
Copy link
Contributor

I think the documentation is outdated

@melloware melloware added documentation Improvements or additions to documentation good first issue Good for newcomers and removed question Further information is requested labels May 18, 2025
@melloware
Copy link
Collaborator

Good first issue if you want to submit a PR @efriandika

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants