Implement JsonSchema for Result<T,E>
This commit is contained in:
parent
3d68dbe929
commit
155190c9ab
4 changed files with 107 additions and 8 deletions
46
schemars/tests/expected/result.json
Normal file
46
schemars/tests/expected/result.json
Normal 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
13
schemars/tests/result.rs
Normal 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue