Skip to main content

validation for aiohttp swagger openAPI 3

Project description

aiohttp-swagger3

Build Status Code Coverage PyPI version Python version Code Style License

!!! Testers are needed !!!

Feel free to try this library and raise an issue if it does not work as expected, thanks!

About

Package to validating requests using swagger specification 3.0.
It's marked as pre-alpha on pypi.org, but that's because I haven't decided architecture yet. However, we use it in production :)

Limitations

  • only application/json supported for now, but you can create own handler
  • header/query parameters only supported simple/form array serialization, e.g. 1,2,3,4
  • see TODO below

Installation

pip install aiohttp-swagger3

Example

from aiohttp import web
from aiohttp_swagger3 import SwaggerDocs

async def get_one_pet(request: web.Request, pet_id: int) -> web.Response:
    """
    Optional route description
    ---
    summary: Info for a specific pet
    tags:
      - pets
    parameters:
      - name: pet_id
        in: path
        required: true
        description: The id of the pet to retrieve
        schema:
          type: integer
          format: int32
    responses:
      '200':
        description: Expected response to a valid request
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Pet"
    """
    if pet_id not in request.app['storage']:
        raise web.HTTPNotFound()
    return web.json_response(request.app['storage'][pet_id])

def main():
    app = web.Application()
    s = SwaggerDocs(app, '/docs', title="Swagger Petstore", version="1.0.0", components="components.yaml")
    s.add_routes([
        web.get("/pets/{pet_id}", get_one_pet),
    ])
    app['storage'] = {}
    web.run_app(app)

More examples

Features

  • items
  • properties
  • pattern
  • required
  • enum
  • minimum
  • maximum
  • exclusiveMinimum
  • exclusiveMaximum
  • minLength
  • maxLength
  • minItems
  • maxItems
  • uniqueItems
  • minProperties
  • maxProperties
  • default (only primitives)
  • additionalProperties
  • nullable
  • allOf
  • oneOf
  • anyOf

TODO (raise an issue if needed)

  • cookies
  • multipleOf
  • not
  • allowEmptyValue
  • Common Parameters for All Methods of a Path (spec file only)
  • readOnly, writeOnly
  • more serialization methods, see: https://swagger.io/docs/specification/serialization/
  • encoding
  • form data serialization out of the box
  • default (array, object)

Project details


Download files

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

Source Distribution

aiohttp-swagger3-0.1.tar.gz (411.5 kB view details)

Uploaded Source

Built Distribution

aiohttp_swagger3-0.1-py3-none-any.whl (420.0 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-swagger3-0.1.tar.gz.

File metadata

  • Download URL: aiohttp-swagger3-0.1.tar.gz
  • Upload date:
  • Size: 411.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for aiohttp-swagger3-0.1.tar.gz
Algorithm Hash digest
SHA256 4cf182e539c88fb199b1860ac94b3a3bfb25c7a28650bc25a1233e1241dfae62
MD5 0e9b27b60b13941fe3f27dcbe1766924
BLAKE2b-256 ba58269ee5ab5b601a9d386f43575a3be0bc4cf1cc16381da863ee8cd6fdceaf

See more details on using hashes here.

File details

Details for the file aiohttp_swagger3-0.1-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_swagger3-0.1-py3-none-any.whl
  • Upload date:
  • Size: 420.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for aiohttp_swagger3-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68bb51026abffcdfbfdf81ee916af88116e379f3cb12c0fcc3f824994fa3392f
MD5 f428de79291782176d85b047dc291fe6
BLAKE2b-256 1eef1bd2aa2488c7a7508fb1cb3f09b04c3c5ba180271e16369a9ed81695ccb4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page