Add test for remote deriving with generic types
This commit is contained in:
parent
8d40625f10
commit
ea28450c30
2 changed files with 108 additions and 0 deletions
59
schemars/tests/expected/remote_derive_generic.json
Normal file
59
schemars/tests/expected/remote_derive_generic.json
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"title": "MyStruct_for_int32",
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"byte_or_bool2",
|
||||||
|
"fake_map",
|
||||||
|
"s",
|
||||||
|
"unit_or_t2"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"byte_or_bool2": {
|
||||||
|
"$ref": "#/definitions/OrDef_for_uint8_and_Boolean"
|
||||||
|
},
|
||||||
|
"fake_map": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"s": {
|
||||||
|
"$ref": "#/definitions/StrDef"
|
||||||
|
},
|
||||||
|
"unit_or_t2": {
|
||||||
|
"$ref": "#/definitions/OrDef_for_Null_and_int32"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"OrDef_for_Null_and_int32": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int32"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"OrDef_for_uint8_and_Boolean": {
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint8",
|
||||||
|
"minimum": 0.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"StrDef": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
49
schemars/tests/remote_derive_generic.rs
Normal file
49
schemars/tests/remote_derive_generic.rs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
mod util;
|
||||||
|
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
use serde::{Serialize};
|
||||||
|
use util::*;
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
enum Or<A, B> {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
A(A),
|
||||||
|
#[allow(dead_code)]
|
||||||
|
B(B),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(JsonSchema, Serialize)]
|
||||||
|
#[serde(untagged, remote = "Or")]
|
||||||
|
enum OrDef<A, B> {
|
||||||
|
A(A),
|
||||||
|
B(B),
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Str<'a>(&'a str);
|
||||||
|
|
||||||
|
#[derive(JsonSchema, Serialize)]
|
||||||
|
#[serde(remote = "Str")]
|
||||||
|
struct StrDef<'a>(&'a str);
|
||||||
|
|
||||||
|
#[derive(JsonSchema, Serialize)]
|
||||||
|
struct MyStruct<'a, T: Serialize> {
|
||||||
|
// #[serde(with = "OrDef::<_, _>")]
|
||||||
|
// byte_or_bool1: Or<u8, bool>,
|
||||||
|
#[serde(with = "OrDef::<u8, bool>")]
|
||||||
|
byte_or_bool2: Or<u8, bool>,
|
||||||
|
// #[serde(with = "OrDef::<_, _>")]
|
||||||
|
// unit_or_t1: Or<(), T>,
|
||||||
|
#[serde(with = "OrDef::<(), T>")]
|
||||||
|
unit_or_t2: Or<(), T>,
|
||||||
|
#[serde(borrow, with = "StrDef")]
|
||||||
|
s: Str<'a>,
|
||||||
|
// #[schemars(with = "HashMap::<_, HashSet<_>>")]
|
||||||
|
// map: BTreeMap<String, BTreeSet<String>>,
|
||||||
|
#[schemars(with = "HashMap::<String, HashSet<String>>")]
|
||||||
|
fake_map: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn remote_derive_json_schema() -> TestResult {
|
||||||
|
test_default_generated_schema::<MyStruct<i32>>("remote_derive_generic")
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue