Skip to main content

validation for aiohttp swagger openAPI 3

Project description

aiohttp-swagger3

https://github.com/hh-h/aiohttp-swagger3/actions/workflows/ci.yaml/badge.svg?branch=master https://img.shields.io/codecov/c/github/hh-h/aiohttp-swagger3/master.svg?style=flat https://badge.fury.io/py/aiohttp-swagger3.svg https://img.shields.io/badge/python-3.7%2B-brightgreen.svg https://img.shields.io/badge/code%20style-black-black.svg https://img.shields.io/pypi/l/aiohttp-swagger3.svg

About

Package for displaying swagger docs via different UI backends and optionally validating/parsing aiohttp requests using swagger specification 3.0, known as OpenAPI3.

Supported UI backends

Multiple UI backends can be used or UI backend can be disabled at all if only needed validation without being able to view documentation.

Documentation

https://aiohttp-swagger3.readthedocs.io/en/latest/

Disable validation

Pass validate=False to SwaggerDocs/SwaggerFile class, the default is True
Also, sometimes validation has to be disabled for a route, to do this you have to pass validate=False during the initialization of the route.
ex. web.post("/route", handler, validate=False), the default is True

Requirements

  • python >= 3.8

  • aiohttp >= 3.8.0

  • pyyaml >= 5.4

  • attrs >= 19.3.0

  • python-fastjsonschema >= 2.15.0

  • rfc3339-validator >= 0.1.4

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, SwaggerInfo, SwaggerUiSettings

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()
    swagger = SwaggerDocs(
        app,
        swagger_ui_settings=SwaggerUiSettings(path="/docs/"),
        info=SwaggerInfo(
            title="Swagger Petstore",
            version="1.0.0",
        ),
        components="components.yaml"
    )
    swagger.add_routes([
        web.get("/pets/{pet_id}", get_one_pet),
    ])
    app['storage'] = {}
    web.run_app(app)

More examples

How it helps

https://raw.githubusercontent.com/hh-h/aiohttp-swagger3/master/docs/_static/comparison.png

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

  • readOnly

  • allOf, oneOf, anyOf

  • string formats: date, date-time, byte, email, uuid, hostname, ipv4, ipv6

  • custom string format validators

TODO (raise an issue if needed)

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.8.0.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

aiohttp_swagger3-0.8.0-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiohttp-swagger3-0.8.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.6

File hashes

Hashes for aiohttp-swagger3-0.8.0.tar.gz
Algorithm Hash digest
SHA256 79009572d4b2fb5ae6252bf68b1909c9523f22cfd5fa2f46add2d5c050cf520c
MD5 6022eb31c682b3e9185794852acf7b54
BLAKE2b-256 9ab073d590d064074026811cbbe1dfc57d4c269049c96f1fd738053b3019496e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp_swagger3-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c487de95111fc03f735355db084a90d51eb83334b3d3c47f9beb72d1df29ec24
MD5 56f28f6fff2631663abb6a23882cee9e
BLAKE2b-256 9f1f292b767b5b4f6ca68980fe84df04e9b0a05703751f7ef4f5e90c26facfc0

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