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
5 changes: 4 additions & 1 deletion packages/openapi-generator/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ function schemaToOpenAPI(

function buildDefaultOpenAPIObject(schema: Schema): OpenAPIV3.SchemaObject {
const defaultValue = getTagName(schema, 'default');
const description = schema.comment?.description;
const example = getTagName(schema, 'example');
const maxLength = getTagName(schema, 'maxLength');
const minLength = getTagName(schema, 'minLength');
const pattern = getTagName(schema, 'pattern');

const deprecated = schema.comment?.tags.find((t) => t.tag === 'deprecated');
const description = schema.comment?.description;

const defaultOpenAPIObject = {
...(defaultValue ? { default: defaultValue } : {}),
...(deprecated ? { deprecated: true } : {}),
...(description ? { description } : {}),
...(example ? { example } : {}),
...(maxLength ? { maxLength: Number(maxLength) } : {}),
Expand Down
92 changes: 92 additions & 0 deletions packages/openapi-generator/test/openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2439,3 +2439,95 @@ testCase('route with min and max values for strings and default value', ROUTE_WI
schemas: {}
}
});

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

/**
* A simple route with type descriptions for references
*
* @operationId api.v1.test
* @tag Test Routes
*/
export const route = h.httpRoute({
path: '/foo',
method: 'GET',
request: h.httpRequest({
body: {
/**
* This is a foo description.
* @deprecated
*/
foo: t.string()
},
}),
response: {
200: {
test: t.string
}
},
});
`;

testCase('route with deprecated tag', ROUTE_WITH_DEPRECATED_TAG, {
openapi: '3.0.3',
info: {
title: 'Test',
version: '1.0.0'
},
paths: {
'/foo': {
get: {
summary: 'A simple route with type descriptions for references',
operationId: 'api.v1.test',
parameters: [],
tags: [
'Test Routes'
],
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
properties: {
foo: {
type: 'string',
description: 'This is a foo description.',
deprecated: true
}
},
required: [
'foo'
]
}
}
}
},
responses: {
'200': {
description: 'OK',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
test: {
type: 'string'
}
},
required: [
'test'
]
}
}
}
}
}
}
}
},
components: {
schemas: {}
}
});