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

Fix delete without id case #131

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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