Package to build routes using swagger specification
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
aiohttp_apiset Merge branch '0.9.X' Dec 12, 2018
docs
examples Update aiohttp from 3.3.2 to 3.4.4 Nov 5, 2018
tests
.gitignore Initial commit Oct 5, 2015
.pyup.yml pyup with Pipfile Aug 9, 2018
.readthedocs.yml
.travis.yml 3.7-dev on ci Nov 2, 2018
CONTRIBUTORS.txt
HISTORY.rst Update HISTORY.rst Dec 12, 2018
LICENSE
MANIFEST.in fix pip install Oct 28, 2016
Makefile
Pipfile Update pytest from 4.0.0 to 4.0.1 Nov 26, 2018
README.rst
setup.cfg fix mypy Dec 9, 2018
setup.py Programming Language :: Python :: 3.7 Nov 3, 2018
swagger_ui.py Revert "os.makedirs(static_dir) in swagger-ui builder" Aug 2, 2018

README.rst

aiohttp-apiset

https://travis-ci.org/aamalev/aiohttp_apiset.svg?branch=master Updates Documentation Status

Package to build routes and validate request using swagger specification 2.0.

Features

  • Building of the routing from specification swagger
  • Using inclusions other specifications with concatenate url
  • Optional output of the resulting specification and view embed swagger-ui
  • Advanced router with TreeResource
  • Extract specify parameters from request and validate with jsonschema
  • Serialize data as response with middleware

Usecase

Package aiohttp_apiset allows supports several strategies:

  • The foreign specification. When the specification is made and maintained by another team.
  • The specification in the code. When the fragments of specification are placed in the docstrings.
  • Mixed strategy. When routing are located in the specification files and operations are described in the docstrings.

Example

async def handler(request, pet_id):
    """
    ---
    tags: [Pet]
    description: Info about pet
    parameters:
      - name: pet_id
        in: path
        type: integer
        minimum: 0
    responses:
      200:
        description: OK
      400:
        description: Validation error
      404:
        description: Not found
    """
    pet = await db.pets.find(pet_id)

    if not pet:
        return {'status': 404, 'msg': 'Not Found'}

    return {
        'pet': pet,  # dict serialized inside jsonify
    }


def main():
    router = SwaggerRouter(
        swagger_ui='/swagger/',
        version_ui=2,
    )
    router.add_get('/pets/{pet_id}', handler=handler)

    app = web.Application(
        router=router,
        middlewares=[jsonify],
    )

    web.run_app(app)

Is now available in the swagger-ui to the address http://localhost:8080/swagger/. Available both branch swagger-ui. For use branch 3.x visit http://localhost:8080/swagger/?version=3

Examples: examples