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

Set 'title' for model field

eduard-sukharev opened this issue · comments

I have a model:

from aiohttp_pydantic import PydanticView, oas
from pydantic import BaseModel

class Task(BaseModel):
    id: str
    type: str
    on_success: Optional[str] # ID for task to run on success
    on_error: Optional[str] # ID for task to run on failure


@routes.view('/task')
class TaskView(PydanticView):
    async def post(self, task: Task):
        // some task logic

And in a Swagger UI (OAS) I get following model description:

id*: string
    title: Id
type*: string
    title: Type
on_success: string
    title: On Success
on_error: string
    title: On Error

What I want is to somehow define the title in pydantic model so that it's not plainly repeat the field itself. How do I do that?

from pydantic import BaseModel, Field

class Task(BaseModel):
    id: str = Field(title="my title")
    type: str
    on_success: Optional[str] # ID for task to run on success
    on_error: Optional[str] # ID for task to run on failure

You can find more details here:

https://pydantic-docs.helpmanual.io/usage/schema/#field-customisation