💻 Programming: recipe: response validation against OpenAPI schema in Python
Summary: code snippets and explanation of how to validate HTTP-response using openapi-core package If you deal with some service based on OpenAPI Specification you might want to perform validation of HTTP responses returned by it. One of the ways to do this an internet search provides for Python is to use openapi-core package. If you look at their documentation ( here or here ) you will find it very stingy: couple of short code snippets and couple of sentences just stating what is done. In particular for response validation we have exactly the following: You can also validate against responses from openapi_core . validation . response . validators import ResponseValidator validator = ResponseValidator (spec) result = validator . validate (request, response) # raise errors if response invalid result .raise_for_errors() # get list of errors errors = result .errors ... Here we see some confusing things: why do we need a request objec...