Skip to content

Commit

Permalink
some tests of the interactions between $id, $anchor and $ref
Browse files Browse the repository at this point in the history
  • Loading branch information
karenetheridge committed Jun 3, 2020
1 parent c3f4319 commit 9d0c502
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/draft2019-09/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,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/draft2019-09/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,36 @@
"valid": true
}
]
},
{
"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/draft2019-09/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,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": "/base/base.json",
"$ref": "int.json",
"$defs": {
"bigint": {
"$comment": "canonical uri: /base/int.json",
"$id": "int.json",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /int.json",
"$id": "/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": "/base.json",
"$ref": "#bigint",
"$defs": {
"bigint": {
"$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint",
"$anchor": "bigint",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#bigint",
"$id": "/",
"$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
}
]
}
]
64 changes: 64 additions & 0 deletions tests/draft6/id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[
{
"description": "non-schema object containing a plain-name $id property",
"schema": {
"$defs": {
"const_not_anchor": {
"const": {
"$id": "#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
}
]
},
{
"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
}
]
}
]
64 changes: 64 additions & 0 deletions tests/draft7/id.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[
{
"description": "non-schema object containing a plain-name $id property",
"schema": {
"$defs": {
"const_not_anchor": {
"const": {
"$id": "#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
}
]
},
{
"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
}
]
}
]
64 changes: 64 additions & 0 deletions tests/draft7/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,5 +439,69 @@
"valid": false
}
]
},
{
"description": "order of evaluation: $id and $ref",
"schema": {
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
"$id": "/base/base.json",
"$ref": "int.json",
"$defs": {
"bigint": {
"$comment": "canonical uri: /base/int.json",
"$id": "int.json",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /int.json",
"$id": "/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: plain-name $id and $ref",
"schema": {
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
"$id": "/base.json",
"$ref": "#bigint",
"$defs": {
"bigint": {
"$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint",
"$id": "#bigint",
"maximum": 10
},
"smallint": {
"$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#bigint",
"$id": "/#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
}
]
}
]

0 comments on commit 9d0c502

Please sign in to comment.