Skip to main content

Builds openapi schemas for aiohttp apps.

Project description

aiohttp-openapi-ermelo

This library helps you to build openapi schemas for your aiohttp app, and serve documentation uis (Swagger) for the schema.

Installation

Add "aiohttp-openapi-ermelo" to your project dependencies. If you wish to use yaml functionality, then please add "aiohttp-openapi-ermelo[yaml]".

How to use

Once you have created an aiohttp Application, create an OpenAPIApp, and specify the global parameters for your schema using classes from openapi-pydantic:

from aiohttp.web import Application, Request, Response
from aiohttp_openapi import OpenAPIApp, SwaggerUI, operation
from openapi_pydantic import Info, OpenAPI, Operation

app = Application()
api = OpenAPIApp(
    app,
    OpenAPI(info=Info(version="1.0.0", title="Petstore")),
    url_base="/api/",
    doc_uis=(SwaggerUI(),),
)

Then routes to handlers can be added while specifying the parameters for the operation.

async def get_pets(request: Request):
    return json_response([{"id": 10, "name": "doggie"}])

api.add_route("GET", "pets", get_pets, summary="List all pets", operationId="listPets", tags=["pets"])

api.add_route, and it's related helper functions works much like app.router.add_route. It also allows you to specify parameters for the operation. This operation gets set for the relevant path on the schema.

Note that the path is relative the the url_base, so for the example above, the path for this example will be "/api/pets". If you want to specify an absolute path, start the path with a /.

One can specify the operation parameters using the @operation decorator:

@operation(summary="List all pets", operationId="listPets", tags=["pets"])
async def get_pets(request: Request):
    return json_response([{"id": 10, "name": "doggie"}])

api.add_route("GET", "pets", get_pets)

Specifying operation parameters

When specifying operation parameters on either add_route or @operation, there are a few options on how to provide parameters:

  • Specify an Operation object:
@operation(operation=Operation(summary="List all pets", operationId="listPets", tags=["pets"]))
async def get_pets(request: Request): ...
  • Specify Operation arguments directly:
@operation(summary="List all pets", operationId="listPets", tags=["pets"])
async def get_pets(request: Request): ...
  • If no summary is provided, and the handler has a doc string, then the doc string is used as the summary. Hence the bellow example is the same as above:
@operation(operationId="listPets", tags=["pets"])
async def get_pets(request: Request):
    "List all pets"
    ...
  • Specify json text:
@operation(json='{"summary":"List all pets","operationId":"listPets","tags":["pets"]}')
async def get_pets(request: Request): ...
  • Specify yaml text:
@operation(yaml="""
    summary: List all pets
    operationId: listPets
    tags:
    - pets
""")
async def get_pets(request: Request): ...
  • Specify yaml text as a docstring:
@operation(yaml_docstring=True)
async def get_pets(request: Request):
    """
    summary: List all pets
    operationId: listPets
    tags:
    - pets
    """
    ...

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_openapi_ermelo-2.1.tar.gz (648.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_openapi_ermelo-2.1-py3-none-any.whl (544.7 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_openapi_ermelo-2.1.tar.gz.

File metadata

  • Download URL: aiohttp_openapi_ermelo-2.1.tar.gz
  • Upload date:
  • Size: 648.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for aiohttp_openapi_ermelo-2.1.tar.gz
Algorithm Hash digest
SHA256 393b77fc1fe9bd148ef3de595991949d5356a3bbdae5b1dc2055d4cde2086717
MD5 01aea6e87724c3af9a0cc1b2a30f1c7b
BLAKE2b-256 99bbc99c413a52870979956d9d9f4652841e78f4cfc24939d0fede03ab6a4a64

See more details on using hashes here.

File details

Details for the file aiohttp_openapi_ermelo-2.1-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_openapi_ermelo-2.1-py3-none-any.whl
  • Upload date:
  • Size: 544.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for aiohttp_openapi_ermelo-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e637296afd2a809e98d65f218aecebe4417d075a2a6d4126c9c4d9dda195e210
MD5 b6a67a511d57fe1de7c66da53739dc89
BLAKE2b-256 f028144ea8f150933394bd466f050af7fcc0c9ee8c613a255ea58d9e2112e6f3

See more details on using hashes here.

Supported by

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