Вот моя схема:
Код: Выделить всё
{
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"status": {
"const": "active",
"type": "string"
}
},
"required": [
"name",
"status"
],
"title": "MyBaseModel",
"type": "object"
}
Код: Выделить всё
from __future__ import annotations
from pydantic import BaseModel, Field
class MyBaseModel(BaseModel):
name: str = Field(..., title='Name')
status: str = Field('active', const=True)
Код: Выделить всё
raise PydanticUserError('`const` is removed, use `Literal` instead', code='removed-kwargs')
pydantic.errors.PydanticUserError: `const` is removed, use `Literal` instead
Использование версий:
Код: Выделить всё
Pydantic:2.0.3Код: Выделить всё
datamodel-code-generator:0.22.0Подробнее здесь: https://stackoverflow.com/questions/771 ... emoved-kwa
Мобильная версия