Respect #[serde(transparent)] attribute (#17)

This commit is contained in:
Graham Esau 2020-05-16 21:16:59 +01:00
parent 509a1c3b7b
commit 5a28cef598
8 changed files with 121 additions and 5 deletions

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

View 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")
}