doubts about ref.json test. #634
-
Hello, I have a doubt about the particular test in the test suit ref.json#L179 : {
"description": "$ref prevents a sibling $id from changing the base uri",
"schema": {
"$id": "http://localhost:1234/sibling_id/base/",
"definitions": {
"foo": {
"$id": "http://localhost:1234/sibling_id/foo.json",
"type": "string"
},
"base_foo": {
"$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json",
"$id": "foo.json",
"type": "number"
}
},
"allOf": [
{
"$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json",
"$id": "http://localhost:1234/sibling_id/",
"$ref": "foo.json"
}
]
},
"tests": [
{
"description": "$ref resolves to /definitions/base_foo, data does not validate",
"data": "a",
"valid": false
},
{
"description": "$ref resolves to /definitions/base_foo, data validates",
"data": 1,
"valid": true
}
]
} Is the "definitions" keyword is just a convention or is a part of the specification? Thank you, D. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It's kind of both part of the specification and convention. A reference will evaluate anything you point to as a schema. For example, this should work. {
"type": "object",
"properties": {
"aaa": { "$ref": "#/mydefs/foo" }
},
"mydefs": {
"foo": { "type": "string" }
}
} However, the validator doesn't know the {
"type": "object",
"properties": {
"aaa": { "$ref": "/foo" }
},
"mydefs": {
"foo": {
"id": "/foo",
"type": "string"
}
}
} The However, Note that |
Beta Was this translation helpful? Give feedback.
-
Thank you, Jason for clearing it. That was the question - whether I must always parse "definitions" (otherwise no $id(s) or $anchor(s) would be recovered while json pointer may fail). |
Beta Was this translation helpful? Give feedback.
It's kind of both part of the specification and convention. A reference will evaluate anything you point to as a schema. For example, this should work.
However, the validator doesn't know the
mydefs
keyword and doesn't know that it's values are schemas. This example wouldn't work.The
id
isn't recognized as an identifier because the validator doesn't know thatmydefs
values should be processed as schem…