Skip to content

Rename definitions to $defs in the 2019-06 draft. #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -5,11 +5,7 @@
"tests": [
{
"description": "valid definition schema",
"data": {
"definitions": {
"foo": {"type": "integer"}
}
},
"data": {"$defs": {"foo": {"type": "integer"}}},
"valid": true
}
]
Expand All @@ -20,11 +16,7 @@
"tests": [
{
"description": "invalid definition schema",
"data": {
"definitions": {
"foo": {"type": 1}
}
},
"data": {"$defs": {"foo": {"type": 1}}},
"valid": false
}
]
Expand Down
12 changes: 6 additions & 6 deletions tests/draft2019-06/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@
{
"description": "items and subitems",
"schema": {
"definitions": {
"$defs": {
"item": {
"type": "array",
"additionalItems": false,
"items": [
{ "$ref": "#/definitions/sub-item" },
{ "$ref": "#/definitions/sub-item" }
{ "$ref": "#/$defs/sub-item" },
{ "$ref": "#/$defs/sub-item" }
]
},
"sub-item": {
Expand All @@ -150,9 +150,9 @@
"type": "array",
"additionalItems": false,
"items": [
{ "$ref": "#/definitions/item" },
{ "$ref": "#/definitions/item" },
{ "$ref": "#/definitions/item" }
{ "$ref": "#/$defs/item" },
{ "$ref": "#/$defs/item" },
{ "$ref": "#/$defs/item" }
]
},
"tests": [
Expand Down
26 changes: 13 additions & 13 deletions tests/draft2019-06/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@
{
"description": "nested refs",
"schema": {
"definitions": {
"$defs": {
"a": {"type": "integer"},
"b": {"$ref": "#/definitions/a"},
"c": {"$ref": "#/definitions/b"}
"b": {"$ref": "#/$defs/a"},
"c": {"$ref": "#/$defs/b"}
},
"$ref": "#/definitions/c"
"$ref": "#/$defs/c"
},
"tests": [
{
Expand All @@ -143,14 +143,14 @@
{
"description": "ref overrides any sibling keywords",
"schema": {
"definitions": {
"$defs": {
"reffed": {
"type": "array"
}
},
"properties": {
"foo": {
"$ref": "#/definitions/reffed",
"$ref": "#/$defs/reffed",
"maxItems": 2
}
}
Expand Down Expand Up @@ -212,8 +212,8 @@
{
"description": "$ref to boolean schema true",
"schema": {
"$ref": "#/definitions/bool",
"definitions": {
"$ref": "#/$defs/bool",
"$defs": {
"bool": true
}
},
Expand All @@ -228,8 +228,8 @@
{
"description": "$ref to boolean schema false",
"schema": {
"$ref": "#/definitions/bool",
"definitions": {
"$ref": "#/$defs/bool",
"$defs": {
"bool": false
}
},
Expand All @@ -255,7 +255,7 @@
}
},
"required": ["meta", "nodes"],
"definitions": {
"$defs": {
"node": {
"$id": "http://localhost:1234/node",
"description": "node",
Expand Down Expand Up @@ -333,9 +333,9 @@
"description": "refs with quote",
"schema": {
"properties": {
"foo\"bar": {"$ref": "#/definitions/foo%22bar"}
"foo\"bar": {"$ref": "#/$defs/foo%22bar"}
},
"definitions": {
"$defs": {
"foo\"bar": {"type": "number"}
}
},
Expand Down
16 changes: 6 additions & 10 deletions tests/draft2019-06/refRemote.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@
"schema": {
"$id": "http://localhost:1234/scope_change_defs1.json",
"type" : "object",
"properties": {
"list": {"$ref": "#/definitions/baz"}
},
"definitions": {
"properties": {"list": {"$ref": "#/$defs/baz"}},
"$defs": {
"baz": {
"$id": "folder/",
"type": "array",
Expand All @@ -105,13 +103,11 @@
"schema": {
"$id": "http://localhost:1234/scope_change_defs2.json",
"type" : "object",
"properties": {
"list": {"$ref": "#/definitions/baz/definitions/bar"}
},
"definitions": {
"properties": {"list": {"$ref": "#/$defs/baz/$defs/bar"}},
"$defs": {
"baz": {
"$id": "folder/",
"definitions": {
"$defs": {
"bar": {
"type": "array",
"items": {"$ref": "folderInteger.json"}
Expand Down Expand Up @@ -139,7 +135,7 @@
"$id": "http://localhost:1234/object",
"type": "object",
"properties": {
"name": {"$ref": "name.json#/definitions/orNull"}
"name": {"$ref": "name.json#/$defs/orNull"}
Copy link
Member

Choose a reason for hiding this comment

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

We may need a new /remotes/name.json:

{
    "definitions": {
        "orNull": {
            "anyOf": [
                {"type": "null"},
                {"$ref": "#"}
            ]
        }
    },
    "type": "string"
}

It has a definitions that 3 of the tests try to reference into.

  • refRemote
    • root in remote ref
      • null is valid
      • object is invalid
      • string is valid

This change updates the definitions to a $defs in the $refs causing the tests to (rightly) fail.

Copy link
Member

@gregsdennis gregsdennis Jun 17, 2019

Choose a reason for hiding this comment

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

Don't just change /remotes/name.json, though. We still need that for the other drafts. (I suppose you could add $defs with a copy of what's in definitions... ¯\_(ツ)_/¯ )

Copy link
Member Author

Choose a reason for hiding this comment

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

Ech, yes that sounds annoying to fix...

Copy link
Member

Choose a reason for hiding this comment

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

I actually tried to add $defs to name.json locally, but my implementation threw a fit because it couldn't determine which draft the schema was.

I have logic which analyzes the keywords to determine which drafts the schema conforms to if it's not specified explicitly by the $schema keyword. Since I don't list definitions as draft-8-compatible, having both it and $defs in the same schema gives it a sad.

I understand that definitions is included for backward compatibility, but I'm trying to dissuade people from using it by producing an error when it is used in a draft-8 schema.

In the end, I ended up creating a name-draft-8 file to get it passing locally.

}
},
"tests": [
Expand Down