Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate an HTTP requests against an OpenAPI3 specification in Python? [closed]

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)?

like image 690
pistacchio Avatar asked Feb 18 '19 13:02

pistacchio


People also ask

Does OpenAPI rest?

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.

What is OpenAPI validator?

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.

Is Swagger and OpenAPI the same?

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.

Which of the following is a mandatory section of an OpenAPI Specification?

The minimum required fields in OpenAPI definitions are: OAS version identifier, such as openapi: 3.0. 2 or swagger: 2.0. info.


1 Answers

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.

like image 160
arturkuchynski Avatar answered Sep 21 '22 10:09

arturkuchynski