@@ -191,6 +191,75 @@ describe("defaultUnevaluatedProperties=false option", function () {
191191 assertInvalid ( schemas , { foo : { baz : 1 } } )
192192 assertInvalid ( schemas , { foo : { bar : "string" , baz : 1 } } )
193193 } )
194+
195+ it ( "should work correctly with anyOf" , ( ) => {
196+ const schema1 = {
197+ type : "object" ,
198+ properties : {
199+ address : { type : "string" } ,
200+ } ,
201+ anyOf : [
202+ {
203+ type : "object" ,
204+ required : [ "firstName" , "lastName" ] ,
205+ properties : {
206+ firstName : { type : "string" } ,
207+ lastName : { type : "string" } ,
208+ } ,
209+ } ,
210+ {
211+ type : "object" ,
212+ required : [ "name" ] ,
213+ properties : {
214+ name : { type : "string" } ,
215+ } ,
216+ } ,
217+ ] ,
218+ }
219+
220+ const schemas = [ schema1 ]
221+ assertInvalid ( schemas , { } )
222+ assertValid ( schemas , { address : "someWhere" , firstName : "John" , lastName : "Doe" } )
223+ assertValid ( schemas , { address : "someWhere" , name : "John Doe" } )
224+ assertInvalid ( schemas , { address : "someWhere" , firstName : "John" } )
225+ assertInvalid ( schemas , { address : "someWhere" , foo : 1 } )
226+ assertValid ( schemas , { firstName : "John" , lastName : "Doe" } )
227+ } )
228+
229+ it ( "should work correctly with oneOf" , ( ) => {
230+ const schema1 = {
231+ type : "object" ,
232+ properties : {
233+ address : { type : "string" } ,
234+ } ,
235+ oneOf : [
236+ {
237+ type : "object" ,
238+ required : [ "firstName" , "lastName" ] ,
239+ properties : {
240+ firstName : { type : "string" } ,
241+ lastName : { type : "string" } ,
242+ } ,
243+ } ,
244+ {
245+ type : "object" ,
246+ required : [ "name" ] ,
247+ properties : {
248+ name : { type : "string" } ,
249+ } ,
250+ } ,
251+ ] ,
252+ }
253+
254+ const schemas = [ schema1 ]
255+
256+ assertInvalid ( schemas , { } )
257+ assertValid ( schemas , { address : "someWhere" , firstName : "John" , lastName : "Doe" } )
258+ assertValid ( schemas , { address : "someWhere" , name : "John Doe" } )
259+ assertInvalid ( schemas , { firstName : "John" , lastName : "Doe" , name : "JD" } )
260+ assertInvalid ( schemas , { address : "someWhere" , foo : 1 } )
261+ assertValid ( schemas , { firstName : "John" , lastName : "Doe" } )
262+ } )
194263 } )
195264
196265 describe ( "validation with $refs" , ( ) => {
0 commit comments