@@ -144,3 +144,39 @@ test('comments are exposed in objects', () => {
144144
145145 assert . deepEqual ( optimize ( input ) , expected ) ;
146146} ) ;
147+
148+ test ( 'consolidatable unions are consolidated to single primitive type' , ( ) => {
149+ const input : Schema = {
150+ type : 'union' ,
151+ schemas : [
152+ { type : 'string' , enum : [ 'true' , 'false' ] , decodedType : 'boolean' } ,
153+ { type : 'boolean' , primitive : true } ,
154+ ] ,
155+ required : [ ] ,
156+ } ;
157+
158+ const expected : Schema = { type : 'boolean' , } ;
159+
160+ assert . deepEqual ( optimize ( input ) , expected ) ;
161+ } ) ;
162+
163+ test ( 'non-consolidatable unions are not consolidated' , ( ) => {
164+ const input : Schema = {
165+ type : 'union' ,
166+ schemas : [
167+ { type : 'string' , enum : [ 'true' , 'false' ] , decodedType : 'boolean' } ,
168+ { type : 'string' , primitive : true } ,
169+ ] ,
170+ required : [ ] ,
171+ } ;
172+
173+ const expected : Schema = {
174+ type : 'union' ,
175+ schemas : [
176+ { type : 'string' , primitive : true } ,
177+ { type : 'string' , enum : [ 'true' , 'false' ] } ,
178+ ]
179+ } ;
180+
181+ assert . deepEqual ( optimize ( input ) , expected ) ;
182+ } ) ;
0 commit comments