From 363856fa3f1d3869741d72f7c23e35459322ce28 Mon Sep 17 00:00:00 2001 From: Roberto Polli Date: Thu, 7 Nov 2019 17:27:41 +0100 Subject: [PATCH] Test request body. --- .../__snapshots__/gen-api-models.test.ts.snap | 16 ++++++++++++++++ src/__tests__/api.yaml | 11 +++++++++++ src/__tests__/gen-api-models.test.ts | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/__tests__/__snapshots__/gen-api-models.test.ts.snap b/src/__tests__/__snapshots__/gen-api-models.test.ts.snap index 815dc1cd..629ee252 100644 --- a/src/__tests__/__snapshots__/gen-api-models.test.ts.snap +++ b/src/__tests__/__snapshots__/gen-api-models.test.ts.snap @@ -509,6 +509,22 @@ exports[`gen-api-models should support file uploads 1`] = ` export const testFileUploadDefaultDecoder = () => testFileUploadDecoder(t.undefined);" `; +exports[`gen-api-models should support generate requestbody 1`] = ` +" + /**************************************************************** + * testRequestBody + */ + + // Request type definition + export type TestRequestBodyT = r.IPostApiRequestType<{readonly body?: #/definitions/Problem}, \\"Content-Type\\", never, r.IResponseType<204, undefined>>; + + // Decodes the success response with a custom success type + export function testRequestBodyDecoder(type: t.Type) { return r.ioResponseDecoder<204, (typeof type)[\\"_A\\"], (typeof type)[\\"_O\\"]>(204, type); } + + // Decodes the success response with the type defined in the specs + export const testRequestBodyDefaultDecoder = () => testRequestBodyDecoder(t.undefined);" +`; + exports[`gen-api-models should support generate serializers 1`] = ` " /**************************************************************** diff --git a/src/__tests__/api.yaml b/src/__tests__/api.yaml index 6bcf4553..6d560753 100644 --- a/src/__tests__/api.yaml +++ b/src/__tests__/api.yaml @@ -63,6 +63,17 @@ paths: description: "Error string" schema: $ref: "#/definitions/Problem" + /test-requestbody: + post: + operationId: "testRequestBody" + parameters: + - in: body + name: body + schema: + type: "#/definitions/Problem" + responses: + "204": + description: No content definitions: Problem: properties: diff --git a/src/__tests__/gen-api-models.test.ts b/src/__tests__/gen-api-models.test.ts index 4d7edeb3..a1fc0d74 100644 --- a/src/__tests__/gen-api-models.test.ts +++ b/src/__tests__/gen-api-models.test.ts @@ -304,4 +304,23 @@ describe("gen-api-models", () => { expect(code.e1).toMatchSnapshot(); }); + it("should support generate requestbody", async () => { + const operation = spec.paths["/test-requestbody"].post; + + const code = await renderOperation( + "post", + operation.operationId, + operation, + spec.parameters, + spec.securityDefinitions, + [], + {}, + "undefined", + "undefined", + true + ); + + expect(code.e1).toMatchSnapshot(); + }); + });