code example
let json_v4_schema: ::serde_json::Value = serde_json::from_reader(::std::fs::File::open("/path/to/schema.json").unwrap()).unwrap();
let mut scope = ::valico::json_schema::Scope::new();
let id = scope.compile(json_v4_schema, false).unwrap();
let schema = scope.resolve(&id).unwrap();
let schema = schema.resolve_fragment(&format!("/definitions/{}", $name)).unwrap();
let schema = ::valico::json_schema::schema::ScopedSchema::new(&scope, &schema);
let o = serde_json::to_value(&foo).unwrap();
let o = schema.validate(&o);
json example
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"Response": {
"anyOf": [
{
"properties": {
"type": {
"enum": [
"error"
],
"type": "string"
},
"value": {
"$ref": "#/definitions/ErrorResponse<\"NotFoundError\">"
}
},
"required": [
"type",
"value"
],
"type": "object"
},
{
"properties": {
"type": {
"enum": [
"ok"
],
"type": "string"
},
"value": {
"type": "string"
}
},
"required": [
"type",
"value"
],
"type": "object"
}
]
},
"ErrorResponse<\"NotFoundError\">": {
"properties": {
"errorMessage": {
"type": "string"
},
"errorType": {
"enum": [
"NotFoundError"
],
"type": "string"
}
},
"required": [
"errorMessage",
"errorType"
],
"type": "object"
}
}
}
code example
json example
{ "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "Response": { "anyOf": [ { "properties": { "type": { "enum": [ "error" ], "type": "string" }, "value": { "$ref": "#/definitions/ErrorResponse<\"NotFoundError\">" } }, "required": [ "type", "value" ], "type": "object" }, { "properties": { "type": { "enum": [ "ok" ], "type": "string" }, "value": { "type": "string" } }, "required": [ "type", "value" ], "type": "object" } ] }, "ErrorResponse<\"NotFoundError\">": { "properties": { "errorMessage": { "type": "string" }, "errorType": { "enum": [ "NotFoundError" ], "type": "string" } }, "required": [ "errorMessage", "errorType" ], "type": "object" } } }