Skip to content
Draft
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
36 changes: 34 additions & 2 deletions src/__tests__/__snapshots__/gen-api-models-oas3.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ exports[`gen-api-models should generate the operator definition 1`] = `
*/

// Request type definition
export type TestAuthBearerT = r.IGetApiRequestType<{readonly bearerToken: string}, \\"Authorization\\", never, r.IResponseType<200, undefined>|r.IResponseType<403, undefined>>;
export type TestAuthBearerT = r.IGetApiRequestType<{readonly bearerToken: string,readonly qo?: string,readonly qr: string}, \\"Authorization\\", never, r.IResponseType<200, undefined>|r.IResponseType<403, undefined>>;

// Decodes the success response with a custom success type
export function testAuthBearerDecoder<A, O>(type: t.Type<A, O>) { return r.composeResponseDecoders(r.ioResponseDecoder<200, (typeof type)[\\"_A\\"], (typeof type)[\\"_O\\"]>(200, type), r.constantResponseDecoder<undefined, 403>(403, undefined)); }
Expand Down Expand Up @@ -500,11 +500,43 @@ exports[`gen-api-models should support file uploads 1`] = `
*/

// Request type definition
export type TestFileUploadT = r.IPostApiRequestType<{}, never, never, r.IResponseType<200, undefined>>;
export type TestFileUploadT = r.IPostApiRequestType<{readonly file: { uri: string, name: string, type: string }}, \\"Content-Type\\", never, r.IResponseType<200, undefined>>;

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

// 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);"
`;

exports[`gen-api-models should support generate serializers 1`] = `
"
/****************************************************************
* testSerializer
*/

// Request type definition
export type TestSerializerT = r.IPostApiRequestType<{readonly qo?: string,readonly paginationRequest?: 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);"
`;
32 changes: 32 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,35 @@ 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);"
`;

exports[`gen-api-models should support generate serializers 1`] = `
"
/****************************************************************
* testSerializer
*/

// Request type definition
export type TestSerializerT = r.IPostApiRequestType<{readonly qo?: string,readonly paginationRequest?: 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);"
`;
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
42 changes: 41 additions & 1 deletion src/__tests__/api_oas3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ paths:
post:
operationId: testFileUpload
requestBody:
required: true
content:
multipart/form-data:
schema:
Expand All @@ -42,6 +43,40 @@ paths:
responses:
"200":
description: File uploaded
/test-serializers:
post:
operationId: "testSerializer"
parameters:
- name: "qo"
in: "query"
required: false
schema:
type: "string"
- $ref: "#/components/parameters/PaginationRequest"
responses:
"200":
description: "File uploaded"
content:
application/json:
schema:
$ref: "#/components/schemas/Message"
"403":
description: "Error string"
content:
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 Expand Up @@ -79,6 +114,12 @@ components:
write: Grants write access
admin: Grants access to admin operations
schemas:
Problem:
properties:
title:
type: string
type:
type: string
AllOfTest:
allOf:
- type: object
Expand Down Expand Up @@ -264,4 +305,3 @@ components:
- is_email_set
- name
- version

41 changes: 40 additions & 1 deletion src/__tests__/gen-api-models-oas3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,26 @@ describe("gen-api-models", () => {
"post",
operation.operationId,
operation,
spec.parameters,
spec.components.parameters,
spec.components.securitySchemes,
[],
{},
"undefined",
"undefined",
true
);

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.components.parameters,
spec.components.securitySchemes,
[],
{},
Expand All @@ -284,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();
});

});
39 changes: 39 additions & 0 deletions src/__tests__/gen-api-models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,43 @@ 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();
});

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();
});

});
Loading