Internally tagged enums don't honor deny_unknown_fields as precisely as
they might. flatten doesn't act quite as intended with regard to additional_properties
This commit is contained in:
parent
d549957183
commit
98ad16288b
8 changed files with 178 additions and 9 deletions
|
@ -99,3 +99,16 @@ pub enum Adjacent {
|
|||
fn enum_adjacent_tagged() -> TestResult {
|
||||
test_default_generated_schema::<Adjacent>("enum-adjacent-tagged")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(tag = "typeProperty")]
|
||||
pub enum SimpleInternal {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_simple_internal_tag() -> TestResult {
|
||||
test_default_generated_schema::<SimpleInternal>("enum-simple-internal")
|
||||
}
|
||||
|
|
|
@ -104,3 +104,16 @@ pub enum Adjacent {
|
|||
fn enum_adjacent_tagged() -> TestResult {
|
||||
test_default_generated_schema::<Adjacent>("enum-adjacent-tagged-duf")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(tag = "typeProperty", deny_unknown_fields)]
|
||||
pub enum SimpleInternal {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_simple_internal_tag() -> TestResult {
|
||||
test_default_generated_schema::<SimpleInternal>("enum-simple-internal-duf")
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"UnitOne"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
|
@ -45,7 +46,8 @@
|
|||
"UnitStructNewType"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
|
@ -106,7 +108,8 @@
|
|||
"UnitTwo"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
|
@ -124,7 +127,8 @@
|
|||
"WithInt"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
}
|
|
@ -28,9 +28,6 @@
|
|||
"StringMap"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
51
schemars/tests/expected/enum-simple-internal-duf.json
Normal file
51
schemars/tests/expected/enum-simple-internal-duf.json
Normal file
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "SimpleInternal",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"typeProperty"
|
||||
],
|
||||
"properties": {
|
||||
"typeProperty": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"A"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"typeProperty"
|
||||
],
|
||||
"properties": {
|
||||
"typeProperty": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"B"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"typeProperty"
|
||||
],
|
||||
"properties": {
|
||||
"typeProperty": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"C"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
}
|
48
schemars/tests/expected/enum-simple-internal.json
Normal file
48
schemars/tests/expected/enum-simple-internal.json
Normal file
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "SimpleInternal",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"typeProperty"
|
||||
],
|
||||
"properties": {
|
||||
"typeProperty": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"A"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"typeProperty"
|
||||
],
|
||||
"properties": {
|
||||
"typeProperty": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"B"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"typeProperty"
|
||||
],
|
||||
"properties": {
|
||||
"typeProperty": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"C"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue