Skip to content

Commit 2bd861a

Browse files
author
Ansh Chaturvedi
committed
feat: add support for @deprecated tag
1 parent 5ed5860 commit 2bd861a

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

packages/openapi-generator/src/openapi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,17 @@ function schemaToOpenAPI(
135135

136136
function buildDefaultOpenAPIObject(schema: Schema): OpenAPIV3.SchemaObject {
137137
const defaultValue = getTagName(schema, 'default');
138-
const description = schema.comment?.description;
139138
const example = getTagName(schema, 'example');
140139
const maxLength = getTagName(schema, 'maxLength');
141140
const minLength = getTagName(schema, 'minLength');
142141
const pattern = getTagName(schema, 'pattern');
143142

143+
const deprecated = schema.comment?.tags.find((t) => t.tag === 'deprecated');
144+
const description = schema.comment?.description;
145+
144146
const defaultOpenAPIObject = {
145147
...(defaultValue ? { default: defaultValue } : {}),
148+
...(deprecated ? { deprecated: true } : {}),
146149
...(description ? { description } : {}),
147150
...(example ? { example } : {}),
148151
...(maxLength ? { maxLength: Number(maxLength) } : {}),

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,3 +2439,95 @@ testCase('route with min and max values for strings and default value', ROUTE_WI
24392439
schemas: {}
24402440
}
24412441
});
2442+
2443+
const ROUTE_WITH_DEPRECATED_TAG = `
2444+
import * as t from 'io-ts';
2445+
import * as h from '@api-ts/io-ts-http';
2446+
2447+
/**
2448+
* A simple route with type descriptions for references
2449+
*
2450+
* @operationId api.v1.test
2451+
* @tag Test Routes
2452+
*/
2453+
export const route = h.httpRoute({
2454+
path: '/foo',
2455+
method: 'GET',
2456+
request: h.httpRequest({
2457+
body: {
2458+
/**
2459+
* This is a foo description.
2460+
* @deprecated
2461+
*/
2462+
foo: t.string()
2463+
},
2464+
}),
2465+
response: {
2466+
200: {
2467+
test: t.string
2468+
}
2469+
},
2470+
});
2471+
`;
2472+
2473+
testCase('route with deprecated tag', ROUTE_WITH_DEPRECATED_TAG, {
2474+
openapi: '3.0.3',
2475+
info: {
2476+
title: 'Test',
2477+
version: '1.0.0'
2478+
},
2479+
paths: {
2480+
'/foo': {
2481+
get: {
2482+
summary: 'A simple route with type descriptions for references',
2483+
operationId: 'api.v1.test',
2484+
parameters: [],
2485+
tags: [
2486+
'Test Routes'
2487+
],
2488+
requestBody: {
2489+
content: {
2490+
'application/json': {
2491+
schema: {
2492+
type: 'object',
2493+
properties: {
2494+
foo: {
2495+
type: 'string',
2496+
description: 'This is a foo description.',
2497+
deprecated: true
2498+
}
2499+
},
2500+
required: [
2501+
'foo'
2502+
]
2503+
}
2504+
}
2505+
}
2506+
},
2507+
responses: {
2508+
'200': {
2509+
description: 'OK',
2510+
content: {
2511+
'application/json': {
2512+
schema: {
2513+
type: 'object',
2514+
properties: {
2515+
test: {
2516+
type: 'string'
2517+
}
2518+
},
2519+
required: [
2520+
'test'
2521+
]
2522+
}
2523+
}
2524+
}
2525+
}
2526+
}
2527+
}
2528+
}
2529+
},
2530+
components: {
2531+
schemas: {}
2532+
}
2533+
});

0 commit comments

Comments
 (0)