Should an implementation know all schemas with their canonical URIs before evaluation? #235
-
Hello. I'd like to clarify my understanding on how {
"description": "refs with relative uris and defs",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "http://example.com/schema-relative-uri-defs1.json",
"properties": {
"foo": {
"$id": "schema-relative-uri-defs2.json",
"$defs": {
"inner": {
"properties": {
"bar": {
"type": "string"
}
}
}
},
"$ref": "#/$defs/inner"
}
},
"$ref": "schema-relative-uri-defs2.json"
},
"tests": [
{
"description": "invalid on inner field",
"data": {
"foo": {
"bar": 1
},
"bar": "a"
},
"valid": false
},
{
"description": "invalid on outer field",
"data": {
"foo": {
"bar": "a"
},
"bar": 1
},
"valid": false
},
{
"description": "valid on both fields",
"data": {
"foo": {
"bar": "a"
},
"bar": "a"
},
"valid": true
}
]
} How I understand evaluation process:
Should implementation process the document twice: first time for collecting all schemas and their canonical URIs and the second time for actual processing the schema (like validation or code generation)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Most implementations do have this two-stage processing where the first stage is scanning for internally-defined schemas, and the second is processing. A bit more expansively, implementations are recommended against downloading content, so preloading them is the preferred approach. Mine has a registry that allows users to load any references schemas ahead of validation. For convenience, I also have a fetch function that is disabled by default. My docs also warn about potential security risks when downloading content. |
Beta Was this translation helpful? Give feedback.
Most implementations do have this two-stage processing where the first stage is scanning for internally-defined schemas, and the second is processing.
A bit more expansively, implementations are recommended against downloading content, so preloading them is the preferred approach. Mine has a registry that allows users to load any references schemas ahead of validation. For convenience, I also have a fetch function that is disabled by default. My docs also warn about potential security risks when downloading content.