Skip to content

Commit

Permalink
Fix: pagopa#141. Test request body with swagger2.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioggstream committed Nov 7, 2019
1 parent 8c6e05b commit f4a5f83
Show file tree
Hide file tree
Showing 3 changed files with 72 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 @@ -508,3 +508,19 @@ exports[`gen-api-models should support file uploads 1`] = `
// Decodes the success response with the type defined in the specs
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);"
`;
35 changes: 35 additions & 0 deletions src/__tests__/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,42 @@ paths:
responses:
"200":
description: "File uploaded"
/test-serializers:
post:
operationId: "testSerializer"
parameters:
- name: "qo"
in: "query"
required: false
type: "string"
- $ref: "#/parameters/PaginationRequest"
responses:
"200":
description: "File uploaded"
schema:
$ref: "#/definitions/Message"
"403":
description: "Error string"
schema:
$ref: "#/definitions/Problem"
/test-requestbody:
post:
operationId: "testRequestBody"
parameters:
- in: body
name: body
schema:
"$ref": "#/definitions/Problem"
responses:
"204":
description: No content
definitions:
Problem:
properties:
title:
type: string
type:
type: string
AllOfTest:
allOf:
- type: object
Expand Down
21 changes: 21 additions & 0 deletions src/__tests__/gen-api-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,25 @@ 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 f4a5f83

Please sign in to comment.