aiohttp-apispec icon indicating copy to clipboard operation
aiohttp-apispec copied to clipboard

docs: RequestSchema(strict=True) raises TypeError

Open ikhlestov opened this issue 2 years ago • 0 comments

If you try to run first example from docs, you'll get an TypeError exception:

Traceback (most recent call last):
  File "app.py", line 19, in <module>
    @request_schema(RequestSchema(strict=True))
TypeError: __init__() got an unexpected keyword argument 'strict'

It looks that after marshmallow version >= 3.0 release Schema always strict.

Should we freeze marshmallow version and update docs? Or there should be some kind of another solution.

Steps to reproduce

Environment

Python 3.8.12

aiohttp==3.8.1
aiohttp-apispec==2.2.3
aiosignal==1.2.0
apispec==3.3.2
async-timeout==4.0.2
attrs==21.4.0
charset-normalizer==2.0.12
frozenlist==1.3.0
idna==3.3
Jinja2==3.1.2
MarkupSafe==2.1.1
marshmallow==3.15.0
multidict==6.0.2
packaging==21.3
pyparsing==3.0.9
webargs==5.5.3
yarl==1.7.2

Code

This is the first snipped from the README

from aiohttp_apispec import (
    docs,
    request_schema,
    setup_aiohttp_apispec,
)
from aiohttp import web
from marshmallow import Schema, fields


class RequestSchema(Schema):
    id = fields.Int()
    name = fields.Str(description="name")

@docs(
    tags=["mytag"],
    summary="Test method summary",
    description="Test method description",
)
@request_schema(RequestSchema(strict=True))
async def index(request):
    return web.json_response({"msg": "done", "data": {}})


app = web.Application()
app.router.add_post("/v1/test", index)

# init docs with all parameters, usual for ApiSpec
setup_aiohttp_apispec(
    app=app, 
    title="My Documentation", 
    version="v1",
    url="/api/docs/swagger.json",
    swagger_path="/api/docs",
)

# Now we can find spec on 'http://localhost:8080/api/docs/swagger.json'
# and docs on 'http://localhost:8080/api/docs'
web.run_app(app)

Save it to app.py file and start with python app.py command

ikhlestov avatar May 15 '22 22:05 ikhlestov