Skip to content

Commit

Permalink
Add test for request body. Related to pagopa#141.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioggstream committed Nov 7, 2019
1 parent 92f572c commit 38e5aa1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/__tests__/__snapshots__/gen-api-models-oas3.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,23 @@ 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 problem?: 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_oas3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Problem"
/test-requestbody:
post:
operationId: "testRequestBody"
requestBody:
content:
application/json:
schema:
"$ref": "#/components/schemas/Problem"
responses:
"204":
description: No content
servers:
- url: https://localhost/api/v1
components:
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/gen-api-models-oas3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,24 @@ 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.components.parameters,
spec.components.securitySchemes,
[],
{},
"undefined",
"undefined",
true
);

expect(code.e1).toMatchSnapshot();
});

});

0 comments on commit 38e5aa1

Please sign in to comment.