@@ -22,11 +22,29 @@ export function getDefaultArgs() {
22
22
}
23
23
24
24
export class JsonSchemaGenerator {
25
- private static validationKeywords = [
26
- "ignore" , "description" , "type" , "minimum" , "exclusiveMinimum" , "maximum" ,
27
- "exclusiveMaximum" , "multipleOf" , "minLength" , "maxLength" , "format" ,
28
- "pattern" , "minItems" , "maxItems" , "uniqueItems" , "default" ,
29
- "additionalProperties" , "enum" ] ;
25
+ /**
26
+ * JSDoc keywords that should be used to annotate the JSON schema.
27
+ */
28
+ private static validationKeywords = {
29
+ ignore : true ,
30
+ description : true ,
31
+ type : true ,
32
+ minimum : true ,
33
+ exclusiveMinimum : true ,
34
+ maximum : true ,
35
+ exclusiveMaximum : true ,
36
+ multipleOf : true ,
37
+ minLength : true ,
38
+ maxLength : true ,
39
+ format : true ,
40
+ pattern : true ,
41
+ minItems : true ,
42
+ maxItems : true ,
43
+ uniqueItems : true ,
44
+ default : true ,
45
+ additionalProperties : true ,
46
+ enum : true
47
+ } ;
30
48
31
49
private allSymbols : { [ name : string ] : ts . Type } ;
32
50
private inheritingTypes : { [ baseName : string ] : string [ ] } ;
@@ -73,7 +91,7 @@ export class JsonSchemaGenerator {
73
91
// jsdocs are separate from comments
74
92
const jsdocs = symbol . getJsDocTags ( ) ;
75
93
jsdocs . forEach ( doc => {
76
- if ( JsonSchemaGenerator . validationKeywords . indexOf ( doc . name ) > 0 || JsonSchemaGenerator . validationKeywords . indexOf ( "TJS-" + doc . name ) >= 0 ) {
94
+ if ( JsonSchemaGenerator . validationKeywords [ doc . name ] || JsonSchemaGenerator . validationKeywords [ "TJS-" + doc . name ] ) {
77
95
definition [ doc . name ] = this . parseValue ( doc . text ) ;
78
96
} else {
79
97
// special annotations
@@ -453,14 +471,14 @@ export class JsonSchemaGenerator {
453
471
}
454
472
}
455
473
456
- private simpleTypesAllowedProperties = [
457
- " type" ,
458
- " description"
459
- ] ;
474
+ private simpleTypesAllowedProperties = {
475
+ type : true ,
476
+ description : true
477
+ } ;
460
478
461
479
private addSimpleType ( def : any , type : string ) {
462
480
for ( let k in def ) {
463
- if ( this . simpleTypesAllowedProperties . indexOf ( k ) === - 1 ) {
481
+ if ( ! this . simpleTypesAllowedProperties [ k ] ) {
464
482
return false ;
465
483
}
466
484
}
0 commit comments