OpenAPIResponse class¶
ravyn.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 ravyn import post
from ravyn.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 ravyn.openapi.datastructures import OpenAPIResponse
from pydantic import BaseModel
class Error(BaseModel):
detail: str
# Single
OpenAPIResponse(model=Error)
# list
OpenAPIResponse(model=[Error])
description
class-attribute
instance-attribute
¶
description = 'Additional response'
Description of the response.
This description is displayed in the OpenAPI documentation.
status_text
class-attribute
instance-attribute
¶
status_text = None
Description of the status_code. The description of the status code itself.
This description is displayed in the OpenAPI documentation.
validate_model
¶
validate_model(model)
Source code in ravyn/openapi/datastructures.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
- "!^model_config"
- "!^validate_model"