@@ -353,12 +353,30 @@ describe("JTDSchemaType", () => {
353
353
} )
354
354
355
355
it ( "should typecheck ref schemas" , ( ) => {
356
+ const ajv = new _Ajv ( )
356
357
const refs : JTDSchemaType < number [ ] , { num : number } > = {
357
358
definitions : {
358
359
num : { type : "float64" } ,
359
360
} ,
360
361
elements : { ref : "num" } ,
361
362
}
363
+
364
+ // test that ajv.validate captures ref data type
365
+ const validData : unknown = [ 0 ]
366
+ if ( ajv . validate ( refs , validData ) ) {
367
+ const postValidation : number [ ] = validData
368
+ postValidation [ 0 ] . should . equal ( 0 )
369
+ }
370
+ should . not . exist ( ajv . errors )
371
+
372
+ // test that ajv.compile captures ref data type
373
+ const validate = ajv . compile ( refs )
374
+ if ( validate ( validData ) ) {
375
+ const postValidation : number [ ] = validData
376
+ postValidation [ 0 ] . should . equal ( 0 )
377
+ }
378
+ should . not . exist ( validate . errors )
379
+
362
380
const missingDef : JTDSchemaType < number [ ] , { num : number } > = {
363
381
// @ts -expect-error
364
382
definitions : { } ,
@@ -393,6 +411,35 @@ describe("JTDSchemaType", () => {
393
411
void [ refs , missingDef , missingType , nullRefs , refsNullOne , refsNullTwo ]
394
412
} )
395
413
414
+ it ( "should typecheck nested ref schemas" , ( ) => {
415
+ const ajv = new _Ajv ( )
416
+ const schema : JTDSchemaType < { str : string ; ref : number } , { num : number } > = {
417
+ definitions : {
418
+ num : { type : "int32" } ,
419
+ } ,
420
+ properties : {
421
+ ref : { ref : "num" } ,
422
+ str : { type : "string" } ,
423
+ } ,
424
+ }
425
+
426
+ // test that ajv.validate captures ref data type
427
+ const validData : unknown = { str : "" , ref : 0 }
428
+ if ( ajv . validate ( schema , validData ) ) {
429
+ const str : string = validData . str
430
+ str . should . equal ( "" )
431
+ }
432
+ should . not . exist ( ajv . errors )
433
+
434
+ // test that ajv.compile captures ref data type
435
+ const validate = ajv . compile ( schema )
436
+ if ( validate ( validData ) ) {
437
+ const str : string = validData . str
438
+ str . should . equal ( "" )
439
+ }
440
+ should . not . exist ( validate . errors )
441
+ } )
442
+
396
443
it ( "should typecheck metadata schemas" , ( ) => {
397
444
const meta : JTDSchemaType < number > = { type : "float32" , metadata : { key : "val" } }
398
445
const emptyMeta : JTDSchemaType < unknown > = { metadata : { key : "val" } }
0 commit comments