fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #197 from hey-api/feat/additional-schema-properties

feat(schema): additional schema properties

authored by

Jordan Shatford and committed by
GitHub
ca2847f6 7a19cf37

+178 -83
+5
.changeset/fresh-timers-train.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + feat(schema): add support for default values
+5
.changeset/swift-candles-melt.md
··· 1 + --- 2 + "@hey-api/openapi-ts": minor 3 + --- 4 + 5 + feat(schema): add array of enum values for enums
+1 -1
src/openApi/common/interfaces/client.ts
··· 56 56 } 57 57 58 58 export interface Schema { 59 + default?: unknown; 59 60 exclusiveMaximum?: boolean; 60 61 exclusiveMinimum?: boolean; 61 62 format?: ··· 95 96 */ 96 97 $refs: string[]; 97 98 base: string; 98 - default?: string; 99 99 deprecated?: boolean; 100 100 description: string | null; 101 101 enum: Enum[];
+1 -1
src/openApi/common/parser/sort.ts
··· 2 2 * Sort list of values and ensure that required parameters are first so that we do not generate 3 3 * invalid types. Optional parameters cannot be positioned after required ones. 4 4 */ 5 - export function toSortedByRequired<T extends { isRequired: boolean; default?: string }>(values: T[]): T[] { 5 + export function toSortedByRequired<T extends { isRequired: boolean; default?: unknown }>(values: T[]): T[] { 6 6 return values.sort((a, b) => { 7 7 const aNeedsValue = a.isRequired && a.default === undefined; 8 8 const bNeedsValue = b.isRequired && b.default === undefined;
+1 -1
src/openApi/v2/interfaces/OpenApiParameter.ts
··· 29 29 allowEmptyValue?: boolean; 30 30 items?: OpenApiItems; 31 31 collectionFormat?: 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'; 32 - default?: number; 32 + default?: unknown; 33 33 maximum?: number; 34 34 exclusiveMaximum?: boolean; 35 35 minimum?: number;
+8 -8
src/openApi/v2/parser/getOperationParameter.ts
··· 1 1 import type { OperationParameter } from '../../common/interfaces/client'; 2 + import { getDefault } from '../../common/parser/getDefault'; 2 3 import { getEnums } from '../../common/parser/getEnums'; 3 4 import { getPattern } from '../../common/parser/getPattern'; 4 5 import { getRef } from '../../common/parser/getRef'; ··· 8 9 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 9 10 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 10 11 import { getModel } from './getModel'; 11 - import { getOperationParameterDefault } from './getOperationParameterDefault'; 12 12 13 13 export const getOperationParameter = (openApi: OpenApi, parameter: OpenApiParameter): OperationParameter => { 14 14 const operationParameter: OperationParameter = { ··· 52 52 operationParameter.base = definitionRef.base; 53 53 operationParameter.template = definitionRef.template; 54 54 operationParameter.imports.push(...definitionRef.imports); 55 - operationParameter.default = getOperationParameterDefault(parameter, operationParameter); 55 + operationParameter.default = getDefault(parameter, operationParameter); 56 56 return operationParameter; 57 57 } 58 58 ··· 63 63 operationParameter.enum.push(...enums); 64 64 operationParameter.export = 'enum'; 65 65 operationParameter.type = 'string'; 66 - operationParameter.default = getOperationParameterDefault(parameter, operationParameter); 66 + operationParameter.default = getDefault(parameter, operationParameter); 67 67 return operationParameter; 68 68 } 69 69 } ··· 75 75 operationParameter.base = items.base; 76 76 operationParameter.template = items.template; 77 77 operationParameter.imports.push(...items.imports); 78 - operationParameter.default = getOperationParameterDefault(parameter, operationParameter); 78 + operationParameter.default = getDefault(parameter, operationParameter); 79 79 return operationParameter; 80 80 } 81 81 ··· 86 86 operationParameter.base = items.base; 87 87 operationParameter.template = items.template; 88 88 operationParameter.imports.push(...items.imports); 89 - operationParameter.default = getOperationParameterDefault(parameter, operationParameter); 89 + operationParameter.default = getDefault(parameter, operationParameter); 90 90 return operationParameter; 91 91 } 92 92 ··· 102 102 operationParameter.base = model.base; 103 103 operationParameter.template = model.template; 104 104 operationParameter.imports.push(...model.imports); 105 - operationParameter.default = getOperationParameterDefault(parameter, operationParameter); 105 + operationParameter.default = getDefault(parameter, operationParameter); 106 106 return operationParameter; 107 107 } else { 108 108 const model = getModel(openApi, schema); ··· 115 115 operationParameter.enum.push(...model.enum); 116 116 operationParameter.enums.push(...model.enums); 117 117 operationParameter.properties.push(...model.properties); 118 - operationParameter.default = getOperationParameterDefault(parameter, operationParameter); 118 + operationParameter.default = getDefault(parameter, operationParameter); 119 119 return operationParameter; 120 120 } 121 121 } ··· 128 128 operationParameter.base = definitionType.base; 129 129 operationParameter.template = definitionType.template; 130 130 operationParameter.imports.push(...definitionType.imports); 131 - operationParameter.default = getOperationParameterDefault(parameter, operationParameter); 131 + operationParameter.default = getDefault(parameter, operationParameter); 132 132 return operationParameter; 133 133 } 134 134
-43
src/openApi/v2/parser/getOperationParameterDefault.ts
··· 1 - import type { OperationParameter } from '../../common/interfaces/client'; 2 - import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 3 - 4 - export const getOperationParameterDefault = ( 5 - parameter: OpenApiParameter, 6 - operationParameter: OperationParameter 7 - ): string | undefined => { 8 - if (parameter.default === undefined) { 9 - return undefined; 10 - } 11 - 12 - if (parameter.default === null) { 13 - return 'null'; 14 - } 15 - 16 - const type = parameter.type || typeof parameter.default; 17 - 18 - switch (type) { 19 - case 'int': 20 - case 'integer': 21 - case 'number': 22 - if (operationParameter.export === 'enum' && operationParameter.enum?.[parameter.default]) { 23 - const { value } = operationParameter.enum[parameter.default]; 24 - return typeof value === 'string' ? `'${value}'` : String(value); 25 - } 26 - return String(parameter.default); 27 - 28 - case 'boolean': 29 - return JSON.stringify(parameter.default); 30 - 31 - case 'string': 32 - return `'${parameter.default}'`; 33 - 34 - case 'object': 35 - try { 36 - return JSON.stringify(parameter.default, null, 4); 37 - } catch (e) { 38 - // Ignore 39 - } 40 - } 41 - 42 - return undefined; 43 - };
+1 -1
src/openApi/v3/interfaces/OpenApiSchema.ts
··· 13 13 allOf?: OpenApiSchema[]; 14 14 anyOf?: OpenApiSchema[]; 15 15 const?: string | number | boolean | null; 16 - default?: number; 16 + default?: unknown; 17 17 deprecated?: boolean; 18 18 description?: string; 19 19 discriminator?: OpenApiDiscriminator;
+7 -7
src/openApi/v3/parser/getModel.ts
··· 1 1 import type { Model } from '../../common/interfaces/client'; 2 + import { getDefault } from '../../common/parser/getDefault'; 2 3 import { getEnums } from '../../common/parser/getEnums'; 3 4 import { getPattern } from '../../common/parser/getPattern'; 4 5 import { getType } from '../../common/parser/type'; 5 6 import type { OpenApi } from '../interfaces/OpenApi'; 6 7 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 7 8 import { findModelComposition, getModelComposition } from './getModelComposition'; 8 - import { getModelDefault } from './getModelDefault'; 9 9 import { getAdditionalPropertiesModel, getModelProperties } from './getModelProperties'; 10 10 import { inferType } from './inferType'; 11 11 ··· 59 59 model.imports = [...model.imports, ...definitionRef.imports]; 60 60 model.template = definitionRef.template; 61 61 model.type = definitionRef.type; 62 - model.default = getModelDefault(definition, model); 62 + model.default = getDefault(definition, model); 63 63 return model; 64 64 } 65 65 ··· 70 70 model.enum = [...model.enum, ...enums]; 71 71 model.export = 'enum'; 72 72 model.type = 'string'; 73 - model.default = getModelDefault(definition, model); 73 + model.default = getDefault(definition, model); 74 74 return model; 75 75 } 76 76 } ··· 84 84 model.imports = [...model.imports, ...arrayItems.imports]; 85 85 model.template = arrayItems.template; 86 86 model.type = arrayItems.type; 87 - model.default = getModelDefault(definition, model); 87 + model.default = getDefault(definition, model); 88 88 return model; 89 89 } 90 90 ··· 112 112 model.link = arrayItems; 113 113 model.template = arrayItems.template; 114 114 model.type = arrayItems.type; 115 - model.default = getModelDefault(definition, model); 115 + model.default = getDefault(definition, model); 116 116 return model; 117 117 } 118 118 ··· 133 133 model.base = 'any'; 134 134 model.export = 'interface'; 135 135 model.type = 'any'; 136 - model.default = getModelDefault(definition, model); 136 + model.default = getDefault(definition, model); 137 137 138 138 const modelProperties = getModelProperties(openApi, definition, getModel, model); 139 139 modelProperties.forEach(modelProperty => { ··· 176 176 model.isNullable = definitionType.isNullable || model.isNullable; 177 177 model.template = definitionType.template; 178 178 model.type = definitionType.type; 179 - model.default = getModelDefault(definition, model); 179 + model.default = getDefault(definition, model); 180 180 return model; 181 181 } 182 182
+11 -10
src/openApi/v3/parser/getModelDefault.ts src/openApi/common/parser/getDefault.ts
··· 1 1 import type { Model } from '../../common/interfaces/client'; 2 - import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 2 + import type { OpenApiParameter } from '../../v2/interfaces/OpenApiParameter'; 3 + import type { OpenApiSchema } from '../../v3/interfaces/OpenApiSchema'; 4 + import type { OperationParameter } from '../interfaces/client'; 3 5 4 - export const getModelDefault = (definition: OpenApiSchema, model?: Model): string | undefined => { 6 + export const getDefault = ( 7 + definition: OpenApiSchema | OpenApiParameter, 8 + model?: Model | OperationParameter 9 + ): string | undefined => { 5 10 if (definition.default === undefined) { 6 11 return undefined; 7 12 } ··· 16 21 case 'int': 17 22 case 'integer': 18 23 case 'number': 19 - if (model?.export === 'enum' && model.enum?.[definition.default]) { 20 - const { value } = model.enum[definition.default]; 24 + if (model?.export === 'enum' && model.enum?.[definition.default as number]) { 25 + const { value } = model.enum[definition.default as number]; 21 26 return typeof value === 'string' ? `'${value}'` : String(value); 22 27 } 23 28 return String(definition.default); 24 - 25 - case 'boolean': 26 - return JSON.stringify(definition.default); 27 - 28 29 case 'string': 29 30 return `'${definition.default}'`; 30 - 31 + case 'array': 32 + case 'boolean': 31 33 case 'object': 32 34 try { 33 35 return JSON.stringify(definition.default, null, 4); ··· 35 37 // Ignore 36 38 } 37 39 } 38 - 39 40 return undefined; 40 41 };
+6 -4
src/openApi/v3/parser/getModelProperties.ts
··· 1 1 import { escapeName } from '../../../utils/escapeName'; 2 2 import type { Model } from '../../common/interfaces/client'; 3 + import { getDefault } from '../../common/parser/getDefault'; 3 4 import { getPattern } from '../../common/parser/getPattern'; 4 5 import { getType } from '../../common/parser/type'; 5 6 import type { OpenApi } from '../interfaces/OpenApi'; 6 7 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 7 8 import { findOneOfParentDiscriminator, mapPropertyValue } from './discriminator'; 8 9 import type { getModel } from './getModel'; 9 - import { getModelDefault } from './getModelDefault'; 10 10 11 11 // Fix for circular dependency 12 12 export type GetModelFn = typeof getModel; ··· 21 21 const apModel = getModel(openApi, ap); 22 22 23 23 if (definition.additionalProperties === true && definition.properties) { 24 - apModel.default = getModelDefault(definition, model); 24 + apModel.default = getDefault(definition, model); 25 25 apModel.export = 'generic'; 26 26 apModel.isRequired = true; 27 27 apModel.name = '[key: string]'; ··· 31 31 if (ap.$ref) { 32 32 const apType = getType(ap.$ref); 33 33 model.base = apType.base; 34 - model.default = getModelDefault(definition, model); 34 + model.default = getDefault(definition, model); 35 35 model.export = 'dictionary'; 36 36 model.imports.push(...apType.imports); 37 37 model.template = apType.template; ··· 40 40 } 41 41 42 42 model.base = apModel.base; 43 - model.default = getModelDefault(definition, model); 43 + model.default = getDefault(definition, model); 44 44 model.export = 'dictionary'; 45 45 model.imports.push(...apModel.imports); 46 46 model.link = apModel; ··· 78 78 > = { 79 79 deprecated: property.deprecated === true, 80 80 description: property.description || null, 81 + default: property.default, 81 82 exclusiveMaximum: property.exclusiveMaximum, 82 83 exclusiveMinimum: property.exclusiveMinimum, 83 84 format: property.format, ··· 138 139 enum: model.enum, 139 140 enums: model.enums, 140 141 export: model.export, 142 + default: model.default, 141 143 imports: model.imports, 142 144 isNullable: model.isNullable || property.nullable === true, 143 145 link: model.link,
+2 -2
src/openApi/v3/parser/getOperationParameter.ts
··· 1 1 import type { OperationParameter } from '../../common/interfaces/client'; 2 + import { getDefault } from '../../common/parser/getDefault'; 2 3 import { getPattern } from '../../common/parser/getPattern'; 3 4 import { getRef } from '../../common/parser/getRef'; 4 5 import { getOperationParameterName } from '../../common/parser/operation'; ··· 7 8 import type { OpenApiParameter } from '../interfaces/OpenApiParameter'; 8 9 import type { OpenApiSchema } from '../interfaces/OpenApiSchema'; 9 10 import { getModel } from './getModel'; 10 - import { getModelDefault } from './getModelDefault'; 11 11 12 12 export const getOperationParameter = (openApi: OpenApi, parameter: OpenApiParameter): OperationParameter => { 13 13 const operationParameter: OperationParameter = { ··· 57 57 operationParameter.template = model.template; 58 58 operationParameter.$refs = [...operationParameter.$refs, ...model.$refs]; 59 59 operationParameter.imports = [...operationParameter.imports, ...model.imports]; 60 - operationParameter.default = getModelDefault(schema); 60 + operationParameter.default = getDefault(schema); 61 61 return operationParameter; 62 62 } else { 63 63 const model = getModel(openApi, schema);
+3
src/templates/partials/schemaArray.hbs
··· 7 7 type: '{{{base}}}', 8 8 }, 9 9 {{/if}} 10 + {{#notEquals default undefined}} 11 + default: {{{default}}}, 12 + {{/notEquals}} 10 13 {{#if isReadOnly}} 11 14 isReadOnly: {{{isReadOnly}}}, 12 15 {{/if}}
+3
src/templates/partials/schemaComposition.hbs
··· 4 4 description: `{{{escapeDescription description}}}`, 5 5 {{/if}} 6 6 contains: [{{#each properties}}{{>schema}}{{#unless @last}}, {{/unless}}{{/each}}], 7 + {{#notEquals default undefined}} 8 + default: {{{default}}}, 9 + {{/notEquals}} 7 10 {{#if isReadOnly}} 8 11 isReadOnly: {{{isReadOnly}}}, 9 12 {{/if}}
+3
src/templates/partials/schemaDictionary.hbs
··· 7 7 type: '{{{base}}}', 8 8 }, 9 9 {{/if}} 10 + {{#notEquals default undefined}} 11 + default: {{{default}}}, 12 + {{/notEquals}} 10 13 {{#if isReadOnly}} 11 14 isReadOnly: {{{isReadOnly}}}, 12 15 {{/if}}
+6
src/templates/partials/schemaEnum.hbs
··· 1 1 { 2 2 type: 'Enum', 3 + {{#if enum}} 4 + enum: [{{#each enum}}{{{enumValue value}}},{{/each}}], 5 + {{/if}} 6 + {{#notEquals default undefined}} 7 + default: {{{default}}}, 8 + {{/notEquals}} 3 9 {{#if isReadOnly}} 4 10 isReadOnly: {{{isReadOnly}}}, 5 11 {{/if}}
+3
src/templates/partials/schemaGeneric.hbs
··· 5 5 {{#if description}} 6 6 description: `{{{escapeDescription description}}}`, 7 7 {{/if}} 8 + {{#notEquals default undefined}} 9 + default: {{{default}}}, 10 + {{/notEquals}} 8 11 {{#if isReadOnly}} 9 12 isReadOnly: {{{isReadOnly}}}, 10 13 {{/if}}
+3
src/templates/partials/schemaInterface.hbs
··· 11 11 {{/each}} 12 12 {{/if}} 13 13 }, 14 + {{#notEquals default undefined}} 15 + default: {{{default}}}, 16 + {{/notEquals}} 14 17 {{#if isReadOnly}} 15 18 isReadOnly: {{{isReadOnly}}}, 16 19 {{/if}}
+7
test/__snapshots__/v2/schemas.ts.snap
··· 70 70 71 71 export const $EnumWithStrings = { 72 72 type: 'Enum', 73 + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'], 73 74 } as const; 74 75 75 76 export const $EnumWithNumbers = { 76 77 type: 'Enum', 78 + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], 77 79 } as const; 78 80 79 81 export const $EnumFromDescription = { ··· 83 85 84 86 export const $EnumWithExtensions = { 85 87 type: 'Enum', 88 + enum: [200, 400, 500], 86 89 } as const; 87 90 88 91 export const $ArrayWithNumbers = { ··· 242 245 properties: { 243 246 test: { 244 247 type: 'Enum', 248 + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 245 249 }, 246 250 statusCode: { 247 251 type: 'Enum', 252 + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'], 248 253 }, 249 254 bool: { 250 255 type: 'boolean', ··· 270 275 type: 'dictionary', 271 276 contains: { 272 277 type: 'Enum', 278 + enum: ['Success', 'Warning', 'Error'], 273 279 }, 274 280 }, 275 281 dictionaryWithEnumFromDescription: { ··· 283 289 type: 'array', 284 290 contains: { 285 291 type: 'Enum', 292 + enum: ['Success', 'Warning', 'Error'], 286 293 }, 287 294 }, 288 295 arrayWithDescription: {
+23
test/__snapshots__/v3/schemas.ts.snap
··· 71 71 72 72 export const $EnumWithStrings = { 73 73 type: 'Enum', 74 + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'], 74 75 } as const; 75 76 76 77 export const $EnumWithReplacedCharacters = { 77 78 type: 'Enum', 79 + enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], 78 80 } as const; 79 81 80 82 export const $EnumWithNumbers = { 81 83 type: 'Enum', 84 + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], 85 + default: 200, 82 86 } as const; 83 87 84 88 export const $EnumFromDescription = { ··· 88 92 89 93 export const $EnumWithExtensions = { 90 94 type: 'Enum', 95 + enum: [200, 400, 500], 91 96 } as const; 92 97 93 98 export const $ArrayWithNumbers = { ··· 109 114 contains: { 110 115 type: 'string', 111 116 }, 117 + default: ['test'], 112 118 } as const; 113 119 114 120 export const $ArrayWithReferences = { ··· 151 157 properties: { 152 158 foo: { 153 159 type: 'string', 160 + default: 'test', 154 161 }, 155 162 }, 156 163 }, ··· 320 327 properties: { 321 328 test: { 322 329 type: 'Enum', 330 + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 323 331 }, 324 332 statusCode: { 325 333 type: 'Enum', 334 + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'], 326 335 }, 327 336 bool: { 328 337 type: 'boolean', ··· 336 345 properties: { 337 346 'foo-bar-baz-qux': { 338 347 type: 'Enum', 348 + enum: ['3.0'], 349 + default: '3.0', 339 350 }, 340 351 }, 341 352 } as const; ··· 357 368 type: 'dictionary', 358 369 contains: { 359 370 type: 'Enum', 371 + enum: ['Success', 'Warning', 'Error'], 360 372 }, 361 373 }, 362 374 dictionaryWithEnumFromDescription: { ··· 370 382 type: 'array', 371 383 contains: { 372 384 type: 'Enum', 385 + enum: ['Success', 'Warning', 'Error'], 373 386 }, 374 387 }, 375 388 arrayWithDescription: { ··· 650 663 651 664 export const $Enum1 = { 652 665 type: 'Enum', 666 + enum: ['Bird', 'Dog'], 653 667 } as const; 654 668 655 669 export const $ConstValue = { ··· 1126 1140 properties: { 1127 1141 page: { 1128 1142 type: 'number', 1143 + default: 0, 1129 1144 format: 'int32', 1130 1145 minimum: 0, 1131 1146 }, ··· 1273 1288 type: 'string', 1274 1289 }, 1275 1290 }, 1291 + default: null, 1276 1292 isNullable: true, 1277 1293 } as const; 1278 1294 ··· 1291 1307 properties: { 1292 1308 foo: { 1293 1309 type: 'Enum', 1310 + enum: ['Bar'], 1294 1311 isRequired: true, 1295 1312 }, 1296 1313 }, ··· 1299 1316 properties: { 1300 1317 foo: { 1301 1318 type: 'Enum', 1319 + enum: ['Baz'], 1302 1320 isRequired: true, 1303 1321 }, 1304 1322 }, ··· 1307 1325 properties: { 1308 1326 foo: { 1309 1327 type: 'Enum', 1328 + enum: ['Qux'], 1310 1329 isRequired: true, 1311 1330 }, 1312 1331 }, ··· 1320 1339 }, 1321 1340 foo: { 1322 1341 type: 'Enum', 1342 + enum: ['Quux'], 1323 1343 isRequired: true, 1324 1344 }, 1325 1345 }, ··· 1344 1364 }, 1345 1365 foo: { 1346 1366 type: 'Enum', 1367 + enum: ['Corge'], 1347 1368 isRequired: true, 1348 1369 }, 1349 1370 }, ··· 1353 1374 1354 1375 export const $ModelWithNestedArrayEnumsDataFoo = { 1355 1376 type: 'Enum', 1377 + enum: ['foo', 'bar'], 1356 1378 } as const; 1357 1379 1358 1380 export const $ModelWithNestedArrayEnumsDataBar = { 1359 1381 type: 'Enum', 1382 + enum: ['baz', 'qux'], 1360 1383 } as const; 1361 1384 1362 1385 export const $ModelWithNestedArrayEnumsData = {
+23
test/__snapshots__/v3_angular/schemas.ts.snap
··· 71 71 72 72 export const $EnumWithStrings = { 73 73 type: 'Enum', 74 + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'], 74 75 } as const; 75 76 76 77 export const $EnumWithReplacedCharacters = { 77 78 type: 'Enum', 79 + enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], 78 80 } as const; 79 81 80 82 export const $EnumWithNumbers = { 81 83 type: 'Enum', 84 + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], 85 + default: 200, 82 86 } as const; 83 87 84 88 export const $EnumFromDescription = { ··· 88 92 89 93 export const $EnumWithExtensions = { 90 94 type: 'Enum', 95 + enum: [200, 400, 500], 91 96 } as const; 92 97 93 98 export const $ArrayWithNumbers = { ··· 109 114 contains: { 110 115 type: 'string', 111 116 }, 117 + default: ['test'], 112 118 } as const; 113 119 114 120 export const $ArrayWithReferences = { ··· 151 157 properties: { 152 158 foo: { 153 159 type: 'string', 160 + default: 'test', 154 161 }, 155 162 }, 156 163 }, ··· 320 327 properties: { 321 328 test: { 322 329 type: 'Enum', 330 + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 323 331 }, 324 332 statusCode: { 325 333 type: 'Enum', 334 + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'], 326 335 }, 327 336 bool: { 328 337 type: 'boolean', ··· 336 345 properties: { 337 346 'foo-bar-baz-qux': { 338 347 type: 'Enum', 348 + enum: ['3.0'], 349 + default: '3.0', 339 350 }, 340 351 }, 341 352 } as const; ··· 357 368 type: 'dictionary', 358 369 contains: { 359 370 type: 'Enum', 371 + enum: ['Success', 'Warning', 'Error'], 360 372 }, 361 373 }, 362 374 dictionaryWithEnumFromDescription: { ··· 370 382 type: 'array', 371 383 contains: { 372 384 type: 'Enum', 385 + enum: ['Success', 'Warning', 'Error'], 373 386 }, 374 387 }, 375 388 arrayWithDescription: { ··· 650 663 651 664 export const $Enum1 = { 652 665 type: 'Enum', 666 + enum: ['Bird', 'Dog'], 653 667 } as const; 654 668 655 669 export const $ConstValue = { ··· 1126 1140 properties: { 1127 1141 page: { 1128 1142 type: 'number', 1143 + default: 0, 1129 1144 format: 'int32', 1130 1145 minimum: 0, 1131 1146 }, ··· 1273 1288 type: 'string', 1274 1289 }, 1275 1290 }, 1291 + default: null, 1276 1292 isNullable: true, 1277 1293 } as const; 1278 1294 ··· 1291 1307 properties: { 1292 1308 foo: { 1293 1309 type: 'Enum', 1310 + enum: ['Bar'], 1294 1311 isRequired: true, 1295 1312 }, 1296 1313 }, ··· 1299 1316 properties: { 1300 1317 foo: { 1301 1318 type: 'Enum', 1319 + enum: ['Baz'], 1302 1320 isRequired: true, 1303 1321 }, 1304 1322 }, ··· 1307 1325 properties: { 1308 1326 foo: { 1309 1327 type: 'Enum', 1328 + enum: ['Qux'], 1310 1329 isRequired: true, 1311 1330 }, 1312 1331 }, ··· 1320 1339 }, 1321 1340 foo: { 1322 1341 type: 'Enum', 1342 + enum: ['Quux'], 1323 1343 isRequired: true, 1324 1344 }, 1325 1345 }, ··· 1344 1364 }, 1345 1365 foo: { 1346 1366 type: 'Enum', 1367 + enum: ['Corge'], 1347 1368 isRequired: true, 1348 1369 }, 1349 1370 }, ··· 1353 1374 1354 1375 export const $ModelWithNestedArrayEnumsDataFoo = { 1355 1376 type: 'Enum', 1377 + enum: ['foo', 'bar'], 1356 1378 } as const; 1357 1379 1358 1380 export const $ModelWithNestedArrayEnumsDataBar = { 1359 1381 type: 'Enum', 1382 + enum: ['baz', 'qux'], 1360 1383 } as const; 1361 1384 1362 1385 export const $ModelWithNestedArrayEnumsData = {
+23
test/__snapshots__/v3_enums_typescript/schemas.ts.snap
··· 71 71 72 72 export const $EnumWithStrings = { 73 73 type: 'Enum', 74 + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'], 74 75 } as const; 75 76 76 77 export const $EnumWithReplacedCharacters = { 77 78 type: 'Enum', 79 + enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], 78 80 } as const; 79 81 80 82 export const $EnumWithNumbers = { 81 83 type: 'Enum', 84 + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], 85 + default: 200, 82 86 } as const; 83 87 84 88 export const $EnumFromDescription = { ··· 88 92 89 93 export const $EnumWithExtensions = { 90 94 type: 'Enum', 95 + enum: [200, 400, 500], 91 96 } as const; 92 97 93 98 export const $ArrayWithNumbers = { ··· 109 114 contains: { 110 115 type: 'string', 111 116 }, 117 + default: ['test'], 112 118 } as const; 113 119 114 120 export const $ArrayWithReferences = { ··· 151 157 properties: { 152 158 foo: { 153 159 type: 'string', 160 + default: 'test', 154 161 }, 155 162 }, 156 163 }, ··· 320 327 properties: { 321 328 test: { 322 329 type: 'Enum', 330 + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 323 331 }, 324 332 statusCode: { 325 333 type: 'Enum', 334 + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'], 326 335 }, 327 336 bool: { 328 337 type: 'boolean', ··· 336 345 properties: { 337 346 'foo-bar-baz-qux': { 338 347 type: 'Enum', 348 + enum: ['3.0'], 349 + default: '3.0', 339 350 }, 340 351 }, 341 352 } as const; ··· 357 368 type: 'dictionary', 358 369 contains: { 359 370 type: 'Enum', 371 + enum: ['Success', 'Warning', 'Error'], 360 372 }, 361 373 }, 362 374 dictionaryWithEnumFromDescription: { ··· 370 382 type: 'array', 371 383 contains: { 372 384 type: 'Enum', 385 + enum: ['Success', 'Warning', 'Error'], 373 386 }, 374 387 }, 375 388 arrayWithDescription: { ··· 650 663 651 664 export const $Enum1 = { 652 665 type: 'Enum', 666 + enum: ['Bird', 'Dog'], 653 667 } as const; 654 668 655 669 export const $ConstValue = { ··· 1126 1140 properties: { 1127 1141 page: { 1128 1142 type: 'number', 1143 + default: 0, 1129 1144 format: 'int32', 1130 1145 minimum: 0, 1131 1146 }, ··· 1273 1288 type: 'string', 1274 1289 }, 1275 1290 }, 1291 + default: null, 1276 1292 isNullable: true, 1277 1293 } as const; 1278 1294 ··· 1291 1307 properties: { 1292 1308 foo: { 1293 1309 type: 'Enum', 1310 + enum: ['Bar'], 1294 1311 isRequired: true, 1295 1312 }, 1296 1313 }, ··· 1299 1316 properties: { 1300 1317 foo: { 1301 1318 type: 'Enum', 1319 + enum: ['Baz'], 1302 1320 isRequired: true, 1303 1321 }, 1304 1322 }, ··· 1307 1325 properties: { 1308 1326 foo: { 1309 1327 type: 'Enum', 1328 + enum: ['Qux'], 1310 1329 isRequired: true, 1311 1330 }, 1312 1331 }, ··· 1320 1339 }, 1321 1340 foo: { 1322 1341 type: 'Enum', 1342 + enum: ['Quux'], 1323 1343 isRequired: true, 1324 1344 }, 1325 1345 }, ··· 1344 1364 }, 1345 1365 foo: { 1346 1366 type: 'Enum', 1367 + enum: ['Corge'], 1347 1368 isRequired: true, 1348 1369 }, 1349 1370 }, ··· 1353 1374 1354 1375 export const $ModelWithNestedArrayEnumsDataFoo = { 1355 1376 type: 'Enum', 1377 + enum: ['foo', 'bar'], 1356 1378 } as const; 1357 1379 1358 1380 export const $ModelWithNestedArrayEnumsDataBar = { 1359 1381 type: 'Enum', 1382 + enum: ['baz', 'qux'], 1360 1383 } as const; 1361 1384 1362 1385 export const $ModelWithNestedArrayEnumsData = {
+23
test/__snapshots__/v3_experimental/schemas.ts.snap
··· 71 71 72 72 export const $EnumWithStrings = { 73 73 type: 'Enum', 74 + enum: ['Success', 'Warning', 'Error', "'Single Quote'", '"Double Quotes"', 'Non-ascii: øæåôöØÆÅÔÖ字符串'], 74 75 } as const; 75 76 76 77 export const $EnumWithReplacedCharacters = { 77 78 type: 'Enum', 79 + enum: ["'Single Quote'", '"Double Quotes"', 'øæåôöØÆÅÔÖ字符串', 3.1, ''], 78 80 } as const; 79 81 80 82 export const $EnumWithNumbers = { 81 83 type: 'Enum', 84 + enum: [1, 2, 3, 1.1, 1.2, 1.3, 100, 200, 300, -100, -200, -300, -1.1, -1.2, -1.3], 85 + default: 200, 82 86 } as const; 83 87 84 88 export const $EnumFromDescription = { ··· 88 92 89 93 export const $EnumWithExtensions = { 90 94 type: 'Enum', 95 + enum: [200, 400, 500], 91 96 } as const; 92 97 93 98 export const $ArrayWithNumbers = { ··· 109 114 contains: { 110 115 type: 'string', 111 116 }, 117 + default: ['test'], 112 118 } as const; 113 119 114 120 export const $ArrayWithReferences = { ··· 151 157 properties: { 152 158 foo: { 153 159 type: 'string', 160 + default: 'test', 154 161 }, 155 162 }, 156 163 }, ··· 320 327 properties: { 321 328 test: { 322 329 type: 'Enum', 330 + enum: ['Success', 'Warning', 'Error', 'ØÆÅ字符串'], 323 331 }, 324 332 statusCode: { 325 333 type: 'Enum', 334 + enum: ['100', '200 FOO', '300 FOO_BAR', '400 foo-bar', '500 foo.bar', '600 foo&bar'], 326 335 }, 327 336 bool: { 328 337 type: 'boolean', ··· 336 345 properties: { 337 346 'foo-bar-baz-qux': { 338 347 type: 'Enum', 348 + enum: ['3.0'], 349 + default: '3.0', 339 350 }, 340 351 }, 341 352 } as const; ··· 357 368 type: 'dictionary', 358 369 contains: { 359 370 type: 'Enum', 371 + enum: ['Success', 'Warning', 'Error'], 360 372 }, 361 373 }, 362 374 dictionaryWithEnumFromDescription: { ··· 370 382 type: 'array', 371 383 contains: { 372 384 type: 'Enum', 385 + enum: ['Success', 'Warning', 'Error'], 373 386 }, 374 387 }, 375 388 arrayWithDescription: { ··· 650 663 651 664 export const $Enum1 = { 652 665 type: 'Enum', 666 + enum: ['Bird', 'Dog'], 653 667 } as const; 654 668 655 669 export const $ConstValue = { ··· 1126 1140 properties: { 1127 1141 page: { 1128 1142 type: 'number', 1143 + default: 0, 1129 1144 format: 'int32', 1130 1145 minimum: 0, 1131 1146 }, ··· 1273 1288 type: 'string', 1274 1289 }, 1275 1290 }, 1291 + default: null, 1276 1292 isNullable: true, 1277 1293 } as const; 1278 1294 ··· 1291 1307 properties: { 1292 1308 foo: { 1293 1309 type: 'Enum', 1310 + enum: ['Bar'], 1294 1311 isRequired: true, 1295 1312 }, 1296 1313 }, ··· 1299 1316 properties: { 1300 1317 foo: { 1301 1318 type: 'Enum', 1319 + enum: ['Baz'], 1302 1320 isRequired: true, 1303 1321 }, 1304 1322 }, ··· 1307 1325 properties: { 1308 1326 foo: { 1309 1327 type: 'Enum', 1328 + enum: ['Qux'], 1310 1329 isRequired: true, 1311 1330 }, 1312 1331 }, ··· 1320 1339 }, 1321 1340 foo: { 1322 1341 type: 'Enum', 1342 + enum: ['Quux'], 1323 1343 isRequired: true, 1324 1344 }, 1325 1345 }, ··· 1344 1364 }, 1345 1365 foo: { 1346 1366 type: 'Enum', 1367 + enum: ['Corge'], 1347 1368 isRequired: true, 1348 1369 }, 1349 1370 }, ··· 1353 1374 1354 1375 export const $ModelWithNestedArrayEnumsDataFoo = { 1355 1376 type: 'Enum', 1377 + enum: ['foo', 'bar'], 1356 1378 } as const; 1357 1379 1358 1380 export const $ModelWithNestedArrayEnumsDataBar = { 1359 1381 type: 'Enum', 1382 + enum: ['baz', 'qux'], 1360 1383 } as const; 1361 1384 1362 1385 export const $ModelWithNestedArrayEnumsData = {
+10 -5
test/spec/v3.json
··· 1799 1799 -1.1, 1800 1800 -1.20, 1801 1801 -1.300 1802 - ] 1802 + ], 1803 + "default": 200 1803 1804 }, 1804 1805 "EnumFromDescription": { 1805 1806 "description": "Success=1,Warning=2,Error=3", ··· 1842 1843 "type": "array", 1843 1844 "items": { 1844 1845 "type": "string" 1845 - } 1846 + }, 1847 + "default": ["test"] 1846 1848 }, 1847 1849 "ArrayWithReferences": { 1848 1850 "description": "This is a simple array with references", ··· 1885 1887 "type": "object", 1886 1888 "properties": { 1887 1889 "foo": { 1888 - "type": "string" 1890 + "type": "string", 1891 + "default": "test" 1889 1892 } 1890 1893 } 1891 1894 }, ··· 2930 2933 "page": { 2931 2934 "minimum": 0, 2932 2935 "type": "integer", 2933 - "format": "int32" 2936 + "format": "int32", 2937 + "default": 0 2934 2938 }, 2935 2939 "size": { 2936 2940 "minimum": 1, ··· 3067 3071 "foo": { 3068 3072 "type": "string" 3069 3073 } 3070 - } 3074 + }, 3075 + "default": null 3071 3076 }, 3072 3077 "ModelWithNullableObject": { 3073 3078 "type": "object",