Implement JsonSchema for std::time types

This commit is contained in:
Graham Esau 2019-10-27 18:57:36 +00:00
parent 155190c9ab
commit e11d5e5a98
4 changed files with 95 additions and 0 deletions

View file

@ -0,0 +1,45 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MyStruct",
"type": "object",
"required": [
"duration",
"time"
],
"properties": {
"duration": {
"$ref": "#/definitions/Duration"
},
"time": {
"$ref": "#/definitions/SystemTime"
}
},
"definitions": {
"Duration": {
"type": "object",
"properties": {
"nanos": {
"type": "integer",
"format": "uint32"
},
"secs": {
"type": "integer",
"format": "uint64"
}
}
},
"SystemTime": {
"type": "object",
"properties": {
"nanos_since_epoch": {
"type": "integer",
"format": "uint32"
},
"secs_since_epoch": {
"type": "integer",
"format": "uint64"
}
}
}
}
}

15
schemars/tests/time.rs Normal file
View file

@ -0,0 +1,15 @@
mod util;
use schemars::JsonSchema;
use util::*;
use std::time::{Duration, SystemTime};
#[derive(Debug, JsonSchema)]
struct MyStruct {
duration: Duration,
time: SystemTime,
}
#[test]
fn duration_and_systemtime() -> TestResult {
test_default_generated_schema::<MyStruct>("duration_and_systemtime")
}