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
Requirements
python >= 3.9
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)
Metadata
Release files for aiohttp-swagger3 0.10.0
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_swagger3-0.10.0.tar.gz | 1.8 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiohttp_swagger3-0.10.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 3.7 MB
Release files / aiohttp_swagger3-0.10.0.tar.gz
| Download URL | aiohttp_swagger3-0.10.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a333c59328f64dd64587e5f276ee84dc256f587d09f2da6ddaae3812fa4d4f33
|
|
BLAKE2b-256 checksum How to use checksums |
a10600ccb2c8afdde4ca7c3cac424d54715c7d90cdd4e13e1ca71d68f5b2e665
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.11
|
Release files / aiohttp_swagger3-0.10.0-py3-none-any.whl
| Download URL | aiohttp_swagger3-0.10.0-py3-none-any.whl |
|---|---|
| Size | 1.8 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ae2d2ba7dbd8ea8fe1cffe8f0197db5d0aa979eb9679bd699ecd87923912509
|
|
BLAKE2b-256 checksum How to use checksums |
0a8fdb4cb843999a3088846d170f38eda2182b50b5733387be8102fed171c53f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.11
|