Enable deriving JsonSchema on adjacent tagged enums

Issue #4
This commit is contained in:
Graham Esau 2020-04-30 14:21:04 +01:00
parent 8207892fa6
commit 11b7a09c93
4 changed files with 235 additions and 3 deletions

View file

@ -59,3 +59,19 @@ pub enum Untagged {
fn enum_untagged() -> TestResult {
test_default_generated_schema::<Untagged>("enum-untagged")
}
#[derive(Debug, JsonSchema)]
#[schemars(tag = "t", content = "c")]
pub enum Adjacent {
UnitOne,
StringMap(Map<String, String>),
UnitStructNewType(UnitStruct),
StructNewType(Struct),
Struct { foo: i32, bar: bool },
Tuple(i32, bool),
}
#[test]
fn enum_adjacent_tagged() -> TestResult {
test_default_generated_schema::<Adjacent>("enum_adjacent_tagged-untagged")
}

View file

@ -0,0 +1,150 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Adjacent",
"anyOf": [
{
"type": "object",
"required": [
"t"
],
"properties": {
"t": {
"type": "string",
"enum": [
"UnitOne"
]
}
}
},
{
"type": "object",
"required": [
"c",
"t"
],
"properties": {
"c": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"t": {
"type": "string",
"enum": [
"StringMap"
]
}
}
},
{
"type": "object",
"required": [
"c",
"t"
],
"properties": {
"c": {
"type": "null"
},
"t": {
"type": "string",
"enum": [
"UnitStructNewType"
]
}
}
},
{
"type": "object",
"required": [
"c",
"t"
],
"properties": {
"c": {
"type": "object",
"required": [
"bar",
"foo"
],
"properties": {
"bar": {
"type": "boolean"
},
"foo": {
"type": "integer",
"format": "int32"
}
}
},
"t": {
"type": "string",
"enum": [
"StructNewType"
]
}
}
},
{
"type": "object",
"required": [
"c",
"t"
],
"properties": {
"c": {
"type": "object",
"required": [
"bar",
"foo"
],
"properties": {
"bar": {
"type": "boolean"
},
"foo": {
"type": "integer",
"format": "int32"
}
}
},
"t": {
"type": "string",
"enum": [
"Struct"
]
}
}
},
{
"type": "object",
"required": [
"c",
"t"
],
"properties": {
"c": {
"type": "array",
"items": [
{
"type": "integer",
"format": "int32"
},
{
"type": "boolean"
}
],
"maxItems": 2,
"minItems": 2
},
"t": {
"type": "string",
"enum": [
"Tuple"
]
}
}
}
]
}