diff --git a/src/scripts/import-open-api.ts b/src/scripts/import-open-api.ts index 019fd5d8..dfae6947 100644 --- a/src/scripts/import-open-api.ts +++ b/src/scripts/import-open-api.ts @@ -320,6 +320,15 @@ export const generateRestfulComponent = ( queryParamsType ? componentName + "QueryParams" : "void" }, ${requestBodyTypes}`; + const genericsTypesWithoutError = + verb === "get" + ? `${needAResponseComponent ? componentName + "Response" : responseTypes}, ${ + queryParamsType ? componentName + "QueryParams" : "void" + }` + : `${needAResponseComponent ? componentName + "Response" : responseTypes}, ${ + queryParamsType ? componentName + "QueryParams" : "void" + }, ${requestBodyTypes}`; + let output = `${ needAResponseComponent ? ` @@ -358,7 +367,7 @@ export const ${componentName} = (${ // Hooks version if (verb === "get" /* TODO: Remove this condition after `useMutate` implementation */) { - output += `export type Use${componentName}Props = Omit, "path"${ + output += `export type Use${componentName}Props = Omit, "path"${ verb === "get" ? "" : ` | "verb"` }>${paramsInPath.length ? ` & {${paramsTypes}}` : ""}; diff --git a/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap b/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap index c437fc48..2ffe2bea 100644 --- a/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap +++ b/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap @@ -26,7 +26,7 @@ export const FindPets = (props: FindPetsProps) => ( /> ); -export type UseFindPetsProps = Omit, \\"path\\">; +export type UseFindPetsProps = Omit, \\"path\\">; export const useFindPets = (props: UseFindPetsProps) => useGet(\`/pets\`, props); @@ -54,7 +54,7 @@ export const FindPetById = ({id, ...props}: FindPetByIdProps) => ( /> ); -export type UseFindPetByIdProps = Omit, \\"path\\"> & {id: number}; +export type UseFindPetByIdProps = Omit, \\"path\\"> & {id: number}; export const useFindPetById = ({id, ...props}: UseFindPetByIdProps) => useGet(\`/pets/\${id}\`, props); diff --git a/src/scripts/tests/import-open-api.test.ts b/src/scripts/tests/import-open-api.test.ts index 79a92dc4..28514db6 100644 --- a/src/scripts/tests/import-open-api.test.ts +++ b/src/scripts/tests/import-open-api.test.ts @@ -516,7 +516,7 @@ export const ListFields = (props: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\">; +export type UseListFieldsProps = Omit, \\"path\\">; // List all fields for the use case schema export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); @@ -550,7 +550,7 @@ export const ListFields = (props: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\">; +export type UseListFieldsProps = Omit, \\"path\\">; // List all fields for the use case schema export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); @@ -597,7 +597,7 @@ export const ListFields = (props: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\">; +export type UseListFieldsProps = Omit, \\"path\\">; // List all fields for the use case schema export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); @@ -661,7 +661,7 @@ export const ListFields = (props: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\">; +export type UseListFieldsProps = Omit, \\"path\\">; // List all fields for the use case schema export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); @@ -731,7 +731,7 @@ export const ListFields = (props: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\">; +export type UseListFieldsProps = Omit, \\"path\\">; // List all fields for the use case schema export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); @@ -794,7 +794,7 @@ export const ListFields = ({id, ...props}: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\"> & {id: string}; +export type UseListFieldsProps = Omit, \\"path\\"> & {id: string}; // List all fields for the use case schema export const useListFields = ({id, ...props}: UseListFieldsProps) => useGet(\`/fields/\${id}\`, props); @@ -864,7 +864,7 @@ export const ListFields = ({id, ...props}: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\"> & {id: string}; +export type UseListFieldsProps = Omit, \\"path\\"> & {id: string}; // List all fields for the use case schema export const useListFields = ({id, ...props}: UseListFieldsProps) => useGet(\`/fields/\${id}\`, props); @@ -1236,7 +1236,7 @@ export const ListFields = (props: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\">; +export type UseListFieldsProps = Omit, \\"path\\">; // List all fields for the use case schema export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); @@ -1287,7 +1287,7 @@ export const ListFields = (props: ListFieldsProps) => ( /> ); -export type UseListFieldsProps = Omit, \\"path\\">; +export type UseListFieldsProps = Omit, \\"path\\">; // List all fields for the use case schema export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props);