Skip to content

Commit 5ed5860

Browse files
authored
Merge pull request #785 from BitGo/DX-448-add-@default-support
feat: add `@default` support
2 parents 026ebd8 + 25eeb9d commit 5ed5860

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/openapi-generator/src/openapi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@ function schemaToOpenAPI(
134134
};
135135

136136
function buildDefaultOpenAPIObject(schema: Schema): OpenAPIV3.SchemaObject {
137+
const defaultValue = getTagName(schema, 'default');
137138
const description = schema.comment?.description;
138139
const example = getTagName(schema, 'example');
139140
const maxLength = getTagName(schema, 'maxLength');
140141
const minLength = getTagName(schema, 'minLength');
141142
const pattern = getTagName(schema, 'pattern');
142143

143144
const defaultOpenAPIObject = {
145+
...(defaultValue ? { default: defaultValue } : {}),
144146
...(description ? { description } : {}),
145147
...(example ? { example } : {}),
146148
...(maxLength ? { maxLength: Number(maxLength) } : {}),

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ testCase('route with descriptions for references', ROUTE_WITH_DESCRIPTIONS_FOR_R
23272327
}
23282328
});
23292329

2330-
const ROUTE_WITH_MIN_AND_MAX_VALUES_FOR_STRINGS = `
2330+
const ROUTE_WITH_MIN_AND_MAX_VALUES_FOR_STRINGS_AND_DEFAULT = `
23312331
import * as t from 'io-ts';
23322332
import * as h from '@api-ts/io-ts-http';
23332333
@@ -2349,7 +2349,8 @@ export const route = h.httpRoute({
23492349
* This is a foo description.
23502350
* @minLength 5
23512351
* @maxLength 10
2352-
* @example "BitgoInc"
2352+
* @example "SomeInc"
2353+
* @default "BitgoInc"
23532354
*/
23542355
foo: t.string()
23552356
},
@@ -2362,7 +2363,7 @@ export const route = h.httpRoute({
23622363
});
23632364
`;
23642365

2365-
testCase('route with min and max values for strings', ROUTE_WITH_MIN_AND_MAX_VALUES_FOR_STRINGS, {
2366+
testCase('route with min and max values for strings and default value', ROUTE_WITH_MIN_AND_MAX_VALUES_FOR_STRINGS_AND_DEFAULT, {
23662367
openapi: '3.0.3',
23672368
info: {
23682369
title: 'Test',
@@ -2398,7 +2399,8 @@ testCase('route with min and max values for strings', ROUTE_WITH_MIN_AND_MAX_VAL
23982399
foo: {
23992400
type: 'string',
24002401
description: 'This is a foo description.',
2401-
example: 'BitgoInc',
2402+
example: 'SomeInc',
2403+
default: 'BitgoInc',
24022404
minLength: 5,
24032405
maxLength: 10
24042406
}

0 commit comments

Comments
 (0)