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

Enhancement(DTO): support setting the serialization name via DTOField #2817

Open
peterschutt opened this issue Dec 2, 2023 · 0 comments
Open
Labels
DTOs This is related to our DTO feature Enhancement This is a new feature or request

Comments

@peterschutt
Copy link
Contributor

peterschutt commented Dec 2, 2023

Summary

Support defining a serialization name on the model type that is applied any time that type is parsed by a DTO factory

Basic Example

from dataclasses import dataclass, field
from typing import Annotated, Any, TypeAlias

from litestar.dto.field import DTOField

AliasedStr: TypeAlias = Annotated[str, DTOField(serialization_name="bar")]

@dataclass
class Message:
    id: str
    foo: AliasedStr

Drawbacks and Impact

Impact should be relatively minor, adds yet another way to rename fields, however the pattern is already established for marking fields private.

Unresolved questions

Should we just bite the bullet and embellish DTOField with every parameter on DTOConfig that makes sense?


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh Litestar dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@peterschutt peterschutt added the Enhancement This is a new feature or request label Dec 2, 2023
@JacobCoffee JacobCoffee added the DTOs This is related to our DTO feature label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DTOs This is related to our DTO feature Enhancement This is a new feature or request
Projects
Status: Ideas
Development

No branches or pull requests

2 participants