Skip to content

Commit 7ad9526

Browse files
author
Ansh Chaturvedi
committed
feat: add support for comments from declarations
Ticket: DX-494
1 parent 07f8ebe commit 7ad9526

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

packages/openapi-generator/src/cli.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const app = command({
177177
);
178178
process.exit(1);
179179
}
180-
const [newSourceFile, init] = initE.right;
180+
const [newSourceFile, init, comment] = initE.right;
181181

182182
const codecE = parseCodecInitializer(project.right, newSourceFile, init);
183183
if (E.isLeft(codecE)) {
@@ -186,6 +186,10 @@ const app = command({
186186
);
187187
process.exit(1);
188188
}
189+
if (comment !== undefined) {
190+
codecE.right.comment = comment;
191+
}
192+
189193
components[ref.name] = codecE.right;
190194
queue.push(codecE.right);
191195
}

packages/openapi-generator/test/openapi.test.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,91 @@ testCase('request body ref', SCHEMA_REF, {
669669
},
670670
});
671671

672+
const SCHEMA_REF_WITH_COMMENT_AT_DECLARATION = `
673+
import * as t from 'io-ts';
674+
import * as h from '@api-ts/io-ts-http';
675+
676+
export const route = h.httpRoute({
677+
path: '/foo',
678+
method: 'GET',
679+
request: h.httpRequest({
680+
params: {
681+
body: t.string,
682+
/**
683+
* Size of the body
684+
* @example 10
685+
*/
686+
size: t.number,
687+
}
688+
}),
689+
response: {
690+
200: Foo
691+
},
692+
});
693+
694+
/**
695+
* a Foo of type 'string'
696+
* @example "foo"
697+
*/
698+
const Foo = t.string;
699+
`;
700+
701+
testCase('request body ref with comments', SCHEMA_REF_WITH_COMMENT_AT_DECLARATION, {
702+
openapi: "3.0.3",
703+
info: {
704+
title: "Test",
705+
version: "1.0.0"
706+
},
707+
paths: {
708+
"/foo": {
709+
get: {
710+
parameters: [
711+
{
712+
name: "body",
713+
in: "path",
714+
required: true,
715+
schema: {
716+
type: "string"
717+
}
718+
},
719+
{
720+
name: "size",
721+
description: "Size of the body",
722+
in: "path",
723+
required: true,
724+
schema: {
725+
type: "number",
726+
example: 10
727+
}
728+
}
729+
],
730+
responses: {
731+
"200": {
732+
description: "OK",
733+
content: {
734+
"application/json": {
735+
schema: {
736+
$ref: "#/components/schemas/Foo"
737+
}
738+
}
739+
}
740+
}
741+
}
742+
}
743+
}
744+
},
745+
components: {
746+
schemas: {
747+
Foo: {
748+
title: "Foo",
749+
type: "string",
750+
description: "a Foo of type 'string'",
751+
example: "foo"
752+
}
753+
}
754+
}
755+
});
756+
672757
const SCHEMA_DOUBLE_REF = `
673758
import * as t from 'io-ts';
674759
import * as h from '@api-ts/io-ts-http';

0 commit comments

Comments
 (0)