@@ -2,8 +2,80 @@ import { JSONSchema4 } from 'json-schema';
22import { mergeAllOf } from '../mergeAllOf' ;
33
44describe ( 'mergeAllOf util' , ( ) => {
5+ describe ( 'example merging' , ( ) => {
6+ test ( 'given incompatible, should leave empty' , ( ) => {
7+ const schema : JSONSchema4 = {
8+ allOf : [
9+ {
10+ type : 'object' ,
11+ properties : {
12+ bar : {
13+ type : 'string' ,
14+ example : 'hello' ,
15+ } ,
16+ } ,
17+ } ,
18+ {
19+ type : 'object' ,
20+ properties : {
21+ bar : {
22+ type : 'string' ,
23+ example : 'bye' ,
24+ } ,
25+ } ,
26+ } ,
27+ ] ,
28+ } ;
29+
30+ expect ( mergeAllOf ( schema , [ ] , jest . fn ( ) ) ) . toEqual ( {
31+ properties : {
32+ bar : {
33+ example : null ,
34+ type : 'string' ,
35+ } ,
36+ } ,
37+ type : 'object' ,
38+ } ) ;
39+ } ) ;
40+
41+ test ( 'given compatible, should merge normally' , ( ) => {
42+ const schema : JSONSchema4 = {
43+ allOf : [
44+ {
45+ type : 'object' ,
46+ properties : {
47+ bar : {
48+ type : 'string' ,
49+ example : 'hello' ,
50+ } ,
51+ } ,
52+ } ,
53+ {
54+ type : 'object' ,
55+ properties : {
56+ bar : {
57+ type : 'string' ,
58+ example : 'hello' ,
59+ } ,
60+ } ,
61+ } ,
62+ ] ,
63+ } ;
64+
65+ expect ( mergeAllOf ( schema , [ ] , jest . fn ( ) ) ) . toEqual ( {
66+ properties : {
67+ bar : {
68+ example : 'hello' ,
69+ type : 'string' ,
70+ } ,
71+ } ,
72+ type : 'object' ,
73+ } ) ;
74+ } ) ;
75+ } ) ;
76+
577 describe ( 'enums merging' , ( ) => {
6- test ( 'given incompatible, should mark enum as empty' , ( ) => {
78+ test ( 'given incompatible, should leave empty' , ( ) => {
779 const schema : JSONSchema4 = {
880 allOf : [
981 {
@@ -38,7 +110,7 @@ describe('mergeAllOf util', () => {
38110 } ) ;
39111 } ) ;
40112
41- test ( 'given incompatible , should merge normally' , ( ) => {
113+ test ( 'given compatible , should merge normally' , ( ) => {
42114 const schema : JSONSchema4 = {
43115 allOf : [
44116 {
0 commit comments