Implement JsonSchema for Bound

This commit is contained in:
Graham Esau 2019-10-30 19:39:44 +00:00
parent 3f56d6b282
commit 5503f0697f
3 changed files with 69 additions and 2 deletions

View file

@ -3,10 +3,14 @@
"title": "MyStruct",
"type": "object",
"required": [
"bound",
"inclusive",
"range"
],
"properties": {
"bound": {
"$ref": "#/definitions/Bound_of_String"
},
"inclusive": {
"$ref": "#/definitions/Range_of_double"
},
@ -15,6 +19,36 @@
}
},
"definitions": {
"Bound_of_String": {
"oneOf": [
{
"type": "object",
"required": [
"Included"
],
"properties": {
"Included": {
"type": "string"
}
}
},
{
"type": "object",
"required": [
"Excluded"
],
"properties": {
"Excluded": {
"type": "string"
}
}
},
{
"type": "string",
"const": "Unbounded"
}
]
},
"Range_of_double": {
"type": "object",
"required": [

View file

@ -1,12 +1,13 @@
mod util;
use schemars::JsonSchema;
use std::ops::{Bound, Range, RangeInclusive};
use util::*;
use std::ops::{Range, RangeInclusive};
#[derive(Debug, JsonSchema)]
struct MyStruct {
range: Range<usize>,
inclusive: RangeInclusive<f64>,
bound: Bound<String>
}
#[test]