-
Notifications
You must be signed in to change notification settings - Fork 39
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
how to deal with snake case vs. camel case in Python vs. JSON? #109
Comments
Usually what I have seen in the wild is that python based backends return snake case JSON and the frontend deals with it. But it's most likely easy to create a converter between the two on (de)serialization. |
+1 to @Sytten 's response. For what its worth, the PEP-8 rule only applies to names, not strings. So And If seeing any camelCase at all in your code makes you squeamish, maybe this excerpt from The Zen of Python will help you find solace:
Also, an opinion (although I believe many will agree): And, similarly, it's often wise for clients to explicitly load JSON objects returned from a server into their own objects, which might include explicitly converting snake_case attributes to camelCase. |
I don't really have anything to add :) Just assigning the "question" label in keeping with my "all issues shall get labels" policy 😂 Will keep this one open for as long as people wanna discuss. Cheers! |
Thanks for thinking about this! Would you accept a PR that added a mixin like the one in marshmallow-code/marshmallow#1295 (similar to the other Schema helpers that Rebar provides in validation.py) to avoid each Rebar user having to figure out a boilerplate solution independently (or come up with their own worse solutions)? /cc @dLuna in case you want to chime in! |
What I would suggest is to allow the customization of Schema helpers (if that is not already the case, I don't remember) and write your validator as a plugin (similar to what I did for auth0). I don't think it should go in the core since this is very dependent on the team. |
Steven Loria just added a |
Just to briefly chime in; I'm not 100% convinced either way myself on the "should/n't we include a helper for this", but if we can figure out a good location to include something that:
|
Thanks @RookieRick, and good luck with what you're working on! |
So I spent some time playing with this today.. At one point I thought I had it figured out but then it also looks like that approach would break as soon as we build in support for Marshmallow 3.0.. Little did I realize at first that for Marshmallow 2.0 I was kind of exploiting the fact that it seems they call |
So to expand on this a bit.. A synopsis of what I had tried on Friday can be seen in this commit: 0eb94aa - it seemed like a promising approach at first, but as noted in the previous comment, Marshmallow 3.0 gets smarter about how often it needs to actually look at things like At this point, the best idea that is still rattling around in the back of my mind is something like a
Since it's entirely marshmallow-related, I'm also leaning toward Sytten's suggestion that this could/should be a separate optional library that users of Flask-Rebar (or any other marshmallow thing) could incorporate when they define their schema subclasses. What do you think @twosigmajab , you want to add that to your OSS resume and we could link to it from Rebar's docs? 😀 |
Update: We've starting using something similar to this internally, see the link for the v3 example.
|
Hi Rebar maintainers and community, just wondering, how are y'all coping with marshmallow-code/marshmallow#1295?
Are we all just reinventing this wheel slightly differently in our own code? Settling for snake_case fields in our JSON or (PEP-8-violating) camelCase fields in our Python? Something else? Thanks in advance for any helpful discussion 😅
The text was updated successfully, but these errors were encountered: