Согласно документации, описание в схеме JSON модели Pydantic получено из строки документации:
class MainModel(BaseModel):
"""This is the description of the main model"""
class Config:
title = 'Main'
print(MainModel.schema_json(indent=2))
# {
# "title": "Main",
# "description": "This is the description of the main model",
# ...
Есть ли способ перезаписать (соответственно установить вручную) значение записи "description"
(без необходимости изменения строки документации), как для "title"
? К сожалению, использование атрибута description
для внутреннего класса Config
не работает.
Можно использовать атрибут schema_extra
внутреннего класса Config
:
class MainModel(BaseModel):
"""This is the description of the main model"""
class Config:
title = 'Main'
schema_extra = {
"description": "Main models are the models we use the most"
}
print(MainModel.schema_json(indent=2))
# {
# "title": "Main",
# "description": "Main models are the models we use the most",
# ...