Skip to content

[BUG] Failing to override Pydantic alias_gnerator config, to convert fields to camelCase in response body #469

@eldardamari

Description

@eldardamari

Describe the bug
Failing to apply Pydantic alias_gnerator config, to convert fields to camelCase in response body.

api = NinjaAPI()


def to_camel(string: str) -> str:
    return ''.join(word.capitalize() for word in string.split('_'))


class AddResult(Schema):
    total_sum: int

    class Config(Schema.Config):
        alias_generator = to_camel
        allow_population_by_field_name = True


@api.get("/add", response=AddResult)
def add(request, a: int, b: int):
    return AddResult(total_sum=a + b)

Expected response:

{
  "totalSum": 3
}

Docs

image

Versions (please complete the following information):

  • Python version: [3.9]
  • Django version: [4.0.4]
  • Django-Ninja version: [0.18.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions