fix: honor rename_all_fields, add tests (#304)
This commit is contained in:
parent
0e8a053c74
commit
04fa0713da
5 changed files with 116 additions and 0 deletions
|
@ -146,3 +146,40 @@ enum NoVariants {}
|
|||
fn enum_no_variants() -> TestResult {
|
||||
test_default_generated_schema::<NoVariants>("no-variants")
|
||||
}
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(rename_all_fields = "PascalCase")]
|
||||
pub enum RenameAllFields {
|
||||
First {
|
||||
nested_attribute: std::string::String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RenameAll {
|
||||
First { nested_attribute: bool },
|
||||
}
|
||||
|
||||
#[derive(JsonSchema)]
|
||||
pub enum RenameAttribute {
|
||||
First {
|
||||
#[serde(rename = "RenamedAttribute")]
|
||||
nested_attribute: std::string::String,
|
||||
},
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_unit_rename_attribute() -> TestResult {
|
||||
test_default_generated_schema::<RenameAttribute>("enum-rename-attr")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_unit_rename_all_fields() -> TestResult {
|
||||
test_default_generated_schema::<RenameAllFields>("enum-rename-all-fields")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_unit_rename_all() -> TestResult {
|
||||
test_default_generated_schema::<RenameAll>("enum-rename-all")
|
||||
}
|
||||
|
|
26
schemars/tests/expected/enum-rename-all-fields.json
Normal file
26
schemars/tests/expected/enum-rename-all-fields.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"title": "RenameAllFields",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"First": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"NestedAttribute": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"NestedAttribute"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"First"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
}
|
26
schemars/tests/expected/enum-rename-all.json
Normal file
26
schemars/tests/expected/enum-rename-all.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"title": "RenameAll",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"first": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nested_attribute": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"nested_attribute"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"first"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
}
|
26
schemars/tests/expected/enum-rename-attr.json
Normal file
26
schemars/tests/expected/enum-rename-attr.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"title": "RenameAttribute",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"First": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"RenamedAttribute": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"RenamedAttribute"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"First"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
]
|
||||
}
|
|
@ -10,6 +10,7 @@ use super::get_meta_items;
|
|||
pub(crate) static SERDE_KEYWORDS: &[&str] = &[
|
||||
"rename",
|
||||
"rename_all",
|
||||
"rename_all_fields",
|
||||
"deny_unknown_fields",
|
||||
"tag",
|
||||
"content",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue