@@ -9,11 +9,15 @@ const ajv = new Ajv();
9
9
10
10
const base = "test/programs/" ;
11
11
12
- export function assertSchema ( group : string , name : string , type : string , settings ? : any , compilerOptions ?: CompilerOptions ) {
12
+ export function assertSchema ( group : string , name : string , type : string , settings : any = { } , compilerOptions ?: CompilerOptions ) {
13
13
it ( group + " should create correct schema" , function ( ) {
14
- if ( ! settings ) {
15
- settings = TJS . getDefaultArgs ( ) ;
16
- settings . generateRequired = true ;
14
+ const defaults = TJS . getDefaultArgs ( ) ;
15
+ defaults . generateRequired = true ;
16
+
17
+ for ( let pref in defaults ) {
18
+ if ( ! ( pref in settings ) ) {
19
+ settings [ pref ] = defaults [ pref ] ;
20
+ }
17
21
}
18
22
19
23
const actual = TJS . generateSchema ( TJS . getProgramFromFiles ( [ resolve ( base + group + "/" + name ) ] , compilerOptions ) , type , settings ) ;
@@ -37,9 +41,9 @@ describe("schema", function () {
37
41
assertSchema ( "interface-single" , "main.ts" , "MyObject" ) ;
38
42
assertSchema ( "interface-multi" , "main.ts" , "MyObject" ) ;
39
43
40
- let settings = TJS . getDefaultArgs ( ) ;
41
- settings . useRootRef = true ;
42
- assertSchema ( "interface-recursion" , "main.ts" , "MyObject" , settings ) ; // this sample needs rootRef
44
+ assertSchema ( "interface-recursion" , "main.ts" , "MyObject" , {
45
+ useRootRef : true
46
+ } ) ;
43
47
44
48
assertSchema ( "module-interface-single" , "main.ts" , "MyObject" ) ;
45
49
@@ -59,12 +63,6 @@ describe("schema", function () {
59
63
60
64
assertSchema ( "namespace" , "main.ts" , "Type" ) ;
61
65
62
- assertSchema ( "type-union" , "main.ts" , "MyObject" ) ;
63
- assertSchema ( "type-intersection" , "main.ts" , "MyObject" ) ;
64
-
65
- assertSchema ( "type-aliases" , "main.ts" , "MyString" ) ;
66
- assertSchema ( "type-aliases-fixed-size-array" , "main.ts" , "MyFixedSizeArray" ) ;
67
- assertSchema ( "type-aliases-multitype-array" , "main.ts" , "MyArray" ) ;
68
66
assertSchema ( "type-anonymous" , "main.ts" , "MyObject" ) ;
69
67
assertSchema ( "type-primitives" , "main.ts" , "MyObject" ) ;
70
68
assertSchema ( "type-nullable" , "main.ts" , "MyObject" ) ;
@@ -74,6 +72,49 @@ describe("schema", function () {
74
72
assertSchema ( "comments" , "main.ts" , "MyObject" ) ;
75
73
assertSchema ( "comments-override" , "main.ts" , "MyObject" ) ;
76
74
75
+ /**
76
+ * Type aliases
77
+ */
78
+
79
+ assertSchema ( "type-alias-single" , "main.ts" , "MyString" ) ;
80
+ assertSchema ( "type-aliases" , "main.ts" , "MyObject" , {
81
+ useTypeAliasRef : true
82
+ } ) ;
83
+ assertSchema ( "type-aliases-fixed-size-array" , "main.ts" , "MyFixedSizeArray" ) ;
84
+ assertSchema ( "type-aliases-multitype-array" , "main.ts" , "MyArray" ) ;
85
+ assertSchema ( "type-aliases-local-namsepace" , "main.ts" , "MyObject" , {
86
+ useTypeAliasRef : true
87
+ } ) ;
88
+
89
+ assertSchema ( "type-aliases-alias-ref" , "main.ts" , "MyAlias" , {
90
+ useTypeAliasRef : true ,
91
+ useRootRef : false
92
+ } ) ;
93
+ // disabled beacuse of #80
94
+ // assertSchema("type-aliases-alias-ref-topref", "main.ts", "MyAlias", {
95
+ // useTypeAliasRef: true,
96
+ // useRootRef: true
97
+ // });
98
+ assertSchema ( "type-aliases-recursive-object-topref" , "main.ts" , "MyObject" , {
99
+ useTypeAliasRef : true ,
100
+ useRootRef : true
101
+ } ) ;
102
+ // disabled beacuse of #80
103
+ // assertSchema("type-aliases-recursive-alias-topref", "main.ts", "MyAlias", {
104
+ // useTypeAliasRef: true,
105
+ // useRootRef: true
106
+ // });
107
+ assertSchema ( "type-no-aliases-recursive-topref" , "main.ts" , "MyAlias" , {
108
+ useTypeAliasRef : false ,
109
+ useRootRef : true
110
+ } ) ;
111
+
112
+ /**
113
+ * unions and intersections
114
+ */
115
+
116
+ assertSchema ( "type-union" , "main.ts" , "MyObject" ) ;
117
+ assertSchema ( "type-intersection" , "main.ts" , "MyObject" ) ;
77
118
assertSchema ( "type-union-tagged" , "main.ts" , "Shape" ) ;
78
119
assertSchema ( "type-aliases-union-namespace" , "main.ts" , "MyModel" ) ;
79
120
0 commit comments