Skip to content

Falcon requests validation against OpenAPI (Swagger) schema

License

Notifications You must be signed in to change notification settings

gwaramadze/falguard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Falguard travis codecov python-versions

Falguard is a Python library that provides request validation helpers for Falcon web framework. Falguard relies on Yelp's bravado-core library.

Features

  • Validation of OpenAPI (Swagger) schema
  • Error serialization compliant with JSON:API specification
  • Validator may be used either as a hook or a middleware component

Installation

$ pip install falguard

Usage

Instantiate Validator with the path to OpenAPI specification (both json and yaml are supported)...

import falguard

validator = falguard.Validator('spec.json')

...and use it as the hook on the responder...

class Resource:

    @falcon.before(validator)
    def on_get(self, request, response, **validated):
        pass

...or the hook on the whole resource...

@falcon.before(validator)
class Resource:
    pass

...or globally, as the middleware component.

import falcon

api = falcon.API(middleware=validator)

All validated parameters (path, query, body) are injected back to the responder so it MUST accept relevant number of arguments, eg.

class Resource:

    def on_put(self, request, response, resource_id, data):
        pass

    def on_post(self, request, response, **validated):
        pass

About

Falcon requests validation against OpenAPI (Swagger) schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages