There seems to be number of python libraries dedicated to validate the correctness of an OpenApi schema. While this might be useful, I can frankly just write my OpenApi schema here it in https://editor.swagger.io and have it validated / converted / pretty formatted.
I'm then left with clients potentially sending any kind of dirty data to my OpenApi documented endpoint.
Currently the problem of validating data against the OpenAPI schema is commonly addressed by extending data validation tools with plugins that can infer the OpenAPI spec from their data validation declaration. However, the reverse is not typically possible, that is to start from the OpenAPI schema and instantiate data validators. Also, the OpenAPI generated from validation declarations tends to be incomplete.
How can I validate HTTP request data against an OpenAPI3 spec in Python (preferably in a generic and framework-agnostic way)?
Originally known as the Swagger Specification, the OpenAPI Specification (OAS) is a format that can be used to describe, produce, consume, and visualize RESTful web services. It is a specification standard for REST APIs that defines the structure and syntax. Most notably, it is programming language agnostic.
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to HTTP APIs. This allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection.
Although the terms once referred to the same thing, they can no longer be used interchangeably…even though some people still do. In 2021, OpenAPI refers to the industry-standard specification for RESTful API design. Swagger refers to a set of SmartBear tools.
The minimum required fields in OpenAPI definitions are: OAS version identifier, such as openapi: 3.0. 2 or swagger: 2.0. info.
OpenAPI 3 is compatible with the most part of JSON Schema - read The Docs
You can install json schema wrapper for Python and validate your JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With