Pydantic
provides
schema_extra
配置选项:
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
class Config:
schema_extra = {
'$id': "my.custom.schema"
}
print(Person.schema_json(indent=2))
输出:
{
"title": "Person",
"type": "object",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"age": {
"title": "Age",
"type": "integer"
}
},
"required": [
"name",
"age"
],
"$id": "my.custom.schema"
}