@@ -249,6 +249,112 @@ describe("generateReactQueryComponents", () => {
249249 ` ) ;
250250 } ) ;
251251
252+ it ( "should generate a useQuery wrapper (with pathParams)" , async ( ) => {
253+ const writeFile = jest . fn ( ) ;
254+ const openAPIDocument : OpenAPIObject = {
255+ openapi : "3.0.0" ,
256+ info : {
257+ title : "petshop" ,
258+ version : "1.0.0" ,
259+ } ,
260+ paths : {
261+ "/pets/{pet_id}" : {
262+ get : {
263+ operationId : "showPetById" ,
264+ description : "Info for a specific pet" ,
265+ parameters : [
266+ {
267+ in : "path" ,
268+ name : "pet_id" ,
269+ description : "The id of the pet to retrieve" ,
270+ required : true ,
271+ schema : {
272+ type : "string" ,
273+ } ,
274+ } ,
275+ ] ,
276+ responses : {
277+ "200" : {
278+ description : "pet response" ,
279+ content : {
280+ "application/json" : {
281+ schema : {
282+ type : "array" ,
283+ items : {
284+ $ref : "#/components/schemas/Pet" ,
285+ } ,
286+ } ,
287+ } ,
288+ } ,
289+ } ,
290+ } ,
291+ } ,
292+ } ,
293+ } ,
294+ } ;
295+
296+ await generateReactQueryComponents (
297+ {
298+ openAPIDocument,
299+ writeFile,
300+ existsFile : ( ) => true ,
301+ readFile : async ( ) => "" ,
302+ } ,
303+ config
304+ ) ;
305+
306+ expect ( writeFile . mock . calls [ 0 ] [ 0 ] ) . toBe ( "petstoreComponents.ts" ) ;
307+ expect ( writeFile . mock . calls [ 0 ] [ 1 ] ) . toMatchInlineSnapshot ( `
308+ "/**
309+ * Generated by @openapi-codegen
310+ *
311+ * @version 1.0.0
312+ */
313+ import * as reactQuery from \\"@tanstack/react-query\\";
314+ import { usePetstoreContext, PetstoreContext } from \\"./petstoreContext\\";
315+ import type * as Fetcher from \\"./petstoreFetcher\\";
316+ import { petstoreFetch } from \\"./petstoreFetcher\\";
317+ import type * as Schemas from \\"./petstoreSchemas\\";
318+
319+ export type ShowPetByIdPathParams = {
320+ /**
321+ * The id of the pet to retrieve
322+ */
323+ petId: string;
324+ };
325+
326+ export type ShowPetByIdError = Fetcher.ErrorWrapper<undefined>;
327+
328+ export type ShowPetByIdResponse = Schemas.Pet[];
329+
330+ export type ShowPetByIdVariables = {
331+ pathParams: ShowPetByIdPathParams;
332+ } & PetstoreContext[\\"fetcherOptions\\"];
333+
334+ /**
335+ * Info for a specific pet
336+ */
337+ export const fetchShowPetById = (variables: ShowPetByIdVariables, signal?: AbortSignal) => petstoreFetch<ShowPetByIdResponse, ShowPetByIdError, undefined, {}, {}, ShowPetByIdPathParams>({ url: \\"/pets/{petId}\\", method: \\"get\\", ...variables, signal });
338+
339+ /**
340+ * Info for a specific pet
341+ */
342+ export const useShowPetById = <TData = ShowPetByIdResponse>(variables: ShowPetByIdVariables, options?: Omit<reactQuery.UseQueryOptions<ShowPetByIdResponse, ShowPetByIdError, TData>, \\"queryKey\\" | \\"queryFn\\" | \\"initialData\\">) => { const { fetcherOptions, queryOptions, queryKeyFn } = usePetstoreContext(options); return reactQuery.useQuery<ShowPetByIdResponse, ShowPetByIdError, TData>({
343+ queryKey: queryKeyFn({ path: \\"/pets/{petId}\\", operationId: \\"showPetById\\", variables }),
344+ queryFn: ({ signal }) => fetchShowPetById({ ...fetcherOptions, ...variables }, signal),
345+ ...options,
346+ ...queryOptions
347+ }); };
348+
349+ export type QueryOperation = {
350+ path: \\"/pets/{petId}\\";
351+ operationId: \\"showPetById\\";
352+ variables: ShowPetByIdVariables;
353+ };
354+ "
355+ ` ) ;
356+ } ) ;
357+
252358 it ( "should deal with injected headers (marked them as optional)" , async ( ) => {
253359 const writeFile = jest . fn ( ) ;
254360 const openAPIDocument : OpenAPIObject = {
0 commit comments