From 25f9686860a272d6b95446e1dd8d54140282833c Mon Sep 17 00:00:00 2001 From: Fabien BERNARD Date: Sun, 15 Dec 2019 11:38:21 +0100 Subject: [PATCH] Add documentation on hooks version --- src/scripts/import-open-api.ts | 7 +- .../import-open-api.test.ts.snap | 20 +- src/scripts/tests/import-open-api.test.ts | 900 +++++++++--------- 3 files changed, 487 insertions(+), 440 deletions(-) diff --git a/src/scripts/import-open-api.ts b/src/scripts/import-open-api.ts index 732cd79c..c90b46f6 100644 --- a/src/scripts/import-open-api.ts +++ b/src/scripts/import-open-api.ts @@ -409,8 +409,11 @@ ${formatDescription( verb === "get" ? "" : ` | "verb"` }>${paramsInPath.length ? ` & {${paramsTypes}}` : ""}; -${operation.summary ? "// " + operation.summary : ""} -export const use${componentName} = (${ +${formatDescription( + operation.summary && operation.description + ? `${operation.summary}\n\n${operation.description}` + : `${operation.summary || ""}${operation.description || ""}`, +)}export const use${componentName} = (${ paramsInPath.length ? `{${paramsInPath.join(", ")}, ...props}` : "props" }: Use${componentName}Props) => use${Component}<${genericsTypes}>(${ verb === "get" ? "" : `"${verb.toUpperCase()}", ` 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 aa555204..3422333c 100644 --- a/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap +++ b/src/scripts/tests/__snapshots__/import-open-api.test.ts.snap @@ -54,7 +54,13 @@ export const FindPets = (props: FindPetsProps) => ( export type UseFindPetsProps = Omit, \\"path\\">; - +/** + * Returns all pets from the system that the user has access to + * Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. + * + * Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. + * + */ export const useFindPets = (props: UseFindPetsProps) => useGet(\`/pets\`, props); @@ -73,7 +79,9 @@ export const AddPet = (props: AddPetProps) => ( export type UseAddPetProps = Omit, \\"path\\" | \\"verb\\">; - +/** + * Creates a new pet in the store. Duplicates are allowed + */ export const useAddPet = (props: UseAddPetProps) => useMutate(\\"POST\\", \`/pets\`, props); @@ -91,7 +99,9 @@ export const FindPetById = ({id, ...props}: FindPetByIdProps) => ( export type UseFindPetByIdProps = Omit, \\"path\\"> & {id: number}; - +/** + * Returns a user based on a single ID, if the user does not have access to the pet + */ export const useFindPetById = ({id, ...props}: UseFindPetByIdProps) => useGet(\`/pets/\${id}\`, props); @@ -110,7 +120,9 @@ export const DeletePet = (props: DeletePetProps) => ( export type UseDeletePetProps = Omit, \\"path\\" | \\"verb\\">; - +/** + * deletes a single pet based on the ID supplied + */ 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 e8f750ee..eebd8ccb 100644 --- a/src/scripts/tests/import-open-api.test.ts +++ b/src/scripts/tests/import-open-api.test.ts @@ -182,11 +182,11 @@ describe("scripts/import-open-api", () => { }, }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - name: string; - age: number; - }" - `); + "{ + name: string; + age: number; + }" + `); }); it("should return the type of an object with optional values", () => { @@ -203,11 +203,11 @@ describe("scripts/import-open-api", () => { }, }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - name: string; - age?: number; - }" - `); + "{ + name: string; + age?: number; + }" + `); }); it("should deal with additionalProperties", () => { @@ -218,10 +218,10 @@ describe("scripts/import-open-api", () => { }, }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - [key: string]: string; - }" - `); + "{ + [key: string]: string; + }" + `); }); it("should deal with ref additionalProperties", () => { @@ -232,10 +232,10 @@ describe("scripts/import-open-api", () => { }, }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - [key: string]: Foo; - }" - `); + "{ + [key: string]: Foo; + }" + `); }); it("should deal with true as additionalProperties", () => { @@ -244,10 +244,10 @@ describe("scripts/import-open-api", () => { additionalProperties: true, }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - [key: string]: any; - }" - `); + "{ + [key: string]: any; + }" + `); }); it("should deal with ref additionalProperties", () => { @@ -258,10 +258,10 @@ describe("scripts/import-open-api", () => { }, }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - [key: string]: Foo; - }" - `); + "{ + [key: string]: Foo; + }" + `); }); it("should deal with oneOf additionalProperties", () => { @@ -272,10 +272,10 @@ describe("scripts/import-open-api", () => { }, }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - [key: string]: Foo | Bar; - }" - `); + "{ + [key: string]: Foo | Bar; + }" + `); }); it("should deal with array as additionalProperties", () => { @@ -290,10 +290,10 @@ describe("scripts/import-open-api", () => { }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - [key: string]: string[]; - }" - `); + "{ + [key: string]: string[]; + }" + `); }); it("should deal with additionalProperties on top of define properties", () => { @@ -308,11 +308,11 @@ describe("scripts/import-open-api", () => { }; expect(getObject(item)).toMatchInlineSnapshot(` - "{ - name?: string; - [key: string]: any; - }" - `); + "{ + name?: string; + [key: string]: any; + }" + `); }); it("should deal with allOf", () => { @@ -330,10 +330,10 @@ describe("scripts/import-open-api", () => { ], }; expect(getObject(item)).toMatchInlineSnapshot(` - "Foo & { - name: string; - }" - `); + "Foo & { + name: string; + }" + `); }); }); @@ -446,12 +446,12 @@ describe("scripts/import-open-api", () => { }, }; expect(generateSchemasDefinition(schema)).toMatchInlineSnapshot(` - "export interface NewPet { - name: string; - tag?: string; - } - " - `); + "export interface NewPet { + name: string; + tag?: string; + } + " + `); }); it("should declare an interface for simple object (nullable)", () => { @@ -470,12 +470,12 @@ describe("scripts/import-open-api", () => { }, }; expect(generateSchemasDefinition(schema)).toMatchInlineSnapshot(` - "export type NewPet = { - name: string; - tag?: string; - } | null; - " - `); + "export type NewPet = { + name: string; + tag?: string; + } | null; + " + `); }); it("should declare a type for union object", () => { @@ -488,11 +488,11 @@ describe("scripts/import-open-api", () => { }, }; expect(generateSchemasDefinition(schema)).toMatchInlineSnapshot(` - "export type Pet = NewPet & { - id: number; - }; - " - `); + "export type Pet = NewPet & { + id: number; + }; + " + `); }); it("should declare a discriminate object", () => { @@ -505,11 +505,11 @@ describe("scripts/import-open-api", () => { }, }; expect(generateSchemasDefinition(schema)).toMatchInlineSnapshot(` - "export type Pet = NewPet | { - id: number; - }; - " - `); + "export type Pet = NewPet | { + id: number; + }; + " + `); }); it("should declare a type for all others types", () => { @@ -566,18 +566,18 @@ describe("scripts/import-open-api", () => { }; expect(generateResponsesDefinition(responses)).toMatchInlineSnapshot(` - " - /** - * Job is starting - */ - export interface JobRunResponse { - /** - * ID of the job execution - */ - executionID?: string; - } - " - `); + " + /** + * Job is starting + */ + export interface JobRunResponse { + /** + * ID of the job execution + */ + executionID?: string; + } + " + `); }); it("should give double quotes for special properties", () => { @@ -601,18 +601,18 @@ describe("scripts/import-open-api", () => { }; expect(generateResponsesDefinition(responses)).toMatchInlineSnapshot(` - " - /** - * Job is starting - */ - export interface JobRunResponse { - /** - * ID of the job execution - */ - \\"execution-id\\"?: string; - } - " - `); + " + /** + * Job is starting + */ + export interface JobRunResponse { + /** + * ID of the job execution + */ + \\"execution-id\\"?: string; + } + " + `); }); it("should declare a a type for composed object", () => { @@ -641,18 +641,18 @@ describe("scripts/import-open-api", () => { }; expect(generateResponsesDefinition(responses)).toMatchInlineSnapshot(` - " - /** - * Job is starting - */ - export type JobRunResponse = { - /** - * ID of the job execution - */ - executionID?: string; - } & ExecutionID; - " - `); + " + /** + * Job is starting + */ + export type JobRunResponse = { + /** + * ID of the job execution + */ + executionID?: string; + } & ExecutionID; + " + `); }); it("should declare a a type for union object", () => { @@ -681,18 +681,18 @@ describe("scripts/import-open-api", () => { }; expect(generateResponsesDefinition(responses)).toMatchInlineSnapshot(` - " - /** - * Job is starting - */ - export type JobRunResponse = { - /** - * ID of the job execution - */ - executionID?: string; - } | ExecutionID; - " - `); + " + /** + * Job is starting + */ + export type JobRunResponse = { + /** + * ID of the job execution + */ + executionID?: string; + } | ExecutionID; + " + `); }); }); @@ -748,10 +748,10 @@ describe("scripts/import-open-api", () => { ]; expect(getResReqTypes(responses)).toMatchInlineSnapshot(` - "FieldListResponse | { - id: string; - }" - `); + "FieldListResponse | { + id: string; + }" + `); }); it("should not generate type duplication", () => { @@ -800,26 +800,28 @@ describe("scripts/import-open-api", () => { }; 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 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); + + " + `); }); it("should have a nice documentation with summary and description", () => { @@ -837,28 +839,32 @@ describe("scripts/import-open-api", () => { }; expect(generateRestfulComponent(operation, "get", "/fields", [])).toMatchInlineSnapshot(` - " - export type ListFieldsProps = Omit, \\"path\\">; - - /** - * List all fields for the use case schema - * - * This is a longer description to describe my endpoint - */ - 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 ListFieldsProps = Omit, \\"path\\">; + + /** + * List all fields for the use case schema + * + * This is a longer description to describe my endpoint + */ + export const ListFields = (props: ListFieldsProps) => ( + + path={\`/fields\`} + {...props} + /> + ); + + export type UseListFieldsProps = Omit, \\"path\\">; + + /** + * List all fields for the use case schema + * + * This is a longer description to describe my endpoint + */ + export const useListFields = (props: UseListFieldsProps) => useGet(\`/fields\`, props); - " - `); + " + `); }); it("should add a fallback if the error is not defined", () => { @@ -875,26 +881,28 @@ describe("scripts/import-open-api", () => { }; 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 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); + + " + `); }); it("should remove duplicate types", () => { @@ -924,26 +932,28 @@ describe("scripts/import-open-api", () => { }; 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 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); + + " + `); }); it("should deal with parameters in query", () => { @@ -988,28 +998,30 @@ describe("scripts/import-open-api", () => { }; 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 = { @@ -1060,28 +1072,30 @@ describe("scripts/import-open-api", () => { ], ), ).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", () => { @@ -1127,26 +1141,28 @@ describe("scripts/import-open-api", () => { }; expect(generateRestfulComponent(operation, "get", "/fields/{id}", [])).toMatchInlineSnapshot(` - " - 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} - /> - ); - - 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); - - " - `); + " + 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} + /> + ); + + 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); + + " + `); }); it("should deal with parameters in path (root level)", () => { @@ -1199,26 +1215,28 @@ describe("scripts/import-open-api", () => { ], ), ).toMatchInlineSnapshot(` - " - 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} - /> - ); - - 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); - - " - `); + " + 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} + /> + ); + + 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); + + " + `); }); it("should generate a Mutate type component", () => { @@ -1264,27 +1282,29 @@ describe("scripts/import-open-api", () => { }; expect(generateRestfulComponent(operation, "put", "/use-cases/{useCaseId}", [])).toMatchInlineSnapshot(` - " - export type UpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - /** - * Update use case details - */ - export const UpdateUseCase = ({useCaseId, ...props}: UpdateUseCaseProps) => ( - - verb=\\"PUT\\" - path={\`/use-cases/\${useCaseId}\`} - {...props} - /> - ); - - export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - // Update use case details - export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); - - " - `); + " + export type UpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Update use case details + */ + export const UpdateUseCase = ({useCaseId, ...props}: UpdateUseCaseProps) => ( + + verb=\\"PUT\\" + path={\`/use-cases/\${useCaseId}\`} + {...props} + /> + ); + + export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Update use case details + */ + export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); + + " + `); }); it("should generate a proper ComponentResponse type if the type is custom", () => { const operation: OperationObject = { @@ -1344,32 +1364,34 @@ describe("scripts/import-open-api", () => { }; expect(generateRestfulComponent(operation, "put", "/use-cases/{useCaseId}", [])).toMatchInlineSnapshot(` - " - export interface UpdateUseCaseResponse { - id: string; - name?: string; - } - - export type UpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - /** - * Update use case details - */ - export const UpdateUseCase = ({useCaseId, ...props}: UpdateUseCaseProps) => ( - - verb=\\"PUT\\" - path={\`/use-cases/\${useCaseId}\`} - {...props} - /> - ); - - export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - // Update use case details - export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); - - " - `); + " + export interface UpdateUseCaseResponse { + id: string; + name?: string; + } + + export type UpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Update use case details + */ + export const UpdateUseCase = ({useCaseId, ...props}: UpdateUseCaseProps) => ( + + verb=\\"PUT\\" + path={\`/use-cases/\${useCaseId}\`} + {...props} + /> + ); + + export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Update use case details + */ + export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); + + " + `); }); it("should ignore 3xx responses", () => { @@ -1433,32 +1455,34 @@ describe("scripts/import-open-api", () => { }; expect(generateRestfulComponent(operation, "put", "/use-cases/{useCaseId}", [])).toMatchInlineSnapshot(` - " - export interface UpdateUseCaseResponse { - id: string; - name?: string; - } - - export type UpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - /** - * Update use case details - */ - export const UpdateUseCase = ({useCaseId, ...props}: UpdateUseCaseProps) => ( - - verb=\\"PUT\\" - path={\`/use-cases/\${useCaseId}\`} - {...props} - /> - ); - - export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - // Update use case details - export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); - - " - `); + " + export interface UpdateUseCaseResponse { + id: string; + name?: string; + } + + export type UpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Update use case details + */ + export const UpdateUseCase = ({useCaseId, ...props}: UpdateUseCaseProps) => ( + + verb=\\"PUT\\" + path={\`/use-cases/\${useCaseId}\`} + {...props} + /> + ); + + export type UseUpdateUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Update use case details + */ + export const useUpdateUseCase = ({useCaseId, ...props}: UseUpdateUseCaseProps) => useMutate(\\"PUT\\", \`/use-cases/\${useCaseId}\`, props); + + " + `); }); it("should ignore the last param of a delete call (the id is give after)", () => { @@ -1499,27 +1523,29 @@ describe("scripts/import-open-api", () => { }; expect(generateRestfulComponent(operation, "delete", "/use-cases/{useCaseId}", [])).toMatchInlineSnapshot(` - " - export type DeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\">; - - /** - * Delete use case - */ - export const DeleteUseCase = (props: DeleteUseCaseProps) => ( - - verb=\\"DELETE\\" - path={\`/use-cases\`} - {...props} - /> - ); - - export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\">; - - // Delete use case - export const useDeleteUseCase = (props: UseDeleteUseCaseProps) => useMutate(\\"DELETE\\", \`/use-cases\`, props); - - " - `); + " + export type DeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\">; + + /** + * Delete use case + */ + export const DeleteUseCase = (props: DeleteUseCaseProps) => ( + + verb=\\"DELETE\\" + path={\`/use-cases\`} + {...props} + /> + ); + + export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\">; + + /** + * Delete use case + */ + export const useDeleteUseCase = (props: UseDeleteUseCaseProps) => useMutate(\\"DELETE\\", \`/use-cases\`, props); + + " + `); }); it("should only remove the last params in delete operation", () => { const operation: OperationObject = { @@ -1559,27 +1585,29 @@ describe("scripts/import-open-api", () => { }; expect(generateRestfulComponent(operation, "delete", "/use-cases/{useCaseId}/secret", [])).toMatchInlineSnapshot(` - " - export type DeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - /** - * Delete use case - */ - export const DeleteUseCase = ({useCaseId, ...props}: DeleteUseCaseProps) => ( - - verb=\\"DELETE\\" - path={\`/use-cases/\${useCaseId}/secret\`} - {...props} - /> - ); - - export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; - - // Delete use case - export const useDeleteUseCase = ({useCaseId, ...props}: UseDeleteUseCaseProps) => useMutate(\\"DELETE\\", \`/use-cases/\${useCaseId}/secret\`, props); - - " - `); + " + export type DeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Delete use case + */ + export const DeleteUseCase = ({useCaseId, ...props}: DeleteUseCaseProps) => ( + + verb=\\"DELETE\\" + path={\`/use-cases/\${useCaseId}/secret\`} + {...props} + /> + ); + + export type UseDeleteUseCaseProps = Omit, \\"path\\" | \\"verb\\"> & {useCaseId: string}; + + /** + * Delete use case + */ + export const useDeleteUseCase = ({useCaseId, ...props}: UseDeleteUseCaseProps) => useMutate(\\"DELETE\\", \`/use-cases/\${useCaseId}/secret\`, props); + + " + `); }); it("should generate a Poll compoment if the `prefer` token is present", () => { @@ -1614,36 +1642,38 @@ describe("scripts/import-open-api", () => { }; 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", () => { @@ -1667,26 +1697,28 @@ describe("scripts/import-open-api", () => { }; 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 ListFieldsProps = Omit, \\"path\\">; + + /** + * 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); - " - `); + " + `); }); describe("reactPropsValueToObjectValue", () => {