dchaplinsky / aiohttp_validate

Simple library that helps you validate your API endpoints requests/responses with json schema
MIT License
48 stars 10 forks source link

=============================== aiohttp_validate

.. image:: https://img.shields.io/pypi/v/aiohttp_validate.svg :target: https://pypi.python.org/pypi/aiohttp_validate

.. image:: https://img.shields.io/travis/dchaplinsky/aiohttp_validate.svg :target: https://travis-ci.org/dchaplinsky/aiohttp_validate

.. image:: https://readthedocs.org/projects/aiohttp-validate/badge/?version=latest :target: https://aiohttp-validate.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status

.. image:: https://pyup.io/repos/github/dchaplinsky/aiohttp_validate/shield.svg :target: https://pyup.io/repos/github/dchaplinsky/aiohttp_validate/ :alt: Updates

Simple library that helps you validate your API endpoints requests/responses with jsonschema_. Documentation is also available here at https://aiohttp-validate.readthedocs.io.

Installation

Install from PyPI::

pip install aiohttp_validate

Usage

Complete example of validation for text tokenization microservice_::

from aiohttp_validate import validate

@validate(
    request_schema={
        "type": "object",
        "properties": {
            "text": {"type": "string"},
        },
        "required": ["text"],
        "additionalProperties": False
    },
    response_schema={
        "type": "array",
        "items": {
            "type": "array",
            "items": {
                "type": "array",
                "items": {"type": "string"}
            }
        }
    }
)
async def tokenize_text_handler(request, *args):
    return tokenize_text(request["text"])

Features

Developing

Install requirement and launch tests::

pip install -r requirements-dev.txt
py.test

Credits

That package is influenced by Tornado-JSON written by Hamza Faran Code to parse errors is written by Ruslan Karalkin

Versioning

This software follows Semantic Versioning_

.. _Semantic Versioning: http://semver.org/

License

.. _jsonschema: http://json-schema.org/ .. _aiohttp_swaggerify: https://github.com/dchaplinsky/aiohttp_swaggerify .. Tornado-JSON: https://github.com/hfaran/Tornado-JSON/ .. Ruslan Karalkin: https://github.com/rkaralkin .. _text tokenization microservice: https://github.com/lang-uk/tokenize-ms