Enable eriving JsonSchema when fields are in remote crates
This commit is contained in:
parent
8d68e36f7c
commit
709ba7b62e
4 changed files with 133 additions and 14 deletions
44
schemars/tests/expected/remote_derive.json
Normal file
44
schemars/tests/expected/remote_derive.json
Normal 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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
37
schemars/tests/remote_derive.rs
Normal file
37
schemars/tests/remote_derive.rs
Normal 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue