wyfo / apischema

JSON (de)serialization, GraphQL and JSON schema generation using Python typing.

Home Page:https://wyfo.github.io/apischema/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow alias where object field is expected

wyfo opened this issue · comments

Several features of apischema requires an object field to be passed, e.g. field ordering, field validator, or object serialization.

Fields can be either:

  • an apischema ObjectField
  • a dataclass Field
  • the field name as string

But it could be convenient to also use the field alias instead. For example, if object serialization is built dynamically from aliases passed in request parameters, it would avoid having to do the reverse mapping.

On the other hand, reverse mapping would be quite easy, so it's not really an issue (things gets more complicated when it comes to serialized methods). Also, allowing field names and aliases at the same could bring some edge cases with both overlapping, but IMO this kind of thing should not happen in real life.