Flask extension for validating JSON requests
Project description
JSON request validation for Flask applications using a JSON Schema specified in a OpenAPI Specification (also know as OAS and Swagger).
Validating schema of passed object provides a level of confidence of correctness of data directly proportional to schema strictness. With a good schema, it maybe be possible to use JSON-dict like object as first order models without having to convert them into trusted python objects. Reducing amount of code that needs to be maintained.
The tests provide a succinct example of usage as well as an example OAS schema file. But at high level usage looks as follows:
from flask import Flask from flask_oasschema import OASSchema, validate_request # Configure application app = Flask(__name__) # Specify path to the OAS schema file, in this case schemas/oas.json of # project firectory app.config['OAS_FILE'] = os.path.join( app.root_path, 'schemas', 'oas.json' ) # Initialize validator jsonschema = OASSchema(app) # Decorate endpoint with @validate_request() @app.route('/books/<isbn>', methods=['POST']) @validate_request() def books(isbn): return 'success'
Installation
This library is available through PyPI as Flask-OASSchema and as such can be installed with:
pip install Flask-OASSchema
Credit
This project is a fork of Matt Wright’s project Flask-JsonSchema and thus borrows ideas and code. Difference being that Flask-OASSchema works only with OAS (Swagger) style schema spec as opposed to raw json-schema. This allows Flask-OASSchema to locate schema corresponding to endpoint and method without explicit per endpoint configuration.
Authors: Dan Baumann Thanavath Jaroenvanit
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Flask_OASSchema-0.9.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f0e0a2c3977dd87a5a1372a87f6a4eb3fe75e5a4e3abc6fa1383515d6268997 |
|
MD5 | 3e8f1966e74687cff2b422aa8ec1c44a |
|
BLAKE2b-256 | fe39116369377fcadb3fd040eb55fab4c8631b275d826a63208eb53a36be9f96 |