Implement JsonSchema for Result<T,E>

This commit is contained in:
Graham Esau 2019-10-27 18:40:57 +00:00
parent 3d68dbe929
commit 155190c9ab
4 changed files with 107 additions and 8 deletions

View file

@ -0,0 +1,46 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Result_Of_MyStruct_Or_Array_Of_String",
"type": "object",
"anyOf": [
{
"type": "object",
"required": [
"Ok"
],
"properties": {
"Ok": {
"$ref": "#/definitions/MyStruct"
}
}
},
{
"type": "object",
"required": [
"Err"
],
"properties": {
"Err": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
],
"definitions": {
"MyStruct": {
"type": "object",
"required": [
"foo"
],
"properties": {
"foo": {
"type": "integer",
"format": "int32"
}
}
}
}
}

13
schemars/tests/result.rs Normal file
View file

@ -0,0 +1,13 @@
mod util;
use schemars::JsonSchema;
use util::*;
#[derive(Debug, JsonSchema)]
struct MyStruct {
foo: i32,
}
#[test]
fn result() -> TestResult {
test_default_generated_schema::<Result<MyStruct, Vec<String>>>("result")
}