Skip to content

Commit 8eb75bf

Browse files
authored
Merge pull request #788 from BitGo/DX-456-add-more-tags-in-openapi-generator
feat: add support for more tags in `openapi-generator`
2 parents 27b380a + ebf6e8a commit 8eb75bf

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

packages/openapi-generator/src/openapi.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ function schemaToOpenAPI(
139139
const maxLength = getTagName(schema, 'maxLength');
140140
const minLength = getTagName(schema, 'minLength');
141141
const pattern = getTagName(schema, 'pattern');
142+
const minimum = getTagName(schema, 'minimum');
143+
const maximum = getTagName(schema, 'maximum');
144+
const minItems = getTagName(schema, 'minItems');
145+
const maxItems = getTagName(schema, 'maxItems');
146+
const minProperties = getTagName(schema, 'minProperties');
147+
const maxProperties = getTagName(schema, 'maxProperties');
148+
const exclusiveMinimum = getTagName(schema, 'exclusiveMinimum');
149+
const exclusiveMaximum = getTagName(schema, 'exclusiveMaximum');
150+
const multipleOf = getTagName(schema, 'multipleOf');
151+
const uniqueItems = getTagName(schema, 'uniqueItems');
152+
const readOnly = getTagName(schema, 'readOnly');
153+
const writeOnly = getTagName(schema, 'writeOnly');
142154
const format = getTagName(schema, 'format');
143155

144156
const deprecated = schema.comment?.tags.find((t) => t.tag === 'deprecated');
@@ -152,6 +164,18 @@ function schemaToOpenAPI(
152164
...(maxLength ? { maxLength: Number(maxLength) } : {}),
153165
...(minLength ? { minLength: Number(minLength) } : {}),
154166
...(pattern ? { pattern } : {}),
167+
...(minimum ? { minimum: Number(minimum) } : {}),
168+
...(maximum ? { maximum: Number(maximum) } : {}),
169+
...(minItems ? { minItems: Number(minItems) } : {}),
170+
...(maxItems ? { maxItems: Number(maxItems) } : {}),
171+
...(minProperties ? { minProperties: Number(minProperties) } : {}),
172+
...(maxProperties ? { maxProperties: Number(maxProperties) } : {}),
173+
...(exclusiveMinimum ? { exclusiveMinimum: true } : {}),
174+
...(exclusiveMaximum ? { exclusiveMaximum: true } : {}),
175+
...(multipleOf ? { multipleOf: Number(multipleOf) } : {}),
176+
...(uniqueItems ? { uniqueItems: true } : {}),
177+
...(readOnly ? { readOnly: true } : {}),
178+
...(writeOnly ? { writeOnly: true } : {}),
155179
...(format ? { format } : {}),
156180
};
157181
return defaultOpenAPIObject;

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

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,3 +2531,117 @@ testCase('route with deprecated tag', ROUTE_WITH_DEPRECATED_TAG, {
25312531
schemas: {}
25322532
}
25332533
});
2534+
2535+
const ROUTE_WITH_MIN_MAX_AND_OTHER_TAGS = `
2536+
import * as t from 'io-ts';
2537+
import * as h from '@api-ts/io-ts-http';
2538+
2539+
/**
2540+
* A simple route with type descriptions for references
2541+
*
2542+
* @operationId api.v1.test
2543+
* @tag Test Routes
2544+
*/
2545+
export const route = h.httpRoute({
2546+
path: '/foo',
2547+
method: 'GET',
2548+
request: h.httpRequest({
2549+
body: {
2550+
/**
2551+
* This is a foo description.
2552+
* @minimum 5
2553+
* @maximum 10
2554+
* @minItems 1
2555+
* @maxItems 5
2556+
* @minProperties 1
2557+
* @maxProperties 500
2558+
* @exclusiveMinimum true
2559+
* @exclusiveMaximum true
2560+
* @multipleOf 7
2561+
* @uniqueItems true
2562+
* @readOnly true
2563+
* @writeOnly true
2564+
*/
2565+
foo: t.number()
2566+
},
2567+
}),
2568+
response: {
2569+
200: {
2570+
test: t.string
2571+
}
2572+
},
2573+
});
2574+
`;
2575+
2576+
testCase('route with min and max tags', ROUTE_WITH_MIN_MAX_AND_OTHER_TAGS, {
2577+
openapi: '3.0.3',
2578+
info: {
2579+
title: 'Test',
2580+
version: '1.0.0'
2581+
},
2582+
paths: {
2583+
'/foo': {
2584+
get: {
2585+
summary: 'A simple route with type descriptions for references',
2586+
operationId: 'api.v1.test',
2587+
parameters: [],
2588+
tags: [
2589+
'Test Routes'
2590+
],
2591+
requestBody: {
2592+
content: {
2593+
'application/json': {
2594+
schema: {
2595+
type: 'object',
2596+
properties: {
2597+
foo: {
2598+
type: 'number',
2599+
description: 'This is a foo description.',
2600+
minimum: 5,
2601+
maximum: 10,
2602+
minItems: 1,
2603+
maxItems: 5,
2604+
minProperties: 1,
2605+
multipleOf: 7,
2606+
maxProperties: 500,
2607+
exclusiveMinimum: true,
2608+
exclusiveMaximum: true,
2609+
uniqueItems: true,
2610+
readOnly: true,
2611+
writeOnly: true
2612+
}
2613+
},
2614+
required: [
2615+
'foo'
2616+
]
2617+
}
2618+
}
2619+
}
2620+
},
2621+
responses: {
2622+
'200': {
2623+
description: 'OK',
2624+
content: {
2625+
'application/json': {
2626+
schema: {
2627+
type: 'object',
2628+
properties: {
2629+
test: {
2630+
type: 'string'
2631+
}
2632+
},
2633+
required: [
2634+
'test'
2635+
]
2636+
}
2637+
}
2638+
}
2639+
}
2640+
}
2641+
}
2642+
}
2643+
},
2644+
components: {
2645+
schemas: {}
2646+
}
2647+
});

0 commit comments

Comments
 (0)