@@ -11,6 +11,7 @@ const vm = require("vm");
11
11
const REGEX_FILE_NAME_OR_SPACE = / ( \b i m p o r t \( " .* ?" \) | " .* ?" ) \. | / g;
12
12
const REGEX_TSCONFIG_NAME = / ^ .* \. j s o n $ / ;
13
13
const REGEX_TJS_JSDOC = / ^ - ( [ \w ] + ) \s + ( \S | \S [ \s \S ] * \S ) \s * $ / g;
14
+ const NUMERIC_INDEX_PATTERN = "^[0-9]+$" ;
14
15
15
16
export function getDefaultArgs ( ) : Args {
16
17
return {
@@ -88,7 +89,7 @@ export type Definition = {
88
89
propertyOrder ?: string [ ] ,
89
90
properties ?: { [ key : string ] : any } ,
90
91
defaultProperties ?: string [ ] ,
91
-
92
+ patternProperties ?: { [ pattern : string ] : Definition } ,
92
93
typeof ?: "function"
93
94
} ;
94
95
@@ -419,8 +420,17 @@ export class JsonSchemaGenerator {
419
420
definition . type = typeof value ;
420
421
definition . enum = [ value ] ;
421
422
} else if ( arrayType !== undefined ) {
422
- definition . type = "array" ;
423
- definition . items = this . getTypeDefinition ( arrayType ) ;
423
+ if ( ( propertyType . flags & ts . TypeFlags . Object ) &&
424
+ ( ( propertyType as ts . ObjectType ) . objectFlags & ( ts . ObjectFlags . Anonymous | ts . ObjectFlags . Interface ) ) ) {
425
+ definition . type = "object" ;
426
+ definition . additionalProperties = false ;
427
+ definition . patternProperties = {
428
+ [ NUMERIC_INDEX_PATTERN ] : this . getTypeDefinition ( arrayType )
429
+ } ;
430
+ } else {
431
+ definition . type = "array" ;
432
+ definition . items = this . getTypeDefinition ( arrayType ) ;
433
+ }
424
434
} else {
425
435
// Report that type could not be processed
426
436
const error = new TypeError ( "Unsupported type: " + propertyTypeString ) ;
0 commit comments