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

Does not working class based views

Open ALeksandr-Fuze opened this issue 4 years ago • 7 comments

python 3.8. aiohttp 3.6.2 It does not work class-based views, Swagger shows nothing. When using function style all work correctly.

class SomeView(web.View):
    @docs(
        tags=["mytag"],
        summary="View method summary",
        description="View method description",
    )
    async def post(self) -> web.json_response:
        pass

ALeksandr-Fuze avatar Nov 22 '19 12:11 ALeksandr-Fuze

you can use a simple class and route that.

class NewsAPIHandler(object):
    @docs(
        tags=['news'],
        summary='Get news article(s)',
        description='Get news article.'
    )
    @request_schema(GetRequestSchema())
    async def get_article(self, request):
        pass

thijstriemstra avatar Dec 01 '19 00:12 thijstriemstra

Yes, but for the router, I should get a callable Requeste or awaitable stream object. app.router.add_route('*', '/some_api', views. NewsAPIHandler) - will be not work app.router.add_post('/some_api', views.NewsAPIHandler(). get_article) - looks not good and works only for one HTTP method.

ALeksandr-Fuze avatar Dec 02 '19 13:12 ALeksandr-Fuze

Hm... It works if a class was decorated:

@docs(
        tags=["mytag"],
        summary="View method summary",
        description="View method description",
    )
class SomeView(web.View):
    async def post(self) -> web.json_response:
        pass

ALeksandr-Fuze avatar Dec 02 '19 14:12 ALeksandr-Fuze

+1

not working for

@request_schema(SchemaPost)
@response_schema(SchemaResp)
async def post(self):
    ...

CrazySky2121 avatar Sep 25 '20 09:09 CrazySky2121

As ALeksandr-Fuze mentioned it works only for web.View classes for now. I will make a fix to support your case.

maximdanilchenko avatar Oct 15 '20 11:10 maximdanilchenko

@maximdanilchenko +1 for this

allyo-dmytro-smyk avatar Oct 18 '20 17:10 allyo-dmytro-smyk

Hello guys! Do you have any ETA for this feature?

CrazySky2121 avatar Dec 09 '20 12:12 CrazySky2121