Ubuntu 18.04
Python 3.8.0
aiohttp==3.6.2
aiohttp-apispec==2.2.1
https://github.com/maximdanilchenko/aiohttp-apispec/blob/master/docs/usage.rst
class ResponseSchema(Schema):
msg = fields.Str()
data = fields.Dict()
@docs(tags=['mytag'],
summary='Test method summary',
description='Test method description')
@request_schema(RequestSchema(strict=True))
@response_schema(ResponseSchema(), 200)
async def index(request):
return web.json_response({'msg': 'done',
'data': {}})
- Run it, get error
Traceback (most recent call last):
...
@request_schema(RequestSchema(strict=True))
TypeError: __init__() got an unexpected keyword argument 'strict'
- Let's add not-in-schema field
@response_schema(ResponseSchema(), 200)
return web.json_response({'msg': 'done',
'data': {}, 'foo': 'bar'})
It seems that ResponseSchema didn't validate response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Server: Python/3.8 aiohttp/3.6.2
{
"data": {},
"foo": "bar",
"msg": "done"
}
But directly it will
>>> ResponseSchema().validate({'msg': 'done', 'data': {}, 'foo': 'bar'})
{'foo': ['Unknown field.']}
https://github.com/maximdanilchenko/aiohttp-apispec/blob/master/docs/usage.rst
It seems that
ResponseSchemadidn't validate responseBut directly it will