-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
47 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use anyhow::{anyhow, Result}; | ||
use jsonschema::Validator; | ||
use lazy_static::lazy_static; | ||
use serde_json::{json, Value}; | ||
|
||
struct DummyResolver {} | ||
impl jsonschema::Retrieve for DummyResolver { | ||
fn retrieve( | ||
&self, | ||
uri: &jsonschema::Uri<&str>, | ||
) -> std::result::Result<Value, Box<dyn std::error::Error + Send + Sync>> { | ||
Err(anyhow!("external resolver disabled (url: {})", uri).into()) | ||
} | ||
} | ||
|
||
lazy_static! { | ||
static ref SCHEMA_VALIDATOR: Validator = { | ||
Validator::options() | ||
.with_draft(jsonschema::Draft::Draft7) | ||
.with_retriever(DummyResolver {}) | ||
.build(&json!({ | ||
"$ref": "http://json-schema.org/draft-07/schema" | ||
})) | ||
.unwrap() | ||
}; | ||
} | ||
|
||
pub fn validate_schema(schema: &Value) -> Result<()> { | ||
SCHEMA_VALIDATOR | ||
.validate(schema) | ||
.map_err(|mut e| anyhow!("Invalid schema: {}", e.next().unwrap())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters