classBookBody(BaseModel):age:intauthor:strmodel_config=dict(openapi_extra={"description":"This is post RequestBody","example":{"age":12,"author":"author1"},"examples":{"example1":{"summary":"example summary1","description":"example description1","value":{"age":24,"author":"author2"}},"example2":{"summary":"example summary2","description":"example description2","value":{"age":48,"author":"author3"}}}})
Effect in swagger:
You can use reqiured in openapi_extra to mark the RequestBody as Optional.
12345678
classPingBody(BaseModel):ping:Optional[str]=Field("ok",description="String to return, 'ok' when null.")model_config=dict(openapi_extra={"required":False})