@@ -554,13 +554,21 @@ describe('ObjectSchema', () => {
554554 describe ( 'extend' , ( ) => {
555555 it ( 'extends a simple schema' , ( ) => {
556556 const base = S . object ( )
557+ . id ( 'base' )
558+ . title ( 'base' )
557559 . additionalProperties ( false )
558560 . prop ( 'foo' , S . string ( ) . minLength ( 5 ) )
559561
560- const extended = S . extend ( base ) . prop ( 'bar' , S . number ( ) )
562+ const extended = S . object ( )
563+ . id ( 'extended' )
564+ . title ( 'extended' )
565+ . prop ( 'bar' , S . number ( ) )
566+ . extend ( base )
561567
562568 expect ( extended . valueOf ( ) ) . toEqual ( {
563569 $schema : 'http://json-schema.org/draft-07/schema#' ,
570+ $id : 'extended' ,
571+ title : 'extended' ,
564572 additionalProperties : false ,
565573 properties : {
566574 foo : {
@@ -576,6 +584,7 @@ describe('ObjectSchema', () => {
576584 } )
577585 it ( 'extends a nested schema' , ( ) => {
578586 const base = S . object ( )
587+ . id ( 'base' )
579588 . additionalProperties ( false )
580589 . prop (
581590 'foo' ,
@@ -590,10 +599,14 @@ describe('ObjectSchema', () => {
590599 . prop ( 'bol' , S . boolean ( ) . required ( ) )
591600 . prop ( 'num' , S . integer ( ) . required ( ) )
592601
593- const extended = S . extend ( base ) . prop ( 'bar' , S . number ( ) )
602+ const extended = S . object ( )
603+ . id ( 'extended' )
604+ . prop ( 'bar' , S . number ( ) )
605+ . extend ( base )
594606
595607 expect ( extended . valueOf ( ) ) . toEqual ( {
596608 $schema : 'http://json-schema.org/draft-07/schema#' ,
609+ $id : 'extended' ,
597610 additionalProperties : false ,
598611 properties : {
599612 foo : {
@@ -623,14 +636,63 @@ describe('ObjectSchema', () => {
623636 type : 'object' ,
624637 } )
625638 } )
639+ it ( 'extends a schema with definitions' , ( ) => {
640+ const base = S . object ( )
641+ . id ( 'base' )
642+ . additionalProperties ( false )
643+ . definition ( 'def1' , S . object ( ) . prop ( 'some' ) )
644+ . definition ( 'def2' , S . object ( ) . prop ( 'somethingElse' ) )
645+ . prop (
646+ 'foo' ,
647+ S . object ( ) . prop (
648+ 'id' ,
649+ S . string ( )
650+ . format ( 'uuid' )
651+ . required ( )
652+ )
653+ )
654+ . prop ( 'str' , S . string ( ) . required ( ) )
655+ . prop ( 'bol' , S . boolean ( ) . required ( ) )
656+ . prop ( 'num' , S . integer ( ) . required ( ) )
657+
658+ const extended = S . object ( )
659+ . id ( 'extended' )
660+ . definition ( 'def1' , S . object ( ) . prop ( 'someExtended' ) )
661+ . prop ( 'bar' , S . number ( ) )
662+ . extend ( base )
663+
664+ expect ( extended . valueOf ( ) ) . toEqual ( {
665+ $schema : 'http://json-schema.org/draft-07/schema#' ,
666+ definitions : {
667+ def1 : { type : 'object' , properties : { someExtended : { } } } ,
668+ def2 : { type : 'object' , properties : { somethingElse : { } } } ,
669+ } ,
670+ type : 'object' ,
671+ $id : 'extended' ,
672+ additionalProperties : false ,
673+ properties : {
674+ foo : {
675+ type : 'object' ,
676+ properties : { id : { type : 'string' , format : 'uuid' } } ,
677+ required : [ 'id' ] ,
678+ } ,
679+ str : { type : 'string' } ,
680+ bol : { type : 'boolean' } ,
681+ num : { type : 'integer' } ,
682+ bar : { type : 'number' } ,
683+ } ,
684+ required : [ 'str' , 'bol' , 'num' ] ,
685+ } )
686+ } )
687+
626688 it ( 'throws an error if a schema is not provided' , ( ) => {
627689 expect ( ( ) => {
628- S . extend ( )
690+ S . object ( ) . extend ( )
629691 } ) . toThrow ( "Schema can't be null or undefined" )
630692 } )
631693 it ( 'throws an error if a schema is not provided' , ( ) => {
632694 expect ( ( ) => {
633- S . extend ( 'boom!' )
695+ S . object ( ) . extend ( 'boom!' )
634696 } ) . toThrow ( "Schema isn't FluentSchema type" )
635697 } )
636698 } )
0 commit comments