@@ -390,6 +390,76 @@ describe('introspection', () => {
390
390
391
391
expect ( formattedDeclaration ) . toMatchSnapshot ( ) ;
392
392
} ) ;
393
+
394
+ test ( 'when using the same schema reference multiple times, it is always resolved inline' , async ( ) => {
395
+ const reusedSchema = z . object ( { id : z . string ( ) } ) ;
396
+
397
+ const router = OneSchemaRouter . create ( {
398
+ using : new Router ( ) ,
399
+ introspection : {
400
+ route : '/private/introspection' ,
401
+ serviceVersion : '123' ,
402
+ } ,
403
+ } ) . declare ( {
404
+ route : 'POST /items' ,
405
+ name : 'createItem' ,
406
+ request : z . object ( { } ) ,
407
+ response : z . object ( {
408
+ resProp1 : reusedSchema ,
409
+ resProp2 : reusedSchema ,
410
+ } ) ,
411
+ } ) ;
412
+
413
+ const { client } = serve ( router ) ;
414
+
415
+ const introspectionResult = await client . get ( '/private/introspection' ) ;
416
+
417
+ console . log ( JSON . stringify ( introspectionResult . data , null , 2 ) ) ;
418
+
419
+ expect ( introspectionResult . data . schema ) . toStrictEqual ( {
420
+ Endpoints : {
421
+ 'POST /items' : {
422
+ Name : 'createItem' ,
423
+ Request : {
424
+ type : 'object' ,
425
+ properties : { } ,
426
+ additionalProperties : false ,
427
+ $schema : 'http://json-schema.org/draft-07/schema#' ,
428
+ } ,
429
+ Response : {
430
+ type : 'object' ,
431
+ properties : {
432
+ // resProp1 and resProp2 should be inlined, even though they have identical
433
+ // schemas defined using the same reference.
434
+ resProp1 : {
435
+ type : 'object' ,
436
+ properties : {
437
+ id : {
438
+ type : 'string' ,
439
+ } ,
440
+ } ,
441
+ required : [ 'id' ] ,
442
+ additionalProperties : false ,
443
+ } ,
444
+ resProp2 : {
445
+ type : 'object' ,
446
+ properties : {
447
+ id : {
448
+ type : 'string' ,
449
+ } ,
450
+ } ,
451
+ required : [ 'id' ] ,
452
+ additionalProperties : false ,
453
+ } ,
454
+ } ,
455
+ required : [ 'resProp1' , 'resProp2' ] ,
456
+ additionalProperties : false ,
457
+ $schema : 'http://json-schema.org/draft-07/schema#' ,
458
+ } ,
459
+ } ,
460
+ } ,
461
+ } ) ;
462
+ } ) ;
393
463
} ) ;
394
464
395
465
test ( 'declaring multiple routes with the same name results in an error' , ( ) => {
0 commit comments