Allow schema_with attr on enum variants
This commit is contained in:
parent
2d38db903a
commit
5dc644000c
9 changed files with 93 additions and 27 deletions
|
@ -14,8 +14,8 @@ pub struct Struct {
|
|||
bar: bool,
|
||||
}
|
||||
|
||||
// Outer container should always have additionalPropreties: false
|
||||
// `Struct` variant should have additionalPropreties: false
|
||||
// Outer container should always have additionalProperties: false
|
||||
// `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub enum External {
|
||||
|
@ -38,7 +38,7 @@ fn enum_external_tag() -> TestResult {
|
|||
test_default_generated_schema::<External>("enum-external-duf")
|
||||
}
|
||||
|
||||
// Only `Struct` variant should have additionalPropreties: false
|
||||
// Only `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(tag = "typeProperty", deny_unknown_fields)]
|
||||
pub enum Internal {
|
||||
|
@ -60,7 +60,7 @@ fn enum_internal_tag() -> TestResult {
|
|||
test_default_generated_schema::<Internal>("enum-internal-duf")
|
||||
}
|
||||
|
||||
// Only `Struct` variant should have additionalPropreties: false
|
||||
// Only `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(untagged, deny_unknown_fields)]
|
||||
pub enum Untagged {
|
||||
|
@ -82,7 +82,7 @@ fn enum_untagged() -> TestResult {
|
|||
test_default_generated_schema::<Untagged>("enum-untagged-duf")
|
||||
}
|
||||
|
||||
// Outer container and `Struct` variant should have additionalPropreties: false
|
||||
// Outer container and `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(tag = "t", content = "c", deny_unknown_fields)]
|
||||
pub enum Adjacent {
|
||||
|
|
|
@ -74,6 +74,24 @@
|
|||
"minItems": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"c",
|
||||
"t"
|
||||
],
|
||||
"properties": {
|
||||
"t": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Unit"
|
||||
]
|
||||
},
|
||||
"c": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -56,6 +56,18 @@
|
|||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": [
|
||||
"unit"
|
||||
],
|
||||
"properties": {
|
||||
"unit": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
}
|
|
@ -36,6 +36,23 @@
|
|||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"boolean",
|
||||
"object"
|
||||
],
|
||||
"required": [
|
||||
"typeProperty"
|
||||
],
|
||||
"properties": {
|
||||
"typeProperty": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Unit"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -29,6 +29,9 @@
|
|||
],
|
||||
"maxItems": 2,
|
||||
"minItems": 2
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -2,8 +2,6 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
// FIXME determine whether schema_with should be allowed on unit variants
|
||||
|
||||
fn schema_fn(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
|
||||
<bool>::json_schema(gen)
|
||||
}
|
||||
|
@ -23,8 +21,8 @@ pub enum External {
|
|||
#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema,
|
||||
i32,
|
||||
),
|
||||
// #[schemars(schema_with = "schema_fn")]
|
||||
// Unit,
|
||||
#[schemars(schema_with = "schema_fn")]
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -40,8 +38,8 @@ pub enum Internal {
|
|||
foo: DoesntImplementJsonSchema,
|
||||
},
|
||||
NewType(#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema),
|
||||
// #[schemars(schema_with = "schema_fn")]
|
||||
// Unit,
|
||||
#[schemars(schema_with = "schema_fn")]
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -61,8 +59,8 @@ pub enum Untagged {
|
|||
#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema,
|
||||
i32,
|
||||
),
|
||||
// #[schemars(schema_with = "schema_fn")]
|
||||
// Unit,
|
||||
#[schemars(schema_with = "schema_fn")]
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -82,8 +80,8 @@ pub enum Adjacent {
|
|||
#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema,
|
||||
i32,
|
||||
),
|
||||
// #[schemars(schema_with = "schema_fn")]
|
||||
// Unit,
|
||||
#[schemars(schema_with = "schema_fn")]
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue