Skip to content
Merged
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
6 changes: 5 additions & 1 deletion packages/openapi-generator/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const app = command({
);
process.exit(1);
}
const [newSourceFile, init] = initE.right;
const [newSourceFile, init, comment] = initE.right;

const codecE = parseCodecInitializer(project.right, newSourceFile, init);
if (E.isLeft(codecE)) {
Expand All @@ -186,6 +186,10 @@ const app = command({
);
process.exit(1);
}
if (comment !== undefined) {
codecE.right.comment = comment;
}

Comment on lines +189 to +192
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This takes inspiration from apiSpec.ts:

if (comment !== undefined) {

components[ref.name] = codecE.right;
queue.push(codecE.right);
}
Expand Down
85 changes: 85 additions & 0 deletions packages/openapi-generator/test/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,91 @@ testCase('request body ref', SCHEMA_REF, {
},
});

const SCHEMA_REF_WITH_COMMENT_AT_DECLARATION = `
import * as t from 'io-ts';
import * as h from '@api-ts/io-ts-http';

export const route = h.httpRoute({
path: '/foo',
method: 'GET',
request: h.httpRequest({
params: {
body: t.string,
/**
* Size of the body
* @example 10
*/
size: t.number,
}
}),
response: {
200: Foo
},
});

/**
* a Foo of type 'string'
* @example "foo"
*/
const Foo = t.string;
`;

testCase('request body ref with comments', SCHEMA_REF_WITH_COMMENT_AT_DECLARATION, {
openapi: "3.0.3",
info: {
title: "Test",
version: "1.0.0"
},
paths: {
"/foo": {
get: {
parameters: [
{
name: "body",
in: "path",
required: true,
schema: {
type: "string"
}
},
{
name: "size",
description: "Size of the body",
in: "path",
required: true,
schema: {
type: "number",
example: 10
}
}
],
responses: {
"200": {
description: "OK",
content: {
"application/json": {
schema: {
$ref: "#/components/schemas/Foo"
}
}
}
}
}
}
}
},
components: {
schemas: {
Foo: {
title: "Foo",
type: "string",
description: "a Foo of type 'string'",
example: "foo"
}
}
}
});

const SCHEMA_DOUBLE_REF = `
import * as t from 'io-ts';
import * as h from '@api-ts/io-ts-http';
Expand Down