garde icon indicating copy to clipboard operation
garde copied to clipboard

Respect serde renames for paths

Open leebenson opened this issue 1 year ago • 2 comments

Is there an obvious way to have garde respect serde rules (specifically, serde(rename_all = "camelCase")) for validation paths?

My public-facing input types are camel-cased to match the Javascript convention, but internally are snake-cased for Rust. When mapping errors back to form fields, I'd like to reflect the same convention.

Thanks.

leebenson avatar Aug 30 '24 18:08 leebenson

There is not, unfortunately. I don't know what the convention for that is, but it feels wrong to read serde's attributes for this.

Implementing our own rename attributes would probably look like:

  • Parsing the new attributes (rename on field-level, rename_all on struct-level)
  • Following the code to thread those attributes through to this line and update the key.to_string() based on whatever rename rule is used (either the struct-level case convert, or field-level rename to specific key, prioritizing the field-level over struct-level rename)

jprochazk avatar Aug 30 '24 19:08 jprochazk

Thanks. Agreed, I think a garde-level rename makes sense 👍🏻 FWIW, I'm using Poem's #[oai(rename_all...) attribute for serialising input, which is effectively the same approach.

leebenson avatar Aug 30 '24 19:08 leebenson

Implemented #157 using guidance from @jprochazk's reply. Did not implement the rename_all as it was a bit out of scope for me.

tsidea avatar Dec 12 '25 16:12 tsidea