validation for aiohttp swagger openAPI 3
Project description
aiohttp-swagger3
!!! Testers are needed !!!
Feel free to try this library and raise an issue if it does not work as expected, thanks!
About
Package for validating aiohttp requests using swagger specification 3.0.
It's marked as pre-alpha on pypi.org, but that's because I haven't decided architecture yet. However, we use it in production :)
Requirements
- python3.6+
- aiohttp>3 (haven't tested with v2, though)
- pyyaml
- attrs
- openapi-spec-validator
- strict_rfc3339
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
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()
s = SwaggerDocs(app, '/docs', title="Swagger Petstore", version="1.0.0", components="components.yaml")
s.add_routes([
web.get("/pets/{pet_id}", get_one_pet),
])
app['storage'] = {}
web.run_app(app)
More examples
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
- allOf
- oneOf
- anyOf
- string formats: date, date-time, password, byte, binary, email, uuid, hostname, ipv4, ipv6
TODO (raise an issue if needed)
-
aiohttp specific
-
class based view
-
METH_ANY (*) routes
-
swagger specific
-
cookies
-
multipleOf
-
not
-
allowEmptyValue
-
Common Parameters for All Methods of a Path (spec file only)
-
readOnly, writeOnly
-
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.1.3.tar.gz
.
File metadata
- Download URL: aiohttp-swagger3-0.1.3.tar.gz
- Upload date:
- Size: 412.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 589f88798b31726fc16e2d4bc8542dc630eebac1bf8e96634d200b9a7ebb95d0 |
|
MD5 | 97cecb45c2b106754d5a7378113dbcd5 |
|
BLAKE2b-256 | 448d4e77edab635cfb6d359cd16591f62c6934028df9ac3e17ff541912825244 |
File details
Details for the file aiohttp_swagger3-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_swagger3-0.1.3-py3-none-any.whl
- Upload date:
- Size: 420.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 627f8ab42fca5bdfc26dcbd3b2aea3d4788c26a55efddc383a0f17541aca914d |
|
MD5 | ad95d11641a4fb84b69b0434f747cd0c |
|
BLAKE2b-256 | 5a01f8683bf410f6953bc65d38bb5501cdcd632b9b66b76dc731671afbfd5d97 |