Giter Club home page Giter Club logo

flask-oasschema's Introduction

Flask-OASSchema

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

flask-oasschema's People

Contributors

ilyasukhanov avatar jahangir-sh avatar thanavath avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.