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

Commit

Permalink
Merge pull request #131 from contiamo/fix-delete-without-id
Browse files Browse the repository at this point in the history
Fix delete without id case
  • Loading branch information
Tejas Kumar authored Jun 12, 2019
2 parents cc04b07 + c689d0e commit 25f6e62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/scripts/import-open-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const generateRestfulComponent = (
route = route.replace(/\{/g, "${"); // `/pet/{id}` => `/pet/${id}`

// Remove the last param of the route if we are in the DELETE case
let lastParamInTheRoute: string;
let lastParamInTheRoute: string | null = null;
if (verb === "delete") {
const lastParamInTheRouteRegExp = /\/\$\{(\w+)\}$/;
lastParamInTheRoute = (route.match(lastParamInTheRouteRegExp) || [])[1];
Expand Down Expand Up @@ -324,7 +324,7 @@ export const generateRestfulComponent = (
}`
: `${needAResponseComponent ? componentName + "Response" : responseTypes}, ${errorTypes}, ${
queryParamsType ? componentName + "QueryParams" : "void"
}, ${verb === "delete" ? "string" : requestBodyTypes}`;
}, ${verb === "delete" && lastParamInTheRoute ? "string" : requestBodyTypes}`;

const genericsTypesForHooksProps =
verb === "get"
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/tests/import-open-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,11 +1238,11 @@ export interface JobRunResponse {}

expect(generateRestfulComponent(operation, "delete", "/use-cases/{useCaseId}/secret", [])).toMatchInlineSnapshot(`
"
export type DeleteUseCaseProps = Omit<MutateProps<void, APIError, void, string>, \\"path\\" | \\"verb\\"> & {useCaseId: string};
export type DeleteUseCaseProps = Omit<MutateProps<void, APIError, void, void>, \\"path\\" | \\"verb\\"> & {useCaseId: string};
// Delete use case
export const DeleteUseCase = ({useCaseId, ...props}: DeleteUseCaseProps) => (
<Mutate<void, APIError, void, string>
<Mutate<void, APIError, void, void>
verb=\\"DELETE\\"
path={\`/use-cases/\${useCaseId}/secret\`}
{...props}
Expand All @@ -1252,7 +1252,7 @@ export interface JobRunResponse {}
export type UseDeleteUseCaseProps = Omit<UseMutateProps<void, void>, \\"path\\" | \\"verb\\"> & {useCaseId: string};
// Delete use case
export const useDeleteUseCase = ({useCaseId, ...props}: UseDeleteUseCaseProps) => useMutate<void, APIError, void, string>(\\"DELETE\\", \`/use-cases/\${useCaseId}/secret\`, props);
export const useDeleteUseCase = ({useCaseId, ...props}: UseDeleteUseCaseProps) => useMutate<void, APIError, void, void>(\\"DELETE\\", \`/use-cases/\${useCaseId}/secret\`, props);
"
`);
Expand Down

0 comments on commit 25f6e62

Please sign in to comment.