Skip to content

Commit

Permalink
Transform disallow from Draft 3 to Draft 4 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
suprith-hub authored Aug 5, 2024
1 parent f2f24b1 commit bbc0d70
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rules/from-draft3/to-draft4/016-disallow-has-value-equals-any.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "disallow" },
{ "operation": "equals", "path": [ "disallow" ], "value": "any" }
],
"transform": [
{ "operation": "add", "path": [ "not" ], "value": {} },
{ "operation": "remove", "path": [ "disallow" ] }
]
}
11 changes: 11 additions & 0 deletions rules/from-draft3/to-draft4/017-disallow-has-any-in-its-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "disallow" },
{ "operation": "equals", "path": [ "disallow", {} ], "value": "any" }
],
"transform": [
{ "operation": "add", "path": [ "not" ], "value": {} },
{ "operation": "remove", "path": [ "disallow" ] }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "disallow" },
{ "operation": "not-has-key", "path": [], "value": "allOf" },
{ "operation": "type-is", "path": [ "disallow" ], "value": "array" },
{ "operation": "contains-type", "path": [ "disallow" ], "value": "object" }
],
"transform": [
{ "operation": "add", "path": [ "allOf" ], "value": [] }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "disallow" },
{ "operation": "has-key", "path": [], "value": "allOf" },
{ "operation": "type-is", "path": [ "disallow" ], "value": "array" },
{ "operation": "type-is", "path": [ "disallow", {} ], "value": "object" }
],
"transform": [
{ "operation": "add", "path": [ "allOf", "-" ], "value": { "not": "temp"} },
{ "operation": "move", "to": [ "allOf", "-", "not" ], "from": [ "disallow", {} ] }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "disallow" },
{ "operation": "type-is", "path": [ "disallow" ], "value": "array" },
{ "operation": "contains-type", "path": [ "disallow" ], "value": "string" },
{ "operation": "has-key", "path": [], "value": "allOf" }
],
"transform": [
{ "operation": "add", "path": [ "allOf", "-" ], "value": { "not": "temp" } },
{ "operation": "add", "path": [ "allOf", "-", "not" ], "value": { "type": "temp" } },
{ "operation": "move", "to": [ "allOf", "-", "not", "type" ], "from": [ "disallow" ] }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "disallow" },
{ "operation": "type-is", "path": [ "disallow" ], "value": "array" },
{ "operation": "contains-type", "path": [ "disallow" ], "value": "string" },
{ "operation": "not-has-key", "path": [], "value": "allOf" }
],
"transform": [
{ "operation": "add", "path": [ "allOf" ], "value": [ { "not": { "type": "temp" } } ] },
{ "operation": "move", "to": [ "allOf", "-", "not", "type" ], "from": [ "disallow" ] }
]
}
11 changes: 11 additions & 0 deletions rules/from-draft3/to-draft4/021-disallow-is-an-empty-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "disallow" },
{ "operation": "type-is", "path": [ "disallow" ], "value": "array" },
{ "operation": "size-equals", "path": [ "disallow" ], "value": 0 }
],
"transform": [
{ "operation": "remove", "path": [ "disallow" ] }
]
}
44 changes: 44 additions & 0 deletions test/from-draft3/to-draft4/disallow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"title": "`disallow` is present and value equals to any",
"from": {
"disallow": "any"
},
"to": {
"not": {}
}
},
{
"title": "`disallow` is present and contains `any` in it",
"from": {
"disallow": [ "any", {}, "string" ]
},
"to": {
"not": {}
}
},
{
"title": "`disallow` is present and contains atleast one object and allOf present",
"from": {
"disallow": [ {}, { "type": "string"} ],
"allOf": []
},
"to": {
"allOf": [
{ "not": { "type": "string"} },
{ "not": {} }
]
}
},
{
"title": "`disallow` is present and is an array of strings",
"from": {
"disallow": [ "number", "string" ]
},
"to": {
"allOf": [
{ "not": { "type": [ "number", "string" ] } }
]
}
}
]

0 comments on commit bbc0d70

Please sign in to comment.