Skip to content

Commit a6802a3

Browse files
authored
Merge pull request #807 from BitGo/DX-494-comments-from-decls
feat: add support for comments from declarations
2 parents dd18f46 + 7ad9526 commit a6802a3

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
@@ -668,6 +668,91 @@ testCase('request body ref', SCHEMA_REF, {
668668
},
669669
});
670670

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

0 commit comments

Comments
 (0)