From a972ca898bf64aa69272601521a497ddc164b338 Mon Sep 17 00:00:00 2001 From: Fabien BERNARD Date: Tue, 30 Jul 2019 11:42:14 +0200 Subject: [PATCH] Fix useMutate with delete generation --- src/scripts/import-open-api.ts | 2 +- .../import-open-api.test.ts.snap | 4 +- src/scripts/tests/import-open-api.test.ts | 294 +++++++++--------- 3 files changed, 150 insertions(+), 150 deletions(-) diff --git a/src/scripts/import-open-api.ts b/src/scripts/import-open-api.ts index b2f1913f..7888fe88 100644 --- a/src/scripts/import-open-api.ts +++ b/src/scripts/import-open-api.ts @@ -333,7 +333,7 @@ export const generateRestfulComponent = ( }` : `${needAResponseComponent ? componentName + "Response" : responseTypes}, ${ queryParamsType ? componentName + "QueryParams" : "void" - }, ${requestBodyTypes}`; + }, ${verb === "delete" && lastParamInTheRoute ? "string" : requestBodyTypes}`; let output = `${ needAResponseComponent 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 6e3d4f95..d6d6d1bd 100644 --- a/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap +++ b/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap @@ -43,7 +43,7 @@ export const AddPet = (props: AddPetProps) => ( /> ); -export type UseAddPetProps = Omit, \\"path\\" | \\"verb\\">; +export type UseAddPetProps = Omit, \\"path\\" | \\"verb\\">; export const useAddPet = (props: UseAddPetProps) => useMutate(\\"POST\\", \`/pets\`, props); @@ -76,7 +76,7 @@ export const DeletePet = (props: DeletePetProps) => ( /> ); -export type UseDeletePetProps = Omit, \\"path\\" | \\"verb\\">; +export type UseDeletePetProps = Omit, \\"path\\" | \\"verb\\">; export const useDeletePet = (props: UseDeletePetProps) => useMutate(\\"DELETE\\", \`/pets\`, props); diff --git a/src/scripts/tests/import-open-api.test.ts b/src/scripts/tests/import-open-api.test.ts index ee91da05..8eb85594 100644 --- a/src/scripts/tests/import-open-api.test.ts +++ b/src/scripts/tests/import-open-api.test.ts @@ -545,24 +545,24 @@ export interface JobRunResponse {} }; expect(generateRestfulComponent(operation, "get", "/fields", [])).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\">; + " + export type ListFieldsProps = Omit, \\"path\\">; - // List all fields for the use case schema - export const ListFields = (props: ListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - " - `); + " + `); }); it("should add a fallback if the error is not defined", () => { @@ -579,24 +579,24 @@ export interface JobRunResponse {} }; expect(generateRestfulComponent(operation, "get", "/fields", [])).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\">; + " + export type ListFieldsProps = Omit, \\"path\\">; - // List all fields for the use case schema - export const ListFields = (props: ListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - " - `); + " + `); }); it("should remove duplicate types", () => { @@ -626,24 +626,24 @@ export interface JobRunResponse {} }; expect(generateRestfulComponent(operation, "get", "/fields", [])).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\">; + " + export type ListFieldsProps = Omit, \\"path\\">; - // List all fields for the use case schema - export const ListFields = (props: ListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - " - `); + " + `); }); it("should deal with parameters in query", () => { @@ -688,26 +688,26 @@ export interface JobRunResponse {} }; expect(generateRestfulComponent(operation, "get", "/fields", [])).toMatchInlineSnapshot(` - " - export interface ListFieldsQueryParams {tenantId: string; projectId?: string} + " + export interface ListFieldsQueryParams {tenantId: string; projectId?: string} - export type ListFieldsProps = Omit, \\"path\\">; + export type ListFieldsProps = Omit, \\"path\\">; - // List all fields for the use case schema - export const ListFields = (props: ListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - " - `); + " + `); }); it("should deal with parameters in query (root level)", () => { const operation: OperationObject = { @@ -758,26 +758,26 @@ export interface JobRunResponse {} ], ), ).toMatchInlineSnapshot(` - " - export interface ListFieldsQueryParams {tenantId: string; projectId?: string} + " + export interface ListFieldsQueryParams {tenantId: string; projectId?: string} - export type ListFieldsProps = Omit, \\"path\\">; + export type ListFieldsProps = Omit, \\"path\\">; - // List all fields for the use case schema - export const ListFields = (props: ListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - " - `); + " + `); }); it("should deal with parameters in path", () => { @@ -823,24 +823,24 @@ export interface JobRunResponse {} }; expect(generateRestfulComponent(operation, "get", "/fields/{id}", [])).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\"> & {id: string}; + " + export type ListFieldsProps = Omit, \\"path\\"> & {id: string}; - // List all fields for the use case schema - export const ListFields = ({id, ...props}: ListFieldsProps) => ( - - path={\`/fields/\${id}\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = ({id, ...props}: ListFieldsProps) => ( + + path={\`/fields/\${id}\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = ({id, ...props}: UseListFieldsProps) => useGet(\`/fields/\${id}\`, props); - " - `); + " + `); }); it("should deal with parameters in path (root level)", () => { @@ -893,24 +893,24 @@ export interface JobRunResponse {} ], ), ).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\"> & {id: string}; + " + export type ListFieldsProps = Omit, \\"path\\"> & {id: string}; - // List all fields for the use case schema - export const ListFields = ({id, ...props}: ListFieldsProps) => ( - - path={\`/fields/\${id}\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = ({id, ...props}: ListFieldsProps) => ( + + path={\`/fields/\${id}\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = ({id, ...props}: UseListFieldsProps) => useGet(\`/fields/\${id}\`, props); - " - `); + " + `); }); it("should generate a Mutate type component", () => { @@ -968,7 +968,7 @@ export interface JobRunResponse {} /> ); - export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; // Update use case details export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); @@ -1048,7 +1048,7 @@ export interface JobRunResponse {} /> ); - export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; // Update use case details export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); @@ -1132,7 +1132,7 @@ export interface JobRunResponse {} /> ); - export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; // Update use case details export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); @@ -1191,7 +1191,7 @@ export interface JobRunResponse {} /> ); - export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\">; + export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\">; // Delete use case export const useDeleteUseCase = (props: UseDeleteUseCaseProps) => useMutate(\\"DELETE\\", \`/use-cases\`, props); @@ -1249,7 +1249,7 @@ export interface JobRunResponse {} /> ); - export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; // Delete use case export const useDeleteUseCase = ({useCaseId, ...props}: UseDeleteUseCaseProps) => useMutate(\\"DELETE\\", \`/use-cases/\${useCaseId}/secret\`, props); @@ -1290,34 +1290,34 @@ export interface JobRunResponse {} }; expect(generateRestfulComponent(operation, "get", "/fields", [])).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\">; - - // List all fields for the use case schema - export const ListFields = (props: ListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); - - export type UseListFieldsProps = Omit, \\"path\\">; - - // List all fields for the use case schema - export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - - export type PollListFieldsProps = Omit, \\"path\\">; - - // List all fields for the use case schema (long polling) - export const PollListFields = (props: PollListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); - - " - `); + " + export type ListFieldsProps = Omit, \\"path\\">; + + // List all fields for the use case schema + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); + + export type UseListFieldsProps = Omit, \\"path\\">; + + // List all fields for the use case schema + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); + + export type PollListFieldsProps = Omit, \\"path\\">; + + // List all fields for the use case schema (long polling) + export const PollListFields = (props: PollListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); + + " + `); }); }); it("should deal with no 2xx response case", () => { @@ -1341,23 +1341,23 @@ export interface JobRunResponse {} }; expect(generateRestfulComponent(operation, "get", "/fields", [])).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\">; + " + export type ListFieldsProps = Omit, \\"path\\">; - // List all fields for the use case schema - export const ListFields = (props: ListFieldsProps) => ( - - path={\`/fields\`} - {...props} - /> - ); + // List all fields for the use case schema + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); - 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); + // List all fields for the use case schema + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - " - `); + " + `); }); });