validation for aiohttp swagger openAPI 3
Project description
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.7
aiohttp >= 3.5.4
pyyaml >= 5.3
attrs >= 19.3.0
python-fastjsonschema >= 2.14.3
strict_rfc3339 == 0.7
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, 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/"),
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)
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
Built Distribution
File details
Details for the file aiohttp-swagger3-0.7.2.tar.gz
.
File metadata
- Download URL: aiohttp-swagger3-0.7.2.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0746bfcc4c5b4e04d0d85cc651fe728e35380f754a21788153b472286c00b50 |
|
MD5 | 3944708f7056161a9fce5c628abd3081 |
|
BLAKE2b-256 | 8ffc07e4d2252bee775480d61a5217f7ba0d3563259a5237c70de78080262ec0 |
File details
Details for the file aiohttp_swagger3-0.7.2-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_swagger3-0.7.2-py3-none-any.whl
- Upload date:
- Size: 1.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b460a8e9cee8a3f3ab7a7c51f01870a79d451f327a71efea6ef37ba5d73f73b |
|
MD5 | f5edd2255147353f807901b84e25ec29 |
|
BLAKE2b-256 | 2842cfadbbe2fabe6fa5af09dad0df1df41c6755b3fadd83ffa1ceee256dffe8 |