Skip to content

Commit 5d07dbe

Browse files
committed
Add tests combining relative refs and defs
For Ref, recursiveRef and dynamicRef, both for absolute and relative ids.
1 parent fcae732 commit 5d07dbe

File tree

4 files changed

+416
-0
lines changed

4 files changed

+416
-0
lines changed

tests/draft2019-09/recursiveRef.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,109 @@
352352
"valid": false
353353
}
354354
]
355+
},
356+
{
357+
"description": "recursive refs with relative uris and defs",
358+
"schema": {
359+
"$id": "schema1.json",
360+
"properties": {
361+
"foo": {
362+
"$id": "schema2.json",
363+
"$defs": {
364+
"inner": {
365+
"properties": {
366+
"bar": { "type": "string" }
367+
}
368+
}
369+
},
370+
"$recursiveRef": "#/$defs/inner"
371+
}
372+
},
373+
"$recursiveRef": "schema2.json"
374+
},
375+
"tests": [
376+
{
377+
"description": "invalid on inner field",
378+
"data": {
379+
"foo": {
380+
"bar": 1
381+
},
382+
"bar": "a"
383+
},
384+
"valid": false
385+
},
386+
{
387+
"description": "invalid on outer field",
388+
"data": {
389+
"foo": {
390+
"bar": "a"
391+
},
392+
"bar": 1
393+
},
394+
"valid": false
395+
},
396+
{
397+
"description": "valid on both fields",
398+
"data": {
399+
"foo": {
400+
"bar": "a"
401+
},
402+
"bar": "a"
403+
},
404+
"valid": true
405+
}
406+
]
407+
},
408+
{
409+
"description": "relative recursive refs with absolute uris and defs",
410+
"schema": {
411+
"$id": "http://example.com/schema1.json",
412+
"properties": {
413+
"foo": {
414+
"$id": "http://example.com/schema2.json",
415+
"$defs": {
416+
"inner": {
417+
"properties": {
418+
"bar": { "type": "string" }
419+
}
420+
}
421+
},
422+
"$recursiveRef": "#/$defs/inner"
423+
}
424+
},
425+
"$recursiveRef": "schema2.json"
426+
},
427+
"tests": [
428+
{
429+
"description": "invalid on inner field",
430+
"data": {
431+
"foo": {
432+
"bar": 1
433+
},
434+
"bar": "a"
435+
},
436+
"valid": false
437+
},
438+
{
439+
"description": "invalid on outer field",
440+
"data": {
441+
"foo": {
442+
"bar": "a"
443+
},
444+
"bar": 1
445+
},
446+
"valid": false
447+
},
448+
{
449+
"description": "valid on both fields",
450+
"data": {
451+
"foo": {
452+
"bar": "a"
453+
},
454+
"bar": "a"
455+
},
456+
"valid": true
457+
}
458+
]
355459
}
356460
]

tests/draft2019-09/ref.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,109 @@
430430
"valid": true
431431
}
432432
]
433+
},
434+
{
435+
"description": "refs with relative uris and defs",
436+
"schema": {
437+
"$id": "schema1.json",
438+
"properties": {
439+
"foo": {
440+
"$id": "schema2.json",
441+
"$defs": {
442+
"inner": {
443+
"properties": {
444+
"bar": { "type": "string" }
445+
}
446+
}
447+
},
448+
"$ref": "#/$defs/inner"
449+
}
450+
},
451+
"$ref": "schema2.json"
452+
},
453+
"tests": [
454+
{
455+
"description": "invalid on inner field",
456+
"data": {
457+
"foo": {
458+
"bar": 1
459+
},
460+
"bar": "a"
461+
},
462+
"valid": false
463+
},
464+
{
465+
"description": "invalid on outer field",
466+
"data": {
467+
"foo": {
468+
"bar": "a"
469+
},
470+
"bar": 1
471+
},
472+
"valid": false
473+
},
474+
{
475+
"description": "valid on both fields",
476+
"data": {
477+
"foo": {
478+
"bar": "a"
479+
},
480+
"bar": "a"
481+
},
482+
"valid": true
483+
}
484+
]
485+
},
486+
{
487+
"description": "relative refs with absolute uris and defs",
488+
"schema": {
489+
"$id": "http://example.com/schema1.json",
490+
"properties": {
491+
"foo": {
492+
"$id": "http://example.com/schema2.json",
493+
"$defs": {
494+
"inner": {
495+
"properties": {
496+
"bar": { "type": "string" }
497+
}
498+
}
499+
},
500+
"$ref": "#/$defs/inner"
501+
}
502+
},
503+
"$ref": "schema2.json"
504+
},
505+
"tests": [
506+
{
507+
"description": "invalid on inner field",
508+
"data": {
509+
"foo": {
510+
"bar": 1
511+
},
512+
"bar": "a"
513+
},
514+
"valid": false
515+
},
516+
{
517+
"description": "invalid on outer field",
518+
"data": {
519+
"foo": {
520+
"bar": "a"
521+
},
522+
"bar": 1
523+
},
524+
"valid": false
525+
},
526+
{
527+
"description": "valid on both fields",
528+
"data": {
529+
"foo": {
530+
"bar": "a"
531+
},
532+
"bar": "a"
533+
},
534+
"valid": true
535+
}
536+
]
433537
}
434538
]

tests/draft2020-12/dynamicRef.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,109 @@
253253
"valid": false
254254
}
255255
]
256+
},
257+
{
258+
"description": "dynamic refs with relative uris and defs",
259+
"schema": {
260+
"$id": "schema1.json",
261+
"properties": {
262+
"foo": {
263+
"$id": "schema2.json",
264+
"$defs": {
265+
"inner": {
266+
"properties": {
267+
"bar": { "type": "string" }
268+
}
269+
}
270+
},
271+
"$dynamicRef": "#/$defs/inner"
272+
}
273+
},
274+
"$dynamicRef": "schema2.json"
275+
},
276+
"tests": [
277+
{
278+
"description": "invalid on inner field",
279+
"data": {
280+
"foo": {
281+
"bar": 1
282+
},
283+
"bar": "a"
284+
},
285+
"valid": false
286+
},
287+
{
288+
"description": "invalid on outer field",
289+
"data": {
290+
"foo": {
291+
"bar": "a"
292+
},
293+
"bar": 1
294+
},
295+
"valid": false
296+
},
297+
{
298+
"description": "valid on both fields",
299+
"data": {
300+
"foo": {
301+
"bar": "a"
302+
},
303+
"bar": "a"
304+
},
305+
"valid": true
306+
}
307+
]
308+
},
309+
{
310+
"description": "relative dynamic refs with absolute uris and defs",
311+
"schema": {
312+
"$id": "http://example.com/schema1.json",
313+
"properties": {
314+
"foo": {
315+
"$id": "http://example.com/schema2.json",
316+
"$defs": {
317+
"inner": {
318+
"properties": {
319+
"bar": { "type": "string" }
320+
}
321+
}
322+
},
323+
"$dynamicRef": "#/$defs/inner"
324+
}
325+
},
326+
"$dynamicRef": "schema2.json"
327+
},
328+
"tests": [
329+
{
330+
"description": "invalid on inner field",
331+
"data": {
332+
"foo": {
333+
"bar": 1
334+
},
335+
"bar": "a"
336+
},
337+
"valid": false
338+
},
339+
{
340+
"description": "invalid on outer field",
341+
"data": {
342+
"foo": {
343+
"bar": "a"
344+
},
345+
"bar": 1
346+
},
347+
"valid": false
348+
},
349+
{
350+
"description": "valid on both fields",
351+
"data": {
352+
"foo": {
353+
"bar": "a"
354+
},
355+
"bar": "a"
356+
},
357+
"valid": true
358+
}
359+
]
256360
}
257361
]

0 commit comments

Comments
 (0)