Skip to content

Commit 8405f08

Browse files
authored
Add rules and test for required keyword, Draft 3 to 4 (#31)
1 parent ff40103 commit 8405f08

6 files changed

+119
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"vocabulary": "core",
3+
"condition": [
4+
{ "operation": "has-key", "path": [], "value": "properties" },
5+
{ "operation": "has-key", "path": [ "properties", {} ], "value": "required" },
6+
{ "operation": "equals", "path": [ "properties", {}, "required" ], "value": false }
7+
],
8+
"transform": [
9+
{ "operation": "remove", "path": [ "properties", {}, "required" ] }
10+
]
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"vocabulary": "core",
3+
"condition": [
4+
{ "operation": "has-key", "path": [], "value": "required" }
5+
],
6+
"transform": [
7+
{ "operation": "replace", "path": [ "required" ], "value": [] }
8+
]
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"vocabulary": "core",
3+
"condition": [
4+
{ "operation": "not-has-key", "path": [], "value": "required" },
5+
{ "operation": "has-key", "path": [], "value": "properties" },
6+
{ "operation": "has-key", "path": [ "properties", {} ], "value": "required" },
7+
{ "operation": "equals", "path": [ "properties", {}, "required" ], "value": true }
8+
],
9+
"transform": [
10+
{ "operation": "add", "path": [ "required" ], "value": [] }
11+
]
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"vocabulary": "core",
3+
"condition": [
4+
{ "operation": "has-key", "path": [], "value": "properties" },
5+
{ "operation": "has-key", "path": [ "properties", {} ], "value": "required" },
6+
{ "operation": "equals", "path": [ "properties", {}, "required" ], "value": true }
7+
],
8+
"transform": [
9+
{ "operation": "append-property", "to": [ "required" ], "from": [ "properties", {} ] },
10+
{ "operation": "remove", "path": [ "properties", {}, "required" ] }
11+
]
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"vocabulary": "core",
3+
"condition": [
4+
{ "operation": "has-key", "path": [], "value": "required" },
5+
{ "operation": "size-equals", "path": [ "required" ], "value": 0 }
6+
],
7+
"transform": [
8+
{ "operation": "remove", "path": [ "required" ] }
9+
]
10+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[
2+
{
3+
"title": "`required` is true in properties/{something} and required absent in outer schema",
4+
"from": {
5+
"properties": {
6+
"foo": { "required": true },
7+
"bar": {
8+
"type": "string",
9+
"required": true
10+
}
11+
}
12+
},
13+
"to": {
14+
"properties": {
15+
"foo": {},
16+
"bar": {
17+
"type": "string"
18+
}
19+
},
20+
"required": [ "foo", "bar" ]
21+
}
22+
},
23+
{
24+
"title": "`required` is true in properties/{something} and required boolean in outer schema",
25+
"from": {
26+
"properties": {
27+
"foo": { "required": true },
28+
"bar": {
29+
"type": "string",
30+
"required": true
31+
}
32+
},
33+
"required": false
34+
},
35+
"to": {
36+
"properties": {
37+
"foo": {},
38+
"bar": {
39+
"type": "string"
40+
}
41+
},
42+
"required": [ "foo", "bar" ]
43+
}
44+
},
45+
{
46+
"title": "`required` has value false present in properties children",
47+
"from": {
48+
"properties": {
49+
"foo": { "required": false }
50+
}
51+
},
52+
"to": {
53+
"properties": {
54+
"foo": {}
55+
}
56+
}
57+
},
58+
{
59+
"title": "`required` is an empty array in outer schema",
60+
"from": {
61+
"required": []
62+
},
63+
"to": {}
64+
}
65+
]

0 commit comments

Comments
 (0)