Files
pydantic/docs/examples/schema1.py
T
Samuel Colvin 12f4e0d082 rename Schema to Field (#824)
* rename Schema to Field

* add Schema function with deprecation warning

* mypy tests and other tweaks

* tweaks and cleanup

* Update pydantic/fields.py

Co-Authored-By: Sebastián Ramírez <tiangolo@gmail.com>
2019-09-30 17:49:59 +01:00

39 lines
787 B
Python

from enum import Enum
from pydantic import BaseModel, Field
class FooBar(BaseModel):
count: int
size: float = None
class Gender(str, Enum):
male = 'male'
female = 'female'
other = 'other'
not_given = 'not_given'
class MainModel(BaseModel):
"""
This is the description of the main model
"""
foo_bar: FooBar = Field(...)
gender: Gender = Field(None, alias='Gender')
snap: int = Field(
42,
title='The Snap',
description='this is the value of snap',
gt=30,
lt=50,
)
class Config:
title = 'Main'
print(MainModel.schema())
# > {
# 'type': 'object',
# 'title': 'Main',
# 'properties': {
# 'foo_bar': {
# ...
print(MainModel.schema_json(indent=2))