Skip to content

Commit

Permalink
Test request body.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioggstream committed Nov 7, 2019
1 parent 23c75a1 commit 363856f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/__tests__/__snapshots__/gen-api-models.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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<A, O>(type: t.Type<A, O>) { 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`] = `
"
/****************************************************************
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/gen-api-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

});

0 comments on commit 363856f

Please sign in to comment.