OpenAPIResponse
class¶
esmerald.openapi.datastructures.OpenAPIResponse
¶
Bases: BaseModel
The OpenAPIResponse is used for OpenAPI documentation purposes and allows to describe in detail what alternative responses the API can return as well as the type of the return itself.
Example
from typing import Union
from esmerald import post
from esmerald.openapi.datastructures import OpenAPIResponse
from pydantic import BaseModel
class ItemOut(BaseModel):
sku: str
description: str
@post(path='/create', summary="Creates an item", responses={200: OpenAPIResponse(model=ItemOut, description="Successfully created an item")})
async def create() -> Union[None, ItemOut]:
...
model
instance-attribute
¶
model
A pydantic.BaseModel
type of object of a list
of
pydantic.BaseModel
types of objects.
This is parsed and displayed in the OpenAPI documentation.
Example
from esmerald.openapi.datastructures import OpenAPIResponse
from pydantic import BaseModel
class Error(BaseModel):
detail: str
# Single
OpenAPIResponse(model=Error)
# List
OpenAPIResponse(model=[Error])