Skip to content

Two errors in Schema #92

Description

@elsimqoz
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': {}})
  1. Run it, get error
Traceback (most recent call last):
  ...
    @request_schema(RequestSchema(strict=True))
TypeError: __init__() got an unexpected keyword argument 'strict'
  1. 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.']}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions