Respect #[serde(transparent)] attribute (#17)
This commit is contained in:
parent
509a1c3b7b
commit
5a28cef598
8 changed files with 121 additions and 5 deletions
33
schemars/tests/expected/transparent-struct.json
Normal file
33
schemars/tests/expected/transparent-struct.json
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "OuterStruct",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"inner": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/InnerStruct"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"InnerStruct": {
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
"minItems": 2
|
||||
}
|
||||
}
|
||||
}
|
27
schemars/tests/transparent.rs
Normal file
27
schemars/tests/transparent.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
mod util;
|
||||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct OuterStruct {
|
||||
inner: TransparentStruct,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[serde(transparent)]
|
||||
pub struct TransparentStruct {
|
||||
#[serde(with = "TransparentNewType")]
|
||||
inner: (),
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(transparent)]
|
||||
pub struct TransparentNewType(Option<InnerStruct>);
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct InnerStruct(String, i32);
|
||||
|
||||
#[test]
|
||||
fn transparent_struct() -> TestResult {
|
||||
test_default_generated_schema::<OuterStruct>("transparent-struct")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue