mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
27 lines
584 B
Python
27 lines
584 B
Python
from pydantic import BaseModel
|
|
|
|
|
|
class Person(BaseModel):
|
|
name: str
|
|
age: int
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
'examples': [
|
|
{
|
|
'name': 'John Doe',
|
|
'age': 25,
|
|
}
|
|
]
|
|
}
|
|
|
|
|
|
print(Person.schema())
|
|
# {'title': 'Person',
|
|
# 'type': 'object',
|
|
# 'properties': {'name': {'title': 'Name', 'type': 'string'},
|
|
# 'age': {'title': 'Age', 'type': 'integer'}},
|
|
# 'required': ['name', 'age'],
|
|
# 'examples': [{'name': 'John Doe', 'age': 25}]}
|
|
print(Person.schema_json(indent=2))
|