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
"""
...
Metadata
Release files for aiohttp-openapi-ermelo 2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiohttp_openapi_ermelo-2.1.tar.gz | 648.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiohttp_openapi_ermelo-2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.2 MB
Release files / aiohttp_openapi_ermelo-2.1.tar.gz
| Download URL | aiohttp_openapi_ermelo-2.1.tar.gz |
|---|---|
| Size | 648.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
393b77fc1fe9bd148ef3de595991949d5356a3bbdae5b1dc2055d4cde2086717
|
|
BLAKE2b-256 checksum How to use checksums |
99bbc99c413a52870979956d9d9f4652841e78f4cfc24939d0fede03ab6a4a64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / aiohttp_openapi_ermelo-2.1-py3-none-any.whl
| Download URL | aiohttp_openapi_ermelo-2.1-py3-none-any.whl |
|---|---|
| Size | 544.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e637296afd2a809e98d65f218aecebe4417d075a2a6d4126c9c4d9dda195e210
|
|
BLAKE2b-256 checksum How to use checksums |
f028144ea8f150933394bd466f050af7fcc0c9ee8c613a255ea58d9e2112e6f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|