Change how validate_request and validate_response validate if the provided model is the same as the model provided in the decorator. For BaseModel and RootModel instances, we can use the validate_python method to do the validation. In all other cases, we'll instead use a pydantic TypeAdapter which will attempt to build a validator for the requested model.
These changes allow us to use the following methods for declaring a method that expects a list of items:
Additional tests have been added to validate cases where lists or RootModels are passed to validate_request and validate_response.
Note that this PR doesn't make any changes to the header validation or query string validation. I wanted to get an idea if this altered way of validating makes sense before making too many changes.
Thanks, I've gone for a very similar approach. I've not documented this yet, as it requires further testing, but please give it a go and let me know your thoughts.
Addresses Issue #16.
Change how
validate_request
andvalidate_response
validate if the provided model is the same as the model provided in the decorator. ForBaseModel
andRootModel
instances, we can use thevalidate_python
method to do the validation. In all other cases, we'll instead use a pydanticTypeAdapter
which will attempt to build a validator for the requested model.These changes allow us to use the following methods for declaring a method that expects a list of items:
Additional tests have been added to validate cases where lists or RootModels are passed to validate_request and validate_response.
Note that this PR doesn't make any changes to the header validation or query string validation. I wanted to get an idea if this altered way of validating makes sense before making too many changes.