When using serde's rename_all_fields on an enum together with schemars, the fields are not properly renamed in the schema.
Only explicitly renaming each and every field renames them.
How to reproduce
use schemars::{schema_for, JsonSchema};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, PartialEq)]
#[serde(tag = "Variant")]
#[serde(rename_all = "lowercase")]
#[serde(rename_all_fields = "PascalCase")]
pub enum Example {
First {
nested_attribute: String,
},
Second {
#[serde(rename = "AnotherAttribute")]
another_attribute: String,
},
}
fn main() {
let schema = schema_for!(Example);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
let example1 = Example::First { nested_attribute: "foo".to_owned()};
println!("{}", serde_json::to_string_pretty(&example1).unwrap());
let example2 = Example::Second { another_attribute: "foo".to_owned()};
println!("{}", serde_json::to_string_pretty(&example2).unwrap());
}
Description
When using serde's rename_all_fields on an enum together with schemars, the fields are not properly renamed in the schema. Only explicitly renaming each and every field renames them.
How to reproduce
Output:
❗ comments are mine