@@ -97,13 +97,6 @@ describe('CommonModel', function() {
9797 const d = CommonModel . toCommonModel ( doc ) ;
9898 expect ( d . additionalProperties ) . toEqual ( undefined ) ;
9999 } ) ;
100-
101- test ( 'should return undefined when null' , function ( ) {
102- const doc : any = { additionalProperties : null } ;
103- const d = CommonModel . toCommonModel ( doc ) ;
104- expect ( d . additionalProperties ) . not . toBeUndefined ( ) ;
105- expect ( d . additionalProperties ) . toEqual ( doc . additionalProperties ) ;
106- } ) ;
107100 } ) ;
108101
109102 describe ( '$ref' , function ( ) {
@@ -423,8 +416,69 @@ describe('CommonModel', function() {
423416 expect ( doc1 . properties ) . toBeUndefined ( ) ;
424417 } ) ;
425418 } ) ;
426- } ) ;
419+ describe ( 'additionalProperties' , function ( ) {
420+ test ( 'should be merged when only right side is defined' , function ( ) {
421+ const doc : Schema = { } ;
422+ let doc1 = CommonModel . toCommonModel ( doc ) ;
423+ let doc2 = CommonModel . toCommonModel ( doc ) ;
424+ doc2 . additionalProperties = CommonModel . toCommonModel ( { type : "string" } ) ;
425+ doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
426+ expect ( doc1 . additionalProperties ) . toEqual ( doc2 . additionalProperties ) ;
427+ } ) ;
428+ test ( 'should be merged together when both sides are defined' , function ( ) {
429+ const doc : Schema = { } ;
430+ let doc1 = CommonModel . toCommonModel ( doc ) ;
431+ let doc2 = CommonModel . toCommonModel ( doc ) ;
432+ doc2 . additionalProperties = CommonModel . toCommonModel ( { type : "string" } ) ;
433+ doc1 . additionalProperties = CommonModel . toCommonModel ( { type : "number" } ) ;
434+ doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
435+ expect ( doc1 . additionalProperties ) . toEqual ( { type : [ "number" , "string" ] , originalSchema : { } } ) ;
436+ } ) ;
437+ test ( 'should not change if nothing is defined' , function ( ) {
438+ const doc : Schema = { } ;
439+ let doc1 = CommonModel . toCommonModel ( doc ) ;
440+ let doc2 = CommonModel . toCommonModel ( doc ) ;
441+ doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
442+ expect ( doc1 . patternProperties ) . toBeUndefined ( ) ;
443+ } ) ;
444+ } ) ;
427445
446+ describe ( 'patternProperties' , function ( ) {
447+ test ( 'should be merged when only right side is defined' , function ( ) {
448+ const doc : Schema = { } ;
449+ let doc1 = CommonModel . toCommonModel ( doc ) ;
450+ let doc2 = CommonModel . toCommonModel ( doc ) ;
451+ doc2 . patternProperties = { "pattern1" : CommonModel . toCommonModel ( { type : "string" } ) } ;
452+ doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
453+ expect ( doc1 . patternProperties ) . toEqual ( doc2 . patternProperties ) ;
454+ } ) ;
455+ test ( 'should be merged when both sides are defined' , function ( ) {
456+ const doc : Schema = { } ;
457+ let doc1 = CommonModel . toCommonModel ( doc ) ;
458+ let doc2 = CommonModel . toCommonModel ( doc ) ;
459+ doc2 . patternProperties = { "pattern1" : CommonModel . toCommonModel ( { type : "string" } ) } ;
460+ doc1 . patternProperties = { "pattern2" : CommonModel . toCommonModel ( { type : "number" } ) } ;
461+ doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
462+ expect ( doc1 . patternProperties ) . toEqual ( { "pattern1" : { type : "string" } , "pattern2" : { type : "number" } } ) ;
463+ } ) ;
464+ test ( 'should be merged together when both sides are defined' , function ( ) {
465+ const doc : Schema = { } ;
466+ let doc1 = CommonModel . toCommonModel ( doc ) ;
467+ let doc2 = CommonModel . toCommonModel ( doc ) ;
468+ doc2 . patternProperties = { "pattern1" : CommonModel . toCommonModel ( { type : "string" } ) } ;
469+ doc1 . patternProperties = { "pattern1" : CommonModel . toCommonModel ( { type : "number" } ) } ;
470+ doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
471+ expect ( doc1 . patternProperties ) . toEqual ( { "pattern1" : { type : [ "number" , "string" ] , originalSchema : { } } } ) ;
472+ } ) ;
473+ test ( 'should not change if nothing is defined' , function ( ) {
474+ const doc : Schema = { } ;
475+ let doc1 = CommonModel . toCommonModel ( doc ) ;
476+ let doc2 = CommonModel . toCommonModel ( doc ) ;
477+ doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
478+ expect ( doc1 . patternProperties ) . toBeUndefined ( ) ;
479+ } ) ;
480+ } ) ;
481+ } ) ;
428482 describe ( 'helpers' , function ( ) {
429483 describe ( 'getFromSchema' , function ( ) {
430484 test ( 'should work' , function ( ) {
0 commit comments