Skip to content

Commit

Permalink
Merge pull request #786 from BitGo/DX-452-add-@deprecated-support
Browse files Browse the repository at this point in the history
feat: add support for `@deprecated` tag
  • Loading branch information
bitgopatmcl authored Jun 6, 2024
2 parents 5ed5860 + 2bd861a commit 421fd5e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
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: {}
}
});

0 comments on commit 421fd5e

Please sign in to comment.