aiohttp-swagger3¶
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.
Swagger UI - https://github.com/swagger-api/swagger-ui
ReDoc - https://github.com/Redocly/redoc
RapiDoc - https://github.com/mrin9/RapiDoc
Documentation¶
Disable validation¶
validate=False
to SwaggerDocs
/SwaggerFile
class, the default is True
validate=False
during the initialization of the route.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¶

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)¶
multipleOf
not
allowEmptyValue
Common Parameters for All Methods of a Path (spec file only)
more serialization methods, see: https://swagger.io/docs/specification/serialization/
encoding
form data serialization (array, object)
default (array, object)
Documentation contents¶
- API Reference
- Changelog
- 0.8.0 (04-02-2023)
- 0.7.4 (04-02-2023)
- 0.7.2 (06-04-2022)
- 0.7.1 (30-01-2021)
- 0.7.0 (04-11-2021)
- 0.6.0 (19-06-2021)
- 0.5.6 (11-05-2021)
- 0.5.4 (28-03-2021)
- 0.5.3 (14-01-2021)
- 0.5.2 (31-12-2020)
- 0.5.1 (28-11-2020)
- 0.5.0 (31-10-2020)
- 0.4.4 (30-06-2020)
- 0.4.3 (13-03-2020)
- 0.4.2 (11-03-2020)
- 0.4.1 (09-03-2020)
- 0.4.0 (07-03-2020)
- 0.3.6 (21-01-2020)
- 0.3.5 (18-12-2019)
- 0.3.4 (18-12-2019)
- 0.3.3 (18-12-2019)
- 0.3.2 (18-12-2019)
- 0.3.1 (17-12-2019)
- 0.3.0 (10-12-2019)
- 0.2.5 (27-11-2019)
- 0.2.4 (16-11-2019)
- 0.2.3 (16-09-2019)
- 0.2.2 (30-08-2019)
- 0.2.1 (29-06-2019)
- 0.2.0 (27-06-2019)
- 0.1.8 (27-06-2019)
- 0.1.7 (11-04-2019)
- 0.1.6 (30-03-2019)
- 0.1.5 (15-03-2019)
- 0.1.4 (31-01-2019)
- 0.1.3 (14-01-2019)
- 0.1.2 (27-12-2018)
- 0.1.1 (25-12-2018)
- 0.1 (22-12-2018)