Skip to content

Multiple Aliases for Pydantic v2 #2474

@ubaumann

Description

@ubaumann

Is your feature request related to a problem? Please describe.
I deal with long aliases (including Namespace information), and I have many values with a dash in the name. I would like to have two aliases: one with the long name and one with the dash.

Describe the solution you'd like
Pydantic v2 supports multiple Aliases using AliasChoices https://docs.pydantic.dev/latest/api/aliases/#pydantic.aliases.AliasChoices. For now, the --aliases only supports one alias, and I would like to support str or a list. With the string, the behaviour stays the same and alias="my_alias" is used, and when it is a list, validation_alias=AliasChoices(*["my_alias", "my-alias"]) should be used.

Describe alternatives you've considered
For now, I am always using the long alias name only.

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