Skip to content

Commit

Permalink
Transform various keywords from Draft 4 to Draft 6 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
suprith-hub authored Aug 5, 2024
1 parent a226338 commit f2f24b1
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "validation",
"condition": [
{ "operation": "has-key", "path": [], "value": "const" }
],
"transform": [
{ "operation": "prefix-until-unique", "path": [ "const" ], "value": "x-" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "validation",
"condition": [
{ "operation": "has-key", "path": [], "value": "contains" }
],
"transform": [
{ "operation": "prefix-until-unique", "path": [ "contains" ], "value": "x-" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "validation",
"condition": [
{ "operation": "has-key", "path": [], "value": "examples" }
],
"transform": [
{ "operation": "prefix-until-unique", "path": [ "examples" ], "value": "x-" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "valildation",
"condition": [
{ "operation": "has-key", "path": [], "value": "propertyNames" }
],
"transform": [
{ "operation": "prefix-until-unique", "path": [ "propertyNames" ], "value": "x-" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "$id" }
],
"transform": [
{ "operation": "prefix-until-unique", "path": [ "$id" ], "value": "x-" }
]
}
10 changes: 10 additions & 0 deletions rules/from-draft4/to-draft6/006-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "$schema" },
{ "operation": "match-pattern", "path": [ "$schema" ], "value": "^http[s]?://json-schema.org/draft-04/schema[#]?$" }
],
"transform": [
{ "operation": "replace", "path": [ "$schema" ], "value": "http://json-schema.org/draft-06/schema#" }
]
}
9 changes: 9 additions & 0 deletions rules/from-draft4/to-draft6/007-id-present.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "id" }
],
"transform": [
{ "operation": "move", "to": [ "$id" ], "from": [ "id" ] }
]
}
11 changes: 11 additions & 0 deletions test/from-draft4/to-draft6/id-present.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"title": "id present in the schema",
"from": {
"id": "http://example.com"
},
"to": {
"$id": "http://example.com"
}
}
]
73 changes: 73 additions & 0 deletions test/from-draft4/to-draft6/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[
{
"title": "Simple matching schema",
"from": {
"$schema": "https://json-schema.org/draft-04/schema#"
},
"to": {
"$schema": "http://json-schema.org/draft-06/schema#"
}
},
{
"title": "Simple non matching schema",
"from": {
"$schema": "http://json-schema.org/draft-06/schema#"
},
"to": {
"$schema": "http://json-schema.org/draft-06/schema#"
}
},
{
"title": "Nested matching schema",
"from": {
"$schema": "https://json-schema.org/draft-04/schema#",
"definitions": {
"foo": {
"$schema": "https://json-schema.org/draft-04/schema#"
}
}
},
"to": {
"$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {
"foo": {
"$schema": "http://json-schema.org/draft-06/schema#"
}
}
}
},
{
"title": "Nested half matching schema",
"from": {
"$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {
"foo": {
"$schema": "https://json-schema.org/draft-04/schema#"
}
}
},
"to": {
"$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {
"foo": {
"$schema": "http://json-schema.org/draft-06/schema#"
}
}
}
},
{
"title": "$schema inside unknown keyword",
"from": {
"$schema": "https://json-schema.org/draft-04/schema#",
"foo": {
"$schema": "https://json-schema.org/draft-04/schema#"
}
},
"to": {
"$schema": "http://json-schema.org/draft-06/schema#",
"foo": {
"$schema": "https://json-schema.org/draft-04/schema#"
}
}
}
]
24 changes: 24 additions & 0 deletions test/from-draft4/to-draft6/unknown-in-previous-draft-$id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"title": "$id present in the schema",
"from": {
"$id": "newbie"
},
"to": {
"x-$id": "newbie"
}
},
{
"title": "$id with $id having `x-` as prefix",
"from": {
"x-$id": "expert",
"x-x-$id": "master",
"$id": "newbie"
},
"to": {
"x-$id": "expert",
"x-x-$id": "master",
"x-x-x-$id": "newbie"
}
}
]
24 changes: 24 additions & 0 deletions test/from-draft4/to-draft6/unknown-in-previous-draft-const.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"title": "const present in the schema",
"from": {
"const": "newbie"
},
"to": {
"x-const": "newbie"
}
},
{
"title": "const with const having `x-` as prefix",
"from": {
"x-const": "expert",
"x-x-const": "master",
"const": "newbie"
},
"to": {
"x-const": "expert",
"x-x-const": "master",
"x-x-x-const": "newbie"
}
}
]
24 changes: 24 additions & 0 deletions test/from-draft4/to-draft6/unknown-in-previous-draft-contains.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"title": "contains present in the schema",
"from": {
"contains": "newbie"
},
"to": {
"x-contains": "newbie"
}
},
{
"title": "contains with contains having `x-` as prefix",
"from": {
"x-contains": "expert",
"x-x-contains": "master",
"contains": "newbie"
},
"to": {
"x-contains": "expert",
"x-x-contains": "master",
"x-x-x-contains": "newbie"
}
}
]
24 changes: 24 additions & 0 deletions test/from-draft4/to-draft6/unknown-in-previous-draft-examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"title": "examples present in the schema",
"from": {
"examples": "newbie"
},
"to": {
"x-examples": "newbie"
}
},
{
"title": "examples with examples having `x-` as prefix",
"from": {
"x-examples": "expert",
"x-x-examples": "master",
"examples": "newbie"
},
"to": {
"x-examples": "expert",
"x-x-examples": "master",
"x-x-x-examples": "newbie"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"title": "propertyNames present in the schema",
"from": {
"propertyNames": "newbie"
},
"to": {
"x-propertyNames": "newbie"
}
},
{
"title": "propertyNames with propertyNames having `x-` as prefix",
"from": {
"x-propertyNames": "expert",
"x-x-propertyNames": "master",
"propertyNames": "newbie"
},
"to": {
"x-propertyNames": "expert",
"x-x-propertyNames": "master",
"x-x-x-propertyNames": "newbie"
}
}
]

0 comments on commit f2f24b1

Please sign in to comment.