@@ -9,7 +9,13 @@ const ajv = new Ajv();
9
9
10
10
const BASE = "test/programs/" ;
11
11
12
- export function assertSchema ( group : string , type : string , settings : TJS . PartialArgs = { } , compilerOptions ?: TJS . CompilerOptions , only ?: boolean ) {
12
+ export function assertSchema (
13
+ group : string ,
14
+ type : string ,
15
+ settings : TJS . PartialArgs = { } ,
16
+ compilerOptions ?: TJS . CompilerOptions ,
17
+ only ?: boolean
18
+ ) {
13
19
const run = only ? it . only : it ;
14
20
15
21
run ( group + " should create correct schema" , ( ) => {
@@ -36,36 +42,49 @@ export function assertSchema(group: string, type: string, settings: TJS.PartialA
36
42
} ) ;
37
43
}
38
44
39
- export function assertSchemas ( group : string , type : string , settings : TJS . PartialArgs = { } , compilerOptions ?: TJS . CompilerOptions ) {
45
+ export function assertSchemas (
46
+ group : string ,
47
+ type : string ,
48
+ settings : TJS . PartialArgs = { } ,
49
+ compilerOptions ?: TJS . CompilerOptions
50
+ ) {
40
51
it ( group + " should create correct schema" , ( ) => {
41
52
if ( ! ( "required" in settings ) ) {
42
53
settings . required = true ;
43
54
}
44
55
45
- const generator = TJS . buildGenerator ( TJS . getProgramFromFiles ( [ resolve ( BASE + group + "/main.ts" ) ] , compilerOptions ) , settings ) ;
56
+ const generator = TJS . buildGenerator (
57
+ TJS . getProgramFromFiles ( [ resolve ( BASE + group + "/main.ts" ) ] , compilerOptions ) ,
58
+ settings
59
+ ) ;
46
60
const symbols = generator ! . getSymbols ( type ) ;
47
61
48
62
for ( let symbol of symbols ) {
49
- const actual = generator ! . getSchemaForSymbol ( symbol . name ) ;
63
+ const actual = generator ! . getSchemaForSymbol ( symbol . name ) ;
50
64
51
- // writeFileSync(BASE + group + `/schema.${symbol.name}.json`, JSON.stringify(actual, null, 4) + "\n\n");
65
+ // writeFileSync(BASE + group + `/schema.${symbol.name}.json`, JSON.stringify(actual, null, 4) + "\n\n");
52
66
53
- const file = readFileSync ( BASE + group + `/schema.${ symbol . name } .json` , "utf8" ) ;
54
- const expected = JSON . parse ( file ) ;
67
+ const file = readFileSync ( BASE + group + `/schema.${ symbol . name } .json` , "utf8" ) ;
68
+ const expected = JSON . parse ( file ) ;
55
69
56
- assert . isObject ( actual ) ;
57
- assert . deepEqual ( actual , expected , "The schema is not as expected" ) ;
70
+ assert . isObject ( actual ) ;
71
+ assert . deepEqual ( actual , expected , "The schema is not as expected" ) ;
58
72
59
- // test against the meta schema
60
- if ( actual !== null ) {
61
- ajv . validateSchema ( actual ) ;
62
- assert . equal ( ajv . errors , null , "The schema is not valid" ) ;
63
- }
73
+ // test against the meta schema
74
+ if ( actual !== null ) {
75
+ ajv . validateSchema ( actual ) ;
76
+ assert . equal ( ajv . errors , null , "The schema is not valid" ) ;
77
+ }
64
78
}
65
79
} ) ;
66
80
}
67
81
68
- export function assertRejection ( group : string , type : string , settings : TJS . PartialArgs = { } , compilerOptions ?: TJS . CompilerOptions ) {
82
+ export function assertRejection (
83
+ group : string ,
84
+ type : string ,
85
+ settings : TJS . PartialArgs = { } ,
86
+ compilerOptions ?: TJS . CompilerOptions
87
+ ) {
69
88
it ( group + " should reject input" , ( ) => {
70
89
let schema = null ;
71
90
assert . throws ( ( ) => {
@@ -122,27 +141,26 @@ describe("interfaces", () => {
122
141
$schema : "http://json-schema.org/draft-07/schema#" ,
123
142
definitions : {
124
143
Some : {
125
- type : "string"
126
- }
144
+ type : "string" ,
145
+ } ,
127
146
} ,
128
147
properties : {
129
148
some : {
130
- $ref : "#/definitions/Some"
131
- }
149
+ $ref : "#/definitions/Some" ,
150
+ } ,
132
151
} ,
133
- type : "object"
152
+ type : "object" ,
134
153
} ) ;
135
154
}
136
155
} ) ;
137
156
} ) ;
138
157
139
158
describe ( "schema" , ( ) => {
140
-
141
159
describe ( "type aliases" , ( ) => {
142
160
assertSchema ( "type-alias-single" , "MyString" ) ;
143
161
assertSchema ( "type-alias-single-annotated" , "MyString" ) ;
144
162
assertSchema ( "type-aliases" , "MyObject" , {
145
- aliasRef : true
163
+ aliasRef : true ,
146
164
} ) ;
147
165
assertSchema ( "type-aliases-fixed-size-array" , "MyFixedSizeArray" ) ;
148
166
assertSchema ( "type-aliases-multitype-array" , "MyArray" ) ;
@@ -151,12 +169,12 @@ describe("schema", () => {
151
169
strictNullChecks : true ,
152
170
} ) ;
153
171
assertSchema ( "type-aliases-partial" , "MyObject" , {
154
- aliasRef : true
172
+ aliasRef : true ,
155
173
} ) ;
156
174
157
175
assertSchema ( "type-aliases-alias-ref" , "MyAlias" , {
158
176
aliasRef : true ,
159
- topRef : false
177
+ topRef : false ,
160
178
} ) ;
161
179
// disabled beacuse of #80
162
180
// assertSchema("type-aliases-alias-ref-topref", "MyAlias", {
@@ -165,7 +183,7 @@ describe("schema", () => {
165
183
// });
166
184
assertSchema ( "type-aliases-recursive-object-topref" , "MyObject" , {
167
185
aliasRef : true ,
168
- topRef : true
186
+ topRef : true ,
169
187
} ) ;
170
188
// disabled beacuse of #80
171
189
// assertSchema("type-aliases-recursive-alias-topref", "MyAlias", {
@@ -174,7 +192,7 @@ describe("schema", () => {
174
192
// });
175
193
assertSchema ( "type-no-aliases-recursive-topref" , "MyAlias" , {
176
194
aliasRef : false ,
177
- topRef : true
195
+ topRef : true ,
178
196
} ) ;
179
197
180
198
assertSchema ( "type-mapped-types" , "MyMappedType" ) ;
@@ -206,7 +224,7 @@ describe("schema", () => {
206
224
describe ( "unions and intersections" , ( ) => {
207
225
assertSchema ( "type-union" , "MyObject" ) ;
208
226
assertSchema ( "type-intersection" , "MyObject" , {
209
- noExtraProps : true
227
+ noExtraProps : true ,
210
228
} ) ;
211
229
assertSchema ( "type-union-tagged" , "Shape" ) ;
212
230
assertSchema ( "type-aliases-union-namespace" , "MyModel" ) ;
@@ -217,15 +235,15 @@ describe("schema", () => {
217
235
assertSchema ( "annotation-default" , "MyObject" ) ;
218
236
assertSchema ( "annotation-ref" , "MyObject" ) ;
219
237
assertSchema ( "annotation-tjs" , "MyObject" , {
220
- validationKeywords : [ "hide" ]
238
+ validationKeywords : [ "hide" ] ,
221
239
} ) ;
222
240
assertSchema ( "annotation-id" , "MyObject" ) ;
223
241
assertSchema ( "annotation-items" , "MyObject" ) ;
224
242
225
- assertSchema ( "typeof-keyword" , "MyObject" , { typeOfKeyword : true } ) ;
243
+ assertSchema ( "typeof-keyword" , "MyObject" , { typeOfKeyword : true } ) ;
226
244
227
245
assertSchema ( "user-validation-keywords" , "MyObject" , {
228
- validationKeywords : [ "chance" , "important" ]
246
+ validationKeywords : [ "chance" , "important" ] ,
229
247
} ) ;
230
248
} ) ;
231
249
@@ -236,9 +254,9 @@ describe("schema", () => {
236
254
assertSchema ( "generic-multiargs" , "MyObject" ) ;
237
255
assertSchema ( "generic-anonymous" , "MyObject" ) ;
238
256
assertSchema ( "generic-recursive" , "MyObject" , {
239
- topRef : true
257
+ topRef : true ,
240
258
} ) ;
241
- if ( + typescriptVersionMajorMinor < 3.7 ) {
259
+ if ( + typescriptVersionMajorMinor < 3.7 ) {
242
260
assertSchema ( "generic-hell" , "MyObject" ) ;
243
261
}
244
262
} ) ;
@@ -247,7 +265,7 @@ describe("schema", () => {
247
265
assertSchema ( "comments" , "MyObject" ) ;
248
266
assertSchema ( "comments-override" , "MyObject" ) ;
249
267
assertSchema ( "comments-imports" , "MyObject" , {
250
- aliasRef : true
268
+ aliasRef : true ,
251
269
} ) ;
252
270
} ) ;
253
271
@@ -275,7 +293,7 @@ describe("schema", () => {
275
293
assertSchema ( "interface-extends" , "MyObject" ) ;
276
294
277
295
assertSchema ( "interface-recursion" , "MyObject" , {
278
- topRef : true
296
+ topRef : true ,
279
297
} ) ;
280
298
281
299
assertSchema ( "module-interface-single" , "MyObject" ) ;
@@ -310,7 +328,7 @@ describe("schema", () => {
310
328
describe ( "dates" , ( ) => {
311
329
assertSchema ( "dates" , "MyObject" ) ;
312
330
assertRejection ( "dates" , "MyObject" , {
313
- rejectDateType : true
331
+ rejectDateType : true ,
314
332
} ) ;
315
333
} ) ;
316
334
@@ -322,16 +340,16 @@ describe("schema", () => {
322
340
323
341
describe ( "uniqueNames" , ( ) => {
324
342
assertSchemas ( "unique-names" , "MyObject" , {
325
- uniqueNames : true
343
+ uniqueNames : true ,
326
344
} ) ;
327
345
328
346
// It should throw an error if there are two definitions for the top-level ref
329
347
assertRejection ( "unique-names" , "MyObject" , {
330
- uniqueNames : true
348
+ uniqueNames : true ,
331
349
} ) ;
332
350
333
351
assertSchema ( "unique-names-multiple-subdefinitions" , "MyObject" , {
334
- uniqueNames : true
352
+ uniqueNames : true ,
335
353
} ) ;
336
354
} ) ;
337
355
@@ -342,27 +360,27 @@ describe("schema", () => {
342
360
assertSchema ( "optionals-derived" , "MyDerived" ) ;
343
361
344
362
assertSchema ( "strict-null-checks" , "MyObject" , undefined , {
345
- strictNullChecks : true
363
+ strictNullChecks : true ,
346
364
} ) ;
347
365
348
366
assertSchema ( "imports" , "MyObject" ) ;
349
367
350
368
assertSchema ( "generate-all-types" , "*" ) ;
351
369
352
370
assertSchema ( "private-members" , "MyObject" , {
353
- excludePrivate : true
371
+ excludePrivate : true ,
354
372
} ) ;
355
373
356
374
assertSchema ( "builtin-names" , "Ext.Foo" ) ;
357
375
358
376
assertSchema ( "user-symbols" , "*" ) ;
359
377
360
378
assertSchemas ( "argument-id" , "MyObject" , {
361
- id : "someSchemaId"
379
+ id : "someSchemaId" ,
362
380
} ) ;
363
381
364
382
assertSchemas ( "type-default-number-as-integer" , "*" , {
365
- defaultNumberType : "integer"
383
+ defaultNumberType : "integer" ,
366
384
} ) ;
367
385
} ) ;
368
386
@@ -385,9 +403,9 @@ describe("tsconfig.json", () => {
385
403
}
386
404
} ) ;
387
405
it ( "should support includeOnlyFiles with tsconfig.json" , ( ) => {
388
- const program = TJS . programFromConfig (
389
- resolve ( BASE + "tsconfig/tsconfig.json" ) , [ resolve ( BASE + "tsconfig/ includedAlways.ts") ]
390
- ) ;
406
+ const program = TJS . programFromConfig ( resolve ( BASE + "tsconfig/tsconfig.json" ) , [
407
+ resolve ( BASE + "tsconfig/includedAlways.ts" ) ,
408
+ ] ) ;
391
409
const generator = TJS . buildGenerator ( program ) ;
392
410
assert ( generator !== null ) ;
393
411
assert . instanceOf ( generator , TJS . JsonSchemaGenerator ) ;
0 commit comments