Enable eriving JsonSchema when fields are in remote crates

This commit is contained in:
Graham Esau 2019-09-12 18:02:37 +01:00
parent 8d68e36f7c
commit 709ba7b62e
4 changed files with 133 additions and 14 deletions

View file

@ -0,0 +1,44 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Process",
"type": "object",
"properties": {
"command_line": {
"type": "string"
},
"system_cpu_time": {
"$ref": "#/definitions/DurationDef"
},
"user_cpu_time": {
"$ref": "#/definitions/DurationDef"
},
"wall_time": {
"$ref": "#/definitions/DurationDef"
}
},
"required": [
"command_line",
"system_cpu_time",
"user_cpu_time",
"wall_time"
],
"definitions": {
"DurationDef": {
"type": "object",
"properties": {
"nanos": {
"type": "integer",
"format": "int32"
},
"secs": {
"type": "integer",
"format": "int64"
}
},
"required": [
"nanos",
"secs"
]
}
}
}

View file

@ -0,0 +1,37 @@
mod util;
use other_crate::Duration;
use schemars::JsonSchema;
use util::*;
mod other_crate {
#[derive(Debug)]
pub struct Duration {
pub secs: i64,
pub nanos: i32,
}
}
#[derive(Debug, JsonSchema)]
#[serde(remote = "Duration")]
struct DurationDef {
secs: i64,
nanos: i32,
}
#[derive(Debug, JsonSchema)]
struct Process {
command_line: String,
#[serde(with = "DurationDef")]
wall_time: Duration,
#[serde(with = "DurationDef")]
user_cpu_time: Duration,
#[serde(deserialize_with = "some_serialize_function")]
#[schemars(with = "DurationDef")]
system_cpu_time: Duration,
}
#[test]
fn remote_derive_json_schema() -> TestResult {
test_default_generated_schema::<Process>("remote_derive")
}