@@ -118,8 +118,10 @@ export class JsonSchemaGenerator {
118
118
// jsdocs are separate from comments
119
119
const jsdocs = symbol . getJsDocTags ( ) ;
120
120
jsdocs . forEach ( doc => {
121
- if ( JsonSchemaGenerator . validationKeywords [ doc . name ] || JsonSchemaGenerator . validationKeywords [ "TJS-" + doc . name ] ) {
122
- definition [ doc . name ] = this . parseValue ( doc . text ) ;
121
+ // if we have @TJS -... annotations, we have to parse them
122
+ const [ name , text ] = doc . name === "TJS" ? / ^ - ( [ \w ] + ) \s ( [ \w ] + ) / g. exec ( doc . text ) . slice ( 1 , 3 ) : [ doc . name , doc . text ] ;
123
+ if ( JsonSchemaGenerator . validationKeywords [ name ] ) {
124
+ definition [ name ] = this . parseValue ( text ) ;
123
125
} else {
124
126
// special annotations
125
127
otherAnnotations [ doc . name ] = true ;
@@ -429,20 +431,20 @@ export class JsonSchemaGenerator {
429
431
if ( props . length === 0 && clazz . members && clazz . members . length === 1 && clazz . members [ 0 ] . kind === ts . SyntaxKind . IndexSignature ) {
430
432
// for case "array-types"
431
433
const indexSignature = < ts . IndexSignatureDeclaration > clazz . members [ 0 ] ;
432
- if ( indexSignature . parameters . length !== 1 ) {
434
+ if ( indexSignature . parameters . length !== 1 ) {
433
435
throw "Not supported: IndexSignatureDeclaration parameters.length != 1" ;
434
436
}
435
437
const indexSymbol : ts . Symbol = ( < any > indexSignature . parameters [ 0 ] ) . symbol ;
436
438
const indexType = tc . getTypeOfSymbolAtLocation ( indexSymbol , node ) ;
437
439
const isStringIndexed = ( indexType . flags === ts . TypeFlags . String ) ;
438
- if ( indexType . flags !== ts . TypeFlags . Number && ! isStringIndexed ) {
440
+ if ( indexType . flags !== ts . TypeFlags . Number && ! isStringIndexed ) {
439
441
throw "Not supported: IndexSignatureDeclaration with index symbol other than a number or a string" ;
440
442
}
441
443
442
444
const typ = tc . getTypeAtLocation ( indexSignature . type ) ;
443
445
const def = this . getTypeDefinition ( typ , tc , undefined , "anyOf" ) ;
444
446
445
- if ( isStringIndexed ) {
447
+ if ( isStringIndexed ) {
446
448
definition . type = "object" ;
447
449
definition . additionalProperties = def ;
448
450
} else {
@@ -611,7 +613,7 @@ export class JsonSchemaGenerator {
611
613
definition . title = fullTypeName ;
612
614
}
613
615
}
614
- const node = symbol ? symbol . getDeclarations ( ) [ 0 ] : null ;
616
+ const node = symbol && symbol . getDeclarations ( ) !== undefined ? symbol . getDeclarations ( ) [ 0 ] : null ;
615
617
if ( typ . flags & ts . TypeFlags . Union ) {
616
618
this . getUnionDefinition ( typ as ts . UnionType , prop , tc , unionModifier , definition ) ;
617
619
} else if ( typ . flags & ts . TypeFlags . Intersection ) {
@@ -624,6 +626,10 @@ export class JsonSchemaGenerator {
624
626
this . getDefinitionForRootType ( typ , tc , reffedType , definition ) ;
625
627
} else if ( node && ( node . kind === ts . SyntaxKind . EnumDeclaration || node . kind === ts . SyntaxKind . EnumMember ) ) {
626
628
this . getEnumDefinition ( typ , tc , definition ) ;
629
+ } else if ( symbol && symbol . flags & ts . SymbolFlags . TypeLiteral && Object . keys ( symbol . members ) . length === 0 ) {
630
+ // {} is TypeLiteral with no members. Need special case because it doesn't have declarations.
631
+ definition . type = "object" ;
632
+ definition . properties = { } ;
627
633
} else {
628
634
this . getClassDefinition ( typ , tc , definition ) ;
629
635
}
0 commit comments