-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
feat: Async retriever #703
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #703 +/- ##
==========================================
+ Coverage 85.31% 85.99% +0.67%
==========================================
Files 94 94
Lines 14448 15220 +772
==========================================
+ Hits 12327 13089 +762
- Misses 2121 2131 +10 ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #703 will not alter performanceComparing Summary
|
bd74f0f
to
10baec1
Compare
Tagging @uncenter @gadomski because of your recent PRs (in This is a very early iteration for async retrieval of external schemas, but it works (the original message with an example above)! If you have any feedback on the API or think that I've missed something here, please, let me know :) I plan to work more on this feature so it covers your use cases and has the least amount of rough edges in terms of usability and ergonomics. |
29fe45c
to
0ec3e10
Compare
57710cf
to
a45cdcb
Compare
With the latest update, the following would work for the simplest case: let validator = jsonschema::async_validator_for(&schema).await?; And custom non-blocking retrievers are also possible: use serde_json::{Value, json};
use jsonschema::{Draft, AsyncRetrieve, Uri};
// Custom async retriever
struct MyRetriever;
#[async_trait::async_trait]
impl AsyncRetrieve for MyRetriever {
async fn retrieve(&self, uri: &Uri<String>) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
// Custom retrieval logic
Ok(json!({}))
}
}
let schema = json!({
"$ref": "https://example.com/user.json"
});
let validator = jsonschema::async_options()
.with_draft(Draft::Draft202012)
.with_retriever(MyRetriever)
.build(&schema)
.await?; I hope it should be enough for the majority of use cases |
9f4fcb8
to
a842dad
Compare
Signed-off-by: Dmitry Dygalo <[email protected]>
a842dad
to
e2c36be
Compare
Resolves #385