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

Add "camelCase" mode #159

Closed
dnp1 opened this Issue Apr 17, 2018 · 7 comments

Comments

2 participants
@dnp1

dnp1 commented Apr 17, 2018

Hello guys,
At my company, our apis uses camelCase for all dictionnaire keys in json request and response bodies. That's a company guideline that came from the fact we communicate with several API's written in diverse languages. Since camelCase is the way variables are written in JS, we chose that.

This awesome library is quite useful for us. I'm using it, but before every request and every response I have to transform my dict.

Maybe you should support a camelCase mode just like Serde does

@samuelcolvin

This comment has been minimized.

Owner

samuelcolvin commented Apr 18, 2018

I'm not clear how pydantic needs to change. Can't you just set the attribute/field names to be camel case?

@dnp1

This comment has been minimized.

dnp1 commented Apr 18, 2018

I like PEP8, If I rename properties names I can't follow it.

Besides my own classes, the json errors returned by pydantic are written snake_case.

I would appreciated a "camelCase" mode for the same reason serde.rs support it: because of naming conventions are important. And transform every key is boring and inneficient.

@samuelcolvin

This comment has been minimized.

Owner

samuelcolvin commented Apr 18, 2018

Humm, you can already have alternative names using config fields. But it would be possible to add such a setting or allow you to easily override the base model. I'll look into it.

samuelcolvin added a commit that referenced this issue Apr 24, 2018

@samuelcolvin

This comment has been minimized.

Owner

samuelcolvin commented Apr 24, 2018

this should be fixed by #165, I've included a test showing how you would use get_field_config to apply camel case.

Let me know if that works and if so I'll merge and deploy in a couple of days.

@samuelcolvin

This comment has been minimized.

Owner

samuelcolvin commented Apr 28, 2018

ping @dnp1, does #165 satisfy your requirement?

samuelcolvin added a commit that referenced this issue May 10, 2018

allow custom get_field_config (#165)
* allow custom get_field_config, fix #159

* improving config inheritance
@dnp1

This comment has been minimized.

dnp1 commented Jun 25, 2018

@samuelcolvin , yes, it helped me!!

I'm sorry I could not ping before.
But now I'll use your feature again.

@samuelcolvin

This comment has been minimized.

Owner

samuelcolvin commented Jun 26, 2018

Pleased it helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment