Skip to content
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 serializers 1`] = `
"
/****************************************************************
* testSerializer
*/

// Request type definition
export type TestSerializerT = r.IPostApiRequestType<{readonly qo?: string}, \\"Content-Type\\", never, r.IResponseType<200, Message>|r.IResponseType<403, Problem>>;

// Decodes the success response with a custom success type
export function testSerializerDecoder<A, O>(type: t.Type<A, O>) { return r.composeResponseDecoders(r.ioResponseDecoder<200, (typeof type)[\\"_A\\"], (typeof type)[\\"_O\\"]>(200, type), r.ioResponseDecoder<403, (typeof Problem)[\\"_A\\"], (typeof Problem)[\\"_O\\"]>(403, Problem)); }

// Decodes the success response with the type defined in the specs
export const testSerializerDefaultDecoder = () => testSerializerDecoder(Message);"
`;
23 changes: 23 additions & 0 deletions src/__tests__/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,30 @@ paths:
responses:
"200":
description: "File uploaded"
/test-serializers:
post:
operationId: "testSerializer"
parameters:
- name: "qo"
in: "query"
required: false
type: "string"
responses:
"200":
description: "File uploaded"
schema:
$ref: "#/definitions/Message"
"403":
description: "Error string"
schema:
$ref: "#/definitions/Problem"
definitions:
Problem:
properties:
title:
type: string
type:
type: string
AllOfTest:
allOf:
- type: object
Expand Down
20 changes: 20 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,24 @@ describe("gen-api-models", () => {

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

it("should support generate serializers", async () => {
const operation = spec.paths["/test-serializers"].post;

const code = await renderOperation(
"post",
operation.operationId,
operation,
spec.parameters,
spec.securityDefinitions,
[],
{},
"undefined",
"undefined",
true
);

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

});