Open ruscoder opened 1 week ago
There's a dirty hack with primitive types - I add Type and then remove Type for unions - it needs to be re-written in a better way. But I'm afraid it will require to change our meta models to add real type and aliased type
I had to add a custom serializer and validator for BaseModel that we use for all resources to handle AnyResource validation/serialization.
Functions _validate/_serialize run for each field, it's definitely not optimized way, however, it skips to default for non AnyResource
values.
I assume it might be refactored using __get_pydantic_core_schema__
with a custom schema for AnyResource/list[AnyResource]
fields.
Also, there's a bit tight connection to the pydantic internals due to enumerating all fields for model_dump
- but otherwise it's impossible to do it with typed kwargs.