Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect serde renames for paths #127

Open
leebenson opened this issue Aug 30, 2024 · 2 comments
Open

Respect serde renames for paths #127

leebenson opened this issue Aug 30, 2024 · 2 comments

Comments

@leebenson
Copy link

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.

@jprochazk
Copy link
Owner

jprochazk commented Aug 30, 2024

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)

@leebenson
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants