Maillol / aiohttp-pydantic

Aiohttp View that validates request body and query sting regarding the annotations declared in the View method

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BUG: UI issues using View without request params

chey opened this issue · comments

commented

oas setup doesn't work right when view method doesn't have extra params. It's not unusual for a get request to have no request data.

This example doesn't work:

from typing import Optional

from aiohttp import web
from aiohttp_pydantic import PydanticView, oas
from pydantic import BaseModel

# Use pydantic BaseModel to validate request body
class ArticleModel(BaseModel):
    name: str
    nb_page: Optional[int]


# Create your PydanticView and add annotations.
class ArticleView(PydanticView):

    async def post(self, article: ArticleModel):
        return web.json_response({'name': article.name,
                                  'number_of_page': article.nb_page})

    async def get(self):
        return web.json_response({'name': 'foobar'})


app = web.Application()
oas.setup(app)
app.router.add_view('/article', ArticleView)
web.run_app(app)

Here is what happens in the UI

image