Version 1.0
API
#475
Replies: 2 comments 3 replies
-
How do you handle cases where references can only be resolved at validation time, i.e. when there is an instance? This is how For example, from the test suite: {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main",
"if": {
"properties": {
"kindOfList": { "const": "numbers" }
},
"required": ["kindOfList"]
},
"then": { "$ref": "numberList" },
"else": { "$ref": "stringList" },
"$defs": {
"genericList": {
"$id": "genericList",
"properties": {
"list": {
"items": { "$dynamicRef": "#itemType" }
}
},
"$defs": {
"defaultItemType": {
"$comment": "Only needed to satisfy bookending requirement",
"$dynamicAnchor": "itemType"
}
}
},
"numberList": {
"$id": "numberList",
"$defs": {
"itemType": {
"$dynamicAnchor": "itemType",
"type": "number"
}
},
"$ref": "genericList"
},
"stringList": {
"$id": "stringList",
"$defs": {
"itemType": {
"$dynamicAnchor": "itemType",
"type": "string"
}
},
"$ref": "genericList"
}
}
} In this case, you don't know where This example has all of the reference targets defined in this document, but that doesn't have to be the case. |
Beta Was this translation helpful? Give feedback.
-
I am not a sophisticated user, but want to build a tool that lets devs use JSON schema in a document utility called JACS. I like Custom keywords Custom reference resolving - If I understand, a general ability to turn off all remote references would be a valuable feature. Maybe that can be done already I'm likely going to use blocking features until the need for async arrises, which is why I ask about the caching of resolutions. Hope this is helpful. [1] - |
Beta Was this translation helpful? Give feedback.
-
Here is the prototype for the
1.0
API. Please, share your concerns and ideas!Context
There are two versions of roughly the same API for JSON Schema validation - async & blocking. The async one is default and is helpful for cases when the schema contains external references, so resolving does not block.
The blocking version is available in the
blocking
module and provides functions & methods with the same signatures except for asyncness.The validation process contains two phases - building the validator and validation.
jsonschema
provides shortcuts that combine them both. They also could be used separately for performance reasons.As reference resolving happens only during the first phase, asyncness is only present in the APIs that involve this phase.
Schema & input are generic and are not restricted to
serde_json::Value
but to anything that implements theJson
trait.One-off API
A set of functions useful for running validation once with the default configuration:
Details:
Reusing validators
Details:
Output formatting
Configuration
Adjusting how validation behaves:
Custom reference resolving
Changing how resolving external references works (i.e. forbidding any external references)
Custom formats
Validate strings with a non-standard format checker:
Custom keywords
Custom validation implementation - requires
validate
and optionallyis_valid
:Errors
Depending on the final size, they could be either enums or structs (with boxed inner enum)
Beta Was this translation helpful? Give feedback.
All reactions