Skip to content
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

some tests of the interactions between $id, $anchor and $ref #383

Merged
merged 3 commits into from
Jun 22, 2022
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
31 changes: 31 additions & 0 deletions tests/draft-next/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,36 @@
"valid": false
}
]
},
{
"description": "non-schema object containing an $anchor property",
"schema": {
"$defs": {
"const_not_anchor": {
"const": {
"$anchor": "not_a_real_anchor"
}
}
},
"if": {
"const": "skip not_a_real_anchor"
},
"then": true,
"else" : {
"$ref": "#/$defs/const_not_anchor"
}
},
"tests": [
{
"description": "skip traversing definition for a valid result",
"data": "skip not_a_real_anchor",
"valid": true
},
{
"description": "const at const_not_anchor does not match",
"data": 1,
"valid": false
}
]
}
]
31 changes: 31 additions & 0 deletions tests/draft-next/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,36 @@
"valid": false
}
]
},
{
"description": "non-schema object containing an $id property",
"schema": {
"$defs": {
"const_not_id": {
"const": {
"$id": "not_a_real_id"
}
}
},
"if": {
"const": "skip not_a_real_id"
},
"then": true,
"else" : {
"$ref": "#/$defs/const_not_id"
}
},
"tests": [
{
"description": "skip traversing definition for a valid result",
"data": "skip not_a_real_id",
"valid": true
},
{
"description": "const at const_not_id does not match",
"data": 1,
"valid": false
}
]
}
]
65 changes: 65 additions & 0 deletions tests/draft-next/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -577,5 +577,70 @@
"valid": false
}
]
},
{
"description": "order of evaluation: $id and $ref",
"schema": {
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
"$id": "/ref-and-id1/base.json",
"$ref": "int.json",
"$defs": {
"bigint": {
"$comment": "canonical uri: /ref-and-id1/int.json",
"$id": "int.json",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /ref-and-id1-int.json",
"$id": "/ref-and-id1-int.json",
"maximum": 2
}
}
},
"tests": [
{
"description": "data is valid against first definition",
"data": 5,
"valid": true
},
{
"description": "data is invalid against first definition",
"data": 50,
"valid": false
}
]
},
{
"description": "order of evaluation: $id and $anchor and $ref",
"schema": {
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
"$id": "/ref-and-id2/base.json",
"$ref": "#bigint",
"$defs": {
"bigint": {
"$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint",
"$anchor": "bigint",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint",
"$id": "/ref-and-id2/",
"$anchor": "bigint",
"maximum": 2
}
}
},
"tests": [
{
"description": "data is valid against first definition",
"data": 5,
"valid": true
},
{
"description": "data is invalid against first definition",
"data": 50,
"valid": false
}
]
}
]
31 changes: 31 additions & 0 deletions tests/draft2019-09/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,36 @@
"valid": false
}
]
},
{
"description": "non-schema object containing an $anchor property",
"schema": {
"$defs": {
"const_not_anchor": {
"const": {
"$anchor": "not_a_real_anchor"
}
}
},
"if": {
"const": "skip not_a_real_anchor"
},
"then": true,
"else" : {
"$ref": "#/$defs/const_not_anchor"
}
},
"tests": [
{
"description": "skip traversing definition for a valid result",
"data": "skip not_a_real_anchor",
"valid": true
},
{
"description": "const at const_not_anchor does not match",
"data": 1,
"valid": false
}
]
}
]
35 changes: 34 additions & 1 deletion tests/draft2019-09/id.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[
{
"description": "Invalid use of fragments in location-independent $id",
"schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
"schema": {
"$ref": "https://json-schema.org/draft/2019-09/schema"
},
"tests": [
{
"description": "Identifier name",
Expand Down Expand Up @@ -252,5 +254,36 @@
"valid": false
}
]
},
{
"description": "non-schema object containing an $id property",
"schema": {
"$defs": {
"const_not_id": {
"const": {
"$id": "not_a_real_id"
}
}
},
"if": {
"const": "skip not_a_real_id"
},
"then": true,
"else" : {
"$ref": "#/$defs/const_not_id"
}
},
"tests": [
{
"description": "skip traversing definition for a valid result",
"data": "skip not_a_real_id",
"valid": true
},
{
"description": "const at const_not_id does not match",
"data": 1,
"valid": false
}
]
}
]
73 changes: 70 additions & 3 deletions tests/draft2019-09/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@
},
{
"description": "remote ref, containing refs itself",
"schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
"schema": {
"$ref": "https://json-schema.org/draft/2019-09/schema"
},
"tests": [
{
"description": "remote ref valid",
Expand Down Expand Up @@ -298,7 +300,7 @@
"tests": [
{
"description": "valid tree",
"data": {
"data": {
"meta": "root",
"nodes": [
{
Expand Down Expand Up @@ -327,7 +329,7 @@
},
{
"description": "invalid tree",
"data": {
"data": {
"meta": "root",
"nodes": [
{
Expand Down Expand Up @@ -575,5 +577,70 @@
"valid": false
}
]
},
{
"description": "order of evaluation: $id and $ref",
"schema": {
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
"$id": "/ref-and-id1/base.json",
"$ref": "int.json",
"$defs": {
"bigint": {
"$comment": "canonical uri: /ref-and-id1/int.json",
"$id": "int.json",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /ref-and-id1-int.json",
"$id": "/ref-and-id1-int.json",
"maximum": 2
}
}
},
"tests": [
{
"description": "data is valid against first definition",
"data": 5,
"valid": true
},
{
"description": "data is invalid against first definition",
"data": 50,
"valid": false
}
]
},
{
"description": "order of evaluation: $id and $anchor and $ref",
"schema": {
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
"$id": "/ref-and-id2/base.json",
"$ref": "#bigint",
"$defs": {
"bigint": {
"$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint",
"$anchor": "bigint",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint",
"$id": "/ref-and-id2/",
"$anchor": "bigint",
"maximum": 2
}
}
},
"tests": [
{
"description": "data is valid against first definition",
"data": 5,
"valid": true
},
{
"description": "data is invalid against first definition",
"data": 50,
"valid": false
}
]
}
]
31 changes: 31 additions & 0 deletions tests/draft2020-12/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,36 @@
"valid": false
}
]
},
{
"description": "non-schema object containing an $anchor property",
"schema": {
"$defs": {
"const_not_anchor": {
"const": {
"$anchor": "not_a_real_anchor"
}
}
},
"if": {
"const": "skip not_a_real_anchor"
},
"then": true,
"else" : {
"$ref": "#/$defs/const_not_anchor"
}
},
"tests": [
{
"description": "skip traversing definition for a valid result",
"data": "skip not_a_real_anchor",
"valid": true
},
{
"description": "const at const_not_anchor does not match",
"data": 1,
"valid": false
}
]
}
]
Loading