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

Define tags for View routes

eduard-sukharev opened this issue · comments

How to define tags for PydanticViews? The usual solution with @docs annotation does not work:

from aiohttp import web
from aiohttp_apispec import docs
from aiohttp_pydantic import PydanticView

from my_models import SomeModel

routes = web.RouteTableDef()


@routes.view('/pipeline')
class PipelineView(PydanticView):
    @docs(tags=['post_tag'])
    async def post(self, some_pydantic_model: SomeModel) -> r201:
        # business logic here

        return web.json_response(
            {'answer': 42},
            status=web.HTTPCreated.status_code)

It's because aiohttp-pydantic does not understand the "aiohttp_apispec.doc" decorator.

Currently, you can only custom the generated Open API Specification using annotation or docstring.
For example you can add response description with:

@routes.view('/pipeline')
class PipelineView(PydanticView):

    async def post(self, some_pydantic_model: SomeModel) -> r201:
        """
        Route description 
        
        Status Codes:
            201: Response description line 1
               response description line 2
        """

Currently custom "tags" is not implemented. I will add this feature.

implemented in aiohttp-pydantic 1.11.0

Add docstring with Tags: post_tag instead of use decorator.