Maillol / aiohttp-pydantic

Aiohttp View that validates request body and query sting regarding the annotations declared in the View method
MIT License
67 stars 21 forks source link

Define tags for View routes #24

Closed eduard-sukharev closed 3 years ago

eduard-sukharev commented 3 years ago

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)
Maillol commented 3 years ago

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.

Maillol commented 3 years ago

implemented in aiohttp-pydantic 1.11.0

Add docstring with Tags: post_tag instead of use decorator.