Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #141. Test request body with swagger2. #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});

});