File tree 4 files changed +35
-4
lines changed
programs/enums-value-in-interface
4 files changed +35
-4
lines changed Original file line number Diff line number Diff line change
1
+ export enum A {
2
+ B ,
3
+ C ,
4
+ D ,
5
+ } ;
6
+
7
+ export interface MyObject {
8
+ code : A . B ;
9
+ } ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "$schema" : " http://json-schema.org/draft-04/schema#" ,
3
+ "definitions" : {
4
+ "A.B" : {
5
+ "enum" : [
6
+ 0
7
+ ],
8
+ "type" : " number"
9
+ }
10
+ },
11
+ "properties" : {
12
+ "code" : {
13
+ "$ref" : " #/definitions/A.B"
14
+ }
15
+ },
16
+ "required" : [
17
+ " code"
18
+ ],
19
+ "type" : " object"
20
+ }
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ describe("schema", () => {
87
87
assertSchema ( "enums-number-initialized" , "main.ts" , "Enum" ) ;
88
88
assertSchema ( "enums-compiled-compute" , "main.ts" , "Enum" ) ;
89
89
assertSchema ( "enums-mixed" , "main.ts" , "MyObject" ) ;
90
+ assertSchema ( "enums-value-in-interface" , "main.ts" , "MyObject" ) ;
90
91
assertSchema ( "string-literals" , "main.ts" , "MyObject" ) ;
91
92
assertSchema ( "string-literals-inline" , "main.ts" , "MyObject" ) ;
92
93
@@ -111,7 +112,7 @@ describe("schema", () => {
111
112
assertSchema ( "imports" , "main.ts" , "MyObject" ) ;
112
113
113
114
assertSchema ( "extra-properties" , "main.ts" , "MyObject" ) ;
114
-
115
+
115
116
assertSchema ( "generate-all-types" , "main.ts" , "*" ) ;
116
117
117
118
/**
Original file line number Diff line number Diff line change @@ -361,8 +361,9 @@ export class JsonSchemaGenerator {
361
361
private getEnumDefinition ( clazzType : ts . Type , tc : ts . TypeChecker , definition : Definition ) : Definition {
362
362
const node = clazzType . getSymbol ( ) . getDeclarations ( ) [ 0 ] ;
363
363
const fullName = tc . typeToString ( clazzType , undefined , ts . TypeFormatFlags . UseFullyQualifiedType ) ;
364
- const enm = < ts . EnumDeclaration > node ;
365
-
364
+ const members : ts . EnumMember [ ] = node . kind === ts . SyntaxKind . EnumDeclaration ?
365
+ ( node as ts . EnumDeclaration ) . members :
366
+ [ node as ts . EnumMember ] ;
366
367
var enumValues : ( number | boolean | string | null ) [ ] = [ ] ;
367
368
let enumTypes : string [ ] = [ ] ;
368
369
@@ -372,7 +373,7 @@ export class JsonSchemaGenerator {
372
373
}
373
374
} ;
374
375
375
- enm . members . forEach ( member => {
376
+ members . forEach ( member => {
376
377
const caseLabel = ( < ts . Identifier > member . name ) . text ;
377
378
const constantValue = tc . getConstantValue ( member ) ;
378
379
if ( constantValue !== undefined ) {
You can’t perform that action at this time.
0 commit comments