litestar
litestar copied to clipboard
Docs: example in "DTO: Excluding fields" is not clear
Summary
Example:
- Docs: https://docs.litestar.dev/latest/usage/dto/1-abstract-dto.html#excluding-fields
- Code:
config = DTOConfig(
exclude={
"id",
"address.id",
"address.street",
"pets.0.id",
"pets.0.user_id",
}
)
Later is specifies:
and "pets.0.id" and "pets.0.user_id" represent fields of the Pets objects nested within the list of User.pets.
and
Given a generic type, with an arbitrary number of type parameters (e.g.,
GenericType[Type0, Type1, ..., TypeN])
, we use the index of the type parameter to indicate which type the exclusion should refer to. For example, a.0.b, excludes the b field from the first type parameter of a, a.1.b excludes the b field from the second type parameter of a, and so on.
But I still don't understand what pets.0.id
means :)
Here are my questions:
- Is
pets.0
an index of an object? For example in[Pet(id=1, name="Dog"), Pet(id=2, name="Cat")]
will both of them not have anid
? Or onlyDog
? - This sentence confuses me even more:
Given a generic type, with an arbitrary number of type parameters (e.g.,
GenericType[Type0, Type1, ..., TypeN])
, we use the index of the type parameter to indicate which type the exclusion should refer to
Because neither User
or Pet
is generic. They don't have any type params.
I don't have any proposals on how to fix this, because I don't understand how it works :)