Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Provides a wrapper which provides valid json to Resource methods.

Project Description

Add the @validate_json decorator and schema class constant to flask_restful.Resource methods (post, get, etc.) in order to validate requests meet the jsonschema.

Ensure JSON request matches schema specified in the class the wrapped method belongs to, provide that valid JSON to the method, or abort 400 with the validation error message.

from flask_restful_jsonschema import validate_json


class Users(flask_restful.Resource):
    SCHEMA_POST = {
        "type": "object",
        "properties": {
            "email": {"type": "string"},
            "password": {"type": "string"},
        },
        "required": ["email", "password"],
    }
    SCHEMA_PUT = {
        "type": "object",
        "properties": {
            "email": {"type": "string"},
            "password": {"type": "string"},
        },
    }
    SCHEMA_GET = {
        "type": "object",
        "properties": {
            "email": {"type": "string"},
        },
        "required": ["email"],
    }

    @validate_json
    def post(self, json_request):
        json_request["email"]
        json_request["password"]

    @validate_json
    def put(self, json_request):
        json_request.get("email")
        json_request.get("password")

    @validate_json
    def get(self, json_request):
        json_request["email"]
Release History

Release History

This version
History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
flask_restful_jsonschema-0.1.1.tar.gz (1.9 kB) Copy SHA256 Checksum SHA256 Source Sep 29, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting