Open IrrerPolterer opened 1 year ago
Hey,
That's the good one! We do the same within our projects 💯
I didn't include it in the list since not every project needs camelCase, but this issue could be a good reference for those who do 👍
the new version of Pydantic includes all of these built-in, no need to install humps anymore:
from pydantic import BaseModel
from pydantic.alias_generators import to_camel
class BaseSchema(BaseModel):
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True,
)
I want to be able to both...
For this I'm using a custom base model for pretty much all my Pydantic schemas:
(This requires the pyHumps package.)
With this BaseSchema, I can now create pydantic schemas with the intended behavior:
My solution above uses the
camelize
function from the pyhumps package. Alternatively, you can create the function yourself like this: