Skip to main content

Build routes using swagger specification

Project description

https://github.com/aamalev/aiohttp_apiset/workflows/Tests/badge.svg Coverage Code style: ruff https://img.shields.io/pypi/v/aiohttp_apiset.svg Documentation Status https://img.shields.io/pypi/dm/aiohttp-apiset.svg Hatch project

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

Development

Check code:

hatch run lint:all

Format code:

hatch run lint:fmt

Run tests:

hatch run pytest

Run tests with coverage:

hatch run cov

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

aiohttp_apiset-0.9.16b1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

aiohttp_apiset-0.9.16b1-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_apiset-0.9.16b1.tar.gz.

File metadata

  • Download URL: aiohttp_apiset-0.9.16b1.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for aiohttp_apiset-0.9.16b1.tar.gz
Algorithm Hash digest
SHA256 213f811c599e55930bb0daea69d277dc81d4bd211d72d57b79c8c514743fd133
MD5 bae93902dc394d7d50e298ccccb53a30
BLAKE2b-256 7914f8853fdc43d89451882b4a85bfe7db77c725195096f3db6cf1f06f38cc8f

See more details on using hashes here.

File details

Details for the file aiohttp_apiset-0.9.16b1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_apiset-0.9.16b1-py3-none-any.whl
Algorithm Hash digest
SHA256 bd3b64febc5e6c2e7a58b7a293b67a70f1f15c7a613cf1e12c16fa13b94b2786
MD5 0814aac76fb0434b3dc46f74b624bc70
BLAKE2b-256 81d643c8ea67b014191a311a9517df63d1052165d239ee922ff428811aeffd54

See more details on using hashes here.

Supported by

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