Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{ "operation": "contains-type", "path": [ "type" ], "value": "string" }
],
"transform": [
{ "operation": "add", "path": [ "anyOf", "-" ], "value": { "type": [] } }
{ "operation": "add", "path": [ "anyOf", "-" ], "value": { "type": [] } },
{ "operation": "add", "path": [ "type", "-" ], "value": true }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
{ "operation": "type-is", "path": [ "type", {} ], "value": "string" }
],
"transform": [
{ "operation": "remove-and-append", "to": [ "anyOf", "-", "type" ], "from": [ "type", {} ] }
{ "operation": "copy", "to": [ "anyOf", "-", "type", "-" ], "from": [ "type", {} ] }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"vocabulary": "core",
"condition": [
{ "operation": "has-key", "path": [], "value": "type" },
{ "operation": "type-is", "path": [ "type" ], "value": "array" },
{ "operation": "contains-type", "path": [ "type" ], "value": "object" },
{ "operation": "type-is", "path": [ "type", {} ], "value": "string" }
],
"transform": [
{ "operation": "remove", "path": [ "type", {} ] }
]
}
11 changes: 11 additions & 0 deletions rules/from-draft3/to-draft4/017-type-has-boolean-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": "type" },
{ "operation": "type-is", "path": [ "type" ], "value": "array" },
{ "operation": "contains-type", "path": [ "type" ], "value": "boolean" }
],
"transform": [
{ "operation": "remove", "path": [ "type" ] }
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
{ "operation": "not-has-key", "path": [], "value": "allOf" }
],
"transform": [
{ "operation": "move", "to": [ "allOf" ], "from": [ "extends" ] }
{ "operation": "add", "path": [ "allOf" ], "value": [] }
]
}
76 changes: 76 additions & 0 deletions test/from-2019-09/to-2020-12/references-tweak.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[
{
"title": "Reference to contains",
"from": {
"$ref": "#/contains",
"contains": {
"type": "string"
}
},
"to": {
"$ref": "#/allOf/0/not/not/contains",
"allOf": [
{
"not": {
"not": {
"contains": {
"type": "string"
}
}
}
}
]
}
},
{
"title":"Reference to items is an array",
"from": {
"$ref": "#/items/0",
"items": [
{
"type": "string"
}
]
},
"to": {
"$ref": "#/prefixItems/0",
"prefixItems": [
{
"type": "string"
}
]
}
},
{
"title":"Reference to items is an object",
"from": {
"$ref": "#/items",
"items": {
"type": "string"
}
},
"to": {
"$ref": "#/items",
"items": {
"type": "string"
}
}
},
{
"title":"Reference to additionalItems is an object, items is an array",
"from": {
"$ref": "#/additionalItems",
"items": [ {} ],
"additionalItems": {
"type": "string"
}
},
"to": {
"$ref": "#/items",
"prefixItems": [ {} ],
"items": {
"type": "string"
}
}
}
]
89 changes: 89 additions & 0 deletions test/from-draft3/to-draft4/references-tweak.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[
{
"title": "Reference to `type` when it has objects in its array",
"from": {
"type": [ {} ],
"$ref": "#/type/0"
},
"to": {
"$ref": "#/anyOf/0",
"anyOf": [
{}
]
}
},
{
"title": "Reference to `type` when it has objects and string in its array",
"from": {
"type": [ "string", {} ],
"$ref": "#/type/1"
},
"to": {
"anyOf": [
{ "type": ["string"] },
{}
]
}
},
{
"title":"Reference to `disallow` when it has objects in its array",
"from": {
"disallow": [ {} ],
"$ref": "#/disallow/0"
},
"to": {
"allOf": [
{ "not": {} }
],
"$ref": "#/allOf/0/not"
}
},
{
"title": "Reference to `disallow` when it has objects and string in its array",
"from": {
"disallow": [ "string", {} ],
"$ref": "#/disallow/1"
},
"to": {
"allOf": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is valid, but shouldn't the subschemas in allOf be in the opposite order? i.e. the disallow keyword first disallows string, so shouldn't the type string not be first in the array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! by doing it this way I can get the indexes of objects, like
If I choose to upgrade index 0: string ... Then I will lose track of the index where the object was present.
If string is popped first, then array will be [{}], then I lose track that it was in index 1, because now its in index 0

{
"not": {}
},
{
"not": {
"type": [
"string"
]
}
}
],
"$ref": "#/allOf/0/not"
}
},
{
"title": "Reference to `extends` when its an array",
"from": {
"extends": [ {}, { "type": "object" } ],
"$ref": "#/extends/0"
},
"to": {
"allOf": [
{}
],
"$ref": "#/allOf/1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not valid, as allOf only has one element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jviotti in the draft4: https://json-schema.org/draft-04/schema It has constaints minItems: 1, so it can have 1 item I think but not 0 items...

}
},
{
"title": "Reference to `extends` when its an object",
"from": {
"extends": {},
"$ref": "#/extends"
},
"to": {
"allOf": [
{}
],
"$ref": "#/allOf/0"
}
}
]
52 changes: 52 additions & 0 deletions test/from-draft7/to-2019-09/references-tweak.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[
{
"title": "Reference to definitions",
"from": {
"allOf": [
{
"$ref": "#/definitions/foo"
}
],
"definitions": {
"foo": {}
}
},
"to": {
"allOf": [
{
"$ref": "#/$defs/foo"
}
],
"$defs": {
"foo": {}
}
}
},
{
"title": "Reference to dependencies, child is a schema",
"from": {
"allOf": [
{
"$ref": "#/dependencies/foo"
}
],
"dependencies": {
"foo": {
"type": "string"
}
}
},
"to": {
"allOf": [
{
"$ref": "#/dependentSchemas/foo"
}
],
"dependentSchemas": {
"foo": {
"type": "string"
}
}
}
}
]