parent
8207892fa6
commit
11b7a09c93
4 changed files with 235 additions and 3 deletions
|
@ -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")
|
||||
}
|
||||
|
|
150
schemars/tests/expected/enum_adjacent_tagged-untagged.json
Normal file
150
schemars/tests/expected/enum_adjacent_tagged-untagged.json
Normal 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"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue