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 for displaying swagger docs and optionally validating/parsing aiohttp requests using swagger specification 3.0 only.
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 :)

Disable validation

Okay, just pass validate=False to SwaggerDocs/SwaggerFile class, default is True

Requirements

  • python3.6+
  • aiohttp>=3
  • pyyaml
  • attrs
  • openapi-spec-validator
  • strict_rfc3339

Limitations

  • only application/json and application/x-www-form-urlencoded 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

  • application/json
  • application/x-www-form-urlencoded (except array and object)
  • items
  • properties
  • pattern
  • required
  • enum
  • minimum
  • maximum
  • exclusiveMinimum
  • exclusiveMaximum
  • minLength
  • maxLength
  • minItems
  • maxItems
  • uniqueItems
  • minProperties
  • maxProperties
  • default (only primitives)
  • additionalProperties
  • nullable
  • allOf
  • oneOf
  • anyOf
  • string formats: date, date-time, password, byte, binary, email, uuid, hostname, ipv4, ipv6

TODO (raise an issue if needed)

  • aiohttp specific

  • class based view

  • METH_ANY (*) routes

  • swagger specific

  • 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 (array, object)

  • 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.7.tar.gz (411.9 kB view details)

Uploaded Source

Built Distribution

aiohttp_swagger3-0.1.7-py3-none-any.whl (421.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiohttp-swagger3-0.1.7.tar.gz
  • Upload date:
  • Size: 411.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for aiohttp-swagger3-0.1.7.tar.gz
Algorithm Hash digest
SHA256 984650c266d7b2b615a5ff806d25231a7d85742b4bc3564dbbb086625531cd80
MD5 74efcc46c3b55274d2385fb715527820
BLAKE2b-256 09c20ec2fab9e1e6e03769e413d6048cdc6dcf18df76cb543e705774fc342c76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiohttp_swagger3-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 421.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for aiohttp_swagger3-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 625bd7c372a69d7316fb4a73ec02e0f5e1f528d59c1c573effed387b0df9ea0a
MD5 06e08566d6d548be26881354769a5f1d
BLAKE2b-256 cb1067eac05da28f9c73da920fc3871e2553330a3f289e9822635cd3c9b97b12

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