sqlalchemy-pydantic-orm icon indicating copy to clipboard operation
sqlalchemy-pydantic-orm copied to clipboard

Integrate with fastapi_camelcase

Open project-DnCo opened this issue 1 year ago • 2 comments

I think we need some kind of possibility to mix sqlalchemy_pydantic_orm.ORMBaseSchema and fastapi_camelcase.CamelModel. So that it is possible to create compatible nested schemas and models with snake_case attributes but still have camelCase`d ones on the frontend.

project-DnCo avatar Jun 22 '23 07:06 project-DnCo

Have you already tried using these 2 together, I don't immediately see a reason for conflict. But maybe I'm missing something.

All that the fastapi_camelcase library does is set 2 config variables: https://github.com/nf1s/fastapi-camelcase/blob/master/fastapi_camelcase/init.py

Maybe try something like:

from humps import camelize
from sqlalchemy_pydantic_orm import ORMBaseSchema

class MyBaseModel(ORMBaseSchema):
    class Config(ORMBaseSchema.Config):
        alias_generator = camelize
        allow_population_by_field_name = True

Does this work? (Haven't tried it myself)

Wouterkoorn avatar Jun 22 '23 19:06 Wouterkoorn

Have you already tried using these 2 together, I don't immediately see a reason for conflict.

It works. The point is, I missed something. Sorry for not answering earlier.

project-DnCo avatar Dec 17 '23 18:12 project-DnCo