Skip to content

Commit ff40103

Browse files
authored
Add rules and test for type keyword, draft 3 to draft 4 (#27)
1 parent 2df6bcd commit ff40103

10 files changed

+133
-0
lines changed
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": "type" },
5+
{ "operation": "equals", "path": [ "type" ], "value": "any" }
6+
],
7+
"transform": [
8+
{ "operation": "remove", "path": [ "type" ] }
9+
]
10+
}
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": "type" },
5+
{ "operation": "type-is", "path": [ "type" ], "value": "array" },
6+
{ "operation": "equals", "path": [ "type", {} ], "value": "any" }
7+
],
8+
"transform": [
9+
{ "operation": "remove", "path": [ "type" ] }
10+
]
11+
}
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": "type" },
5+
{ "operation": "not-has-key", "path": [], "value": "anyOf" },
6+
{ "operation": "type-is", "path": [ "type" ], "value": "array" },
7+
{ "operation": "contains-type", "path": [ "type" ], "value": "object" }
8+
],
9+
"transform": [
10+
{ "operation": "add", "path": [ "anyOf" ], "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": "type" },
5+
{ "operation": "type-is", "path": [ "type" ], "value": "array" },
6+
{ "operation": "contains-type", "path": [ "type" ], "value": "object" },
7+
{ "operation": "contains-type", "path": [ "type" ], "value": "string" }
8+
],
9+
"transform": [
10+
{ "operation": "add", "path": [ "anyOf", "-" ], "value": { "type": [] } }
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": "type" },
5+
{ "operation": "type-is", "path": [ "type" ], "value": "array" },
6+
{ "operation": "contains-type", "path": [ "type" ], "value": "object" },
7+
{ "operation": "type-is", "path": [ "type", {} ], "value": "string" }
8+
],
9+
"transform": [
10+
{ "operation": "remove-and-append", "to": [ "anyOf", "-", "type" ], "from": [ "type", {} ] }
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": "type" },
5+
{ "operation": "type-is", "path": [ "type" ], "value": "array" },
6+
{ "operation": "has-key", "path": [], "value": "anyOf" },
7+
{ "operation": "type-is", "path": [ "type", {} ], "value": "object" }
8+
],
9+
"transform": [
10+
{ "operation": "remove-and-append", "to": [ "anyOf" ], "from": [ "type", {} ] }
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": "type" },
5+
{ "operation": "size-equals", "path": [ "type" ], "value": 0 }
6+
],
7+
"transform": [
8+
{ "operation": "remove", "to": [ "type" ] }
9+
]
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"title": "`type` is present and contains `any` in it",
4+
"from": {
5+
"type": [ {}, "string", "any", { "type": "string" } ]
6+
},
7+
"to": {}
8+
}
9+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"title": "`type` is present and value equals to any",
4+
"from": {
5+
"type": "any"
6+
},
7+
"to": {}
8+
}
9+
]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[
2+
{
3+
"title": "`type` is present is an array of objects",
4+
"from": {
5+
"type": [ {}, { "type": "string" } ]
6+
},
7+
"to": {
8+
"anyOf": [
9+
{},
10+
{ "type": "string" }
11+
]
12+
}
13+
},
14+
{
15+
"title": "`type` is present and contains objects and strings in it",
16+
"from": {
17+
"type": [ {}, "string", "object", { "type": "string" } ]
18+
},
19+
"to": {
20+
"anyOf": [
21+
{ "type": [ "object", "string" ] },
22+
{},
23+
{ "type": "string" }
24+
]
25+
}
26+
},
27+
{
28+
"title": "`type` is present and is an array of strings",
29+
"from": {
30+
"type": [ "string", "object" ]
31+
},
32+
"to": {
33+
"type": [ "string", "object" ]
34+
}
35+
}
36+
]

0 commit comments

Comments
 (0)