Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
useGetProps take only 2 generics (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 authored and mpotomin committed Apr 23, 2019
1 parent 217f0e3 commit a3751de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
11 changes: 10 additions & 1 deletion src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? `
Expand Down Expand Up @@ -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<Use${Component}Props<${genericsTypes}>, "path"${
output += `export type Use${componentName}Props = Omit<Use${Component}Props<${genericsTypesWithoutError}>, "path"${
verb === "get" ? "" : ` | "verb"`
}>${paramsInPath.length ? ` & {${paramsTypes}}` : ""};
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/tests/__snapshots__/import-open-api.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const FindPets = (props: FindPetsProps) => (
/>
);
export type UseFindPetsProps = Omit<UseGetProps<Pet[], Error, FindPetsQueryParams>, \\"path\\">;
export type UseFindPetsProps = Omit<UseGetProps<Pet[], FindPetsQueryParams>, \\"path\\">;
export const useFindPets = (props: UseFindPetsProps) => useGet<Pet[], Error, FindPetsQueryParams>(\`/pets\`, props);
Expand Down Expand Up @@ -54,7 +54,7 @@ export const FindPetById = ({id, ...props}: FindPetByIdProps) => (
/>
);
export type UseFindPetByIdProps = Omit<UseGetProps<Pet, Error, void>, \\"path\\"> & {id: number};
export type UseFindPetByIdProps = Omit<UseGetProps<Pet, void>, \\"path\\"> & {id: number};
export const useFindPetById = ({id, ...props}: UseFindPetByIdProps) => useGet<Pet, Error, void>(\`/pets/\${id}\`, props);
Expand Down
18 changes: 9 additions & 9 deletions src/scripts/tests/import-open-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ export const ListFields = (props: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, APIError, void>, \\"path\\">;
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, void>, \\"path\\">;
// List all fields for the use case schema
export const useListFields = (props: UseListFieldsProps) => useGet<FieldListResponse, APIError, void>(\`/fields\`, props);
Expand Down Expand Up @@ -550,7 +550,7 @@ export const ListFields = (props: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, unknown, void>, \\"path\\">;
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, void>, \\"path\\">;
// List all fields for the use case schema
export const useListFields = (props: UseListFieldsProps) => useGet<FieldListResponse, unknown, void>(\`/fields\`, props);
Expand Down Expand Up @@ -597,7 +597,7 @@ export const ListFields = (props: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, APIError, void>, \\"path\\">;
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, void>, \\"path\\">;
// List all fields for the use case schema
export const useListFields = (props: UseListFieldsProps) => useGet<FieldListResponse, APIError, void>(\`/fields\`, props);
Expand Down Expand Up @@ -661,7 +661,7 @@ export const ListFields = (props: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, APIError, ListFieldsQueryParams>, \\"path\\">;
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, ListFieldsQueryParams>, \\"path\\">;
// List all fields for the use case schema
export const useListFields = (props: UseListFieldsProps) => useGet<FieldListResponse, APIError, ListFieldsQueryParams>(\`/fields\`, props);
Expand Down Expand Up @@ -731,7 +731,7 @@ export const ListFields = (props: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, APIError, ListFieldsQueryParams>, \\"path\\">;
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, ListFieldsQueryParams>, \\"path\\">;
// List all fields for the use case schema
export const useListFields = (props: UseListFieldsProps) => useGet<FieldListResponse, APIError, ListFieldsQueryParams>(\`/fields\`, props);
Expand Down Expand Up @@ -794,7 +794,7 @@ export const ListFields = ({id, ...props}: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, APIError, void>, \\"path\\"> & {id: string};
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, void>, \\"path\\"> & {id: string};
// List all fields for the use case schema
export const useListFields = ({id, ...props}: UseListFieldsProps) => useGet<FieldListResponse, APIError, void>(\`/fields/\${id}\`, props);
Expand Down Expand Up @@ -864,7 +864,7 @@ export const ListFields = ({id, ...props}: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, APIError, void>, \\"path\\"> & {id: string};
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, void>, \\"path\\"> & {id: string};
// List all fields for the use case schema
export const useListFields = ({id, ...props}: UseListFieldsProps) => useGet<FieldListResponse, APIError, void>(\`/fields/\${id}\`, props);
Expand Down Expand Up @@ -1236,7 +1236,7 @@ export const ListFields = (props: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, APIError, void>, \\"path\\">;
export type UseListFieldsProps = Omit<UseGetProps<FieldListResponse, void>, \\"path\\">;
// List all fields for the use case schema
export const useListFields = (props: UseListFieldsProps) => useGet<FieldListResponse, APIError, void>(\`/fields\`, props);
Expand Down Expand Up @@ -1287,7 +1287,7 @@ export const ListFields = (props: ListFieldsProps) => (
/>
);
export type UseListFieldsProps = Omit<UseGetProps<void, APIError, void>, \\"path\\">;
export type UseListFieldsProps = Omit<UseGetProps<void, void>, \\"path\\">;
// List all fields for the use case schema
export const useListFields = (props: UseListFieldsProps) => useGet<void, APIError, void>(\`/fields\`, props);
Expand Down

0 comments on commit a3751de

Please sign in to comment.