Implement JsonSchema for std::time types
This commit is contained in:
parent
155190c9ab
commit
e11d5e5a98
4 changed files with 95 additions and 0 deletions
45
schemars/tests/expected/duration_and_systemtime.json
Normal file
45
schemars/tests/expected/duration_and_systemtime.json
Normal 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
15
schemars/tests/time.rs
Normal 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue