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

schema_extra param not passed to pydantic_model_{output | optional | plural} methods #246

Open
hoosnick opened this issue Jul 29, 2023 · 1 comment

Comments

@hoosnick
Copy link

@property
def pydantic_model(self) -> t.Type[pydantic.BaseModel]:
"""
Useful for serialising inbound data from POST and PUT requests.
"""
return create_pydantic_model(
self.table,
model_name=f"{self.table.__name__}In",
exclude_columns=(self.table._meta.primary_key,),
**self.schema_extra,
)

Why is schema_extra not passed to the following methods as in this method above?

pydantic_model_output
pydantic_model_optional
pydantic_model_plural

When I use my pydantic basic config it only works for ModelIn and others don't

def to_camel(string: str) -> str:
    string_split = string.split("_")
    return string_split[0] + "".join(word.capitalize() for word in string_split[1:])

class MyConfig(pydantic.BaseConfig):
    alias_generator = to_camel
    allow_population_by_field_name = True

chat_crud = PiccoloCRUD(
    table=Message,
    read_only=False,
    max_joins=2,
    schema_extra={
        'pydantic_config_class': MyConfig
    }
)

It is convenient for my frontend that every input and output field is in camelCase. As another solution, I could name each field in my Table as camelCase, but then I would have to change my backend structure.

hoosnick added a commit to hoosnick/piccolo_api that referenced this issue Jul 29, 2023
@hoosnick
Copy link
Author

hoosnick commented Jul 29, 2023

#248

@hoosnick hoosnick changed the title scheme_extra param not passed to pydantic_model_{output | optional | plural} methods schema_extra param not passed to pydantic_model_{output | optional | plural} methods Jul 29, 2023
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

1 participant