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
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