evestera / json_typegen

Tools and libraries to create types for Rust, Kotlin, TypeScript and Python from JSON samples
https://typegen.vestera.as
Apache License 2.0
268 stars 26 forks source link

Use rename_all attribute #1

Closed dtolnay closed 4 years ago

dtolnay commented 7 years ago

Amazing work!

I noticed this behavior:

{
  "aaAaaAaa": 0,
  "bbBbbBbb": 0,
  "ccCccCcc": 0
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
struct ZalandoArticle {
    #[serde(rename = "aaAaaAaa")]
    aa_aaa_aaa: i64,
    #[serde(rename = "bbBbbBbb")]
    bb_bbb_bbb: i64,
    #[serde(rename = "ccCccCcc")]
    cc_ccc_ccc: i64,
}

This would be more friendly using rename_all instead:

#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct ZalandoArticle {
    aa_aaa_aaa: i64,
    bb_bbb_bbb: i64,
    cc_ccc_ccc: i64,
}

The supported renames are "lowercase" (which you won't need, mostly for enums), "PascalCase", "camelCase", "snake_case" (also for enum variants), "SCREAMING_SNAKE_CASE", "kebab-case".

evestera commented 7 years ago

Thanks!

Yes, I've looked at that rename_all, and it does look quite a bit nicer when you actually see the generated code, so I would certainly like to use rename_all in the future. Just prioritizing the biggest flaws first (at the moment duplicate type names).

evestera commented 4 years ago

Took a while, but finally implemented now in release 0.4 🎉