diff --git a/packages/openapi-generator/src/openapi.ts b/packages/openapi-generator/src/openapi.ts index c386ec1b..0d16bdf9 100644 --- a/packages/openapi-generator/src/openapi.ts +++ b/packages/openapi-generator/src/openapi.ts @@ -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) } : {}), diff --git a/packages/openapi-generator/test/openapi.test.ts b/packages/openapi-generator/test/openapi.test.ts index 0da2be6e..a5242ba3 100644 --- a/packages/openapi-generator/test/openapi.test.ts +++ b/packages/openapi-generator/test/openapi.test.ts @@ -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: {} + } +});