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

Is there a way to convert key casing in responses? #14

Closed
eboddington opened this issue Sep 10, 2020 · 3 comments
Closed

Is there a way to convert key casing in responses? #14

eboddington opened this issue Sep 10, 2020 · 3 comments

Comments

@eboddington
Copy link

I'd like to have my Pydantic models defined in snake_case but have the API return JSON with camelCase fields.

In FastAPI, I can do the following:

def to_camel(string: str):
    # returns "string" converted to camelCase

class MyModel(BaseModel):
    foo_bar: str

    class Config:
        alias_generator = to_camel
        allow_population_by_field_name = True

And the resulting JSON will be {"fooBar": "x"}. This is similar to the way it's described in the Pydantic docs.

This doesn't work with flask-pydantic. Is there any way to achieve similar behaviour?

@bauerji bauerji mentioned this issue Sep 10, 2020
@bauerji
Copy link
Owner

bauerji commented Sep 10, 2020

Hi,

please refer to #15 where I implemented the solution.

Jirka

@bauerji
Copy link
Owner

bauerji commented Sep 10, 2020

Model aliases for response models are added in newest version 0.4.0.

If you are not satisfied with solution or have another suggestion, please reopen this or create a new issue.

Jirka

@bauerji bauerji closed this as completed Sep 10, 2020
@eboddington
Copy link
Author

Thanks for the super quick fix, it's working well!

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

2 participants