diff --git a/src/createImports.mts b/src/createImports.mts index aa1b433..ac887ec 100644 --- a/src/createImports.mts +++ b/src/createImports.mts @@ -36,6 +36,26 @@ export const createImports = ({ const serviceNames = serviceExports; const imports = [ + ts.factory.createImportDeclaration( + undefined, + ts.factory.createImportClause( + false, + undefined, + ts.factory.createNamedImports([ + ts.factory.createImportSpecifier( + true, + undefined, + ts.factory.createIdentifier("Options"), + ), + ]), + ), + ts.factory.createStringLiteral( + client === "@hey-api/client-axios" + ? "@hey-api/client-axios" + : "@hey-api/client-fetch", + ), + undefined, + ), ts.factory.createImportDeclaration( undefined, ts.factory.createImportClause( diff --git a/tests/__snapshots__/createSource.test.ts.snap b/tests/__snapshots__/createSource.test.ts.snap index 88a3e5e..861fc50 100644 --- a/tests/__snapshots__/createSource.test.ts.snap +++ b/tests/__snapshots__/createSource.test.ts.snap @@ -11,6 +11,7 @@ export * from "./queries"; exports[`createSource > createSource - @hey-api/client-axios 2`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 +import { type Options } from "@hey-api/client-axios"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; @@ -47,6 +48,7 @@ exports[`createSource > createSource - @hey-api/client-axios 3`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; +import { type Options } from "@hey-api/client-axios"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; @@ -65,6 +67,7 @@ exports[`createSource > createSource - @hey-api/client-axios 4`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; +import { type Options } from "@hey-api/client-axios"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; @@ -80,6 +83,7 @@ exports[`createSource > createSource - @hey-api/client-axios 5`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; +import { type Options } from "@hey-api/client-axios"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; @@ -102,6 +106,7 @@ export * from "./queries"; exports[`createSource > createSource - @hey-api/client-fetch 2`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 +import { type Options } from "@hey-api/client-fetch"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; @@ -137,6 +142,7 @@ exports[`createSource > createSource - @hey-api/client-fetch 3`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; +import { type Options } from "@hey-api/client-fetch"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; @@ -154,6 +160,7 @@ exports[`createSource > createSource - @hey-api/client-fetch 4`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; +import { type Options } from "@hey-api/client-fetch"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; @@ -168,6 +175,7 @@ exports[`createSource > createSource - @hey-api/client-fetch 5`] = ` "// generated with @7nohe/openapi-react-query-codegen@1.0.0 import * as Common from "./common"; +import { type Options } from "@hey-api/client-fetch"; import { type QueryClient, useQuery, useSuspenseQuery, useMutation, UseQueryResult, UseQueryOptions, UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; import { client, findPets, addPet, getNotDefined, postNotDefined, findPetById, deletePet, findPaginatedPets } from "../requests/services.gen"; import { Pet, NewPet, Error, FindPetsData, FindPetsResponse, FindPetsError, AddPetData, AddPetResponse, AddPetError, GetNotDefinedResponse, GetNotDefinedError, PostNotDefinedResponse, PostNotDefinedError, FindPetByIdData, FindPetByIdResponse, FindPetByIdError, DeletePetData, DeletePetResponse, DeletePetError, FindPaginatedPetsData, FindPaginatedPetsResponse, FindPaginatedPetsError } from "../requests/types.gen"; diff --git a/tests/createImports.test.ts b/tests/createImports.test.ts index 80b39ef..7c6ee1f 100644 --- a/tests/createImports.test.ts +++ b/tests/createImports.test.ts @@ -20,6 +20,7 @@ describe(fileName, () => { // @ts-ignore const moduleNames = imports.map((i) => i.moduleSpecifier.text); expect(moduleNames).toStrictEqual([ + "@hey-api/client-fetch", "@tanstack/react-query", "../requests/services.gen", "../requests/types.gen", @@ -41,6 +42,7 @@ describe(fileName, () => { // @ts-ignore const moduleNames = imports.map((i) => i.moduleSpecifier.text); expect(moduleNames).toStrictEqual([ + "@hey-api/client-fetch", "@tanstack/react-query", "../requests/services.gen", "../requests/types.gen",