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

[BUG] Django Ninja doesn't use alias_generator for response body #811

Closed
avin-kavish opened this issue Aug 3, 2023 · 2 comments
Closed

Comments

@avin-kavish
Copy link

Describe the bug
I have a class like this,

from humps import camelize

class Dashboard(Schema):
    dataset_id: str

    class Config(Schema.Config):
        alias_generator = camelize

When I use this as the body type in a POST request. it correctly camelizes the field to datasetId. But when I use it as the response type, the field comes out dataset_id

Versions

  • Python version: 3.11
  • Django version: 4.1.9
  • Django-Ninja version: 0.22.2
  • Pydantic version: 1.10.9
@vitalik
Copy link
Owner

vitalik commented Aug 3, 2023

@avin-kavish

you need to use by_alias=True in your view to kick in alias_generators

@router.get("/some", response=Dashboard, by_alias=True)
def some(request):
    return Dashboard(...)

@avin-kavish
Copy link
Author

avin-kavish commented Aug 3, 2023

Should it work for the body type without by_alias though?

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