mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
c3098a30cf
* Consistent __repr__ and __str__ methods for all types * add change description * devtools integration and feedback on repr methods * fix Color repr * tests for truncate * add devtools section to docs * tests for devtools * ValidationError inheriting from Representation * fix imports * tweaks * tweak docs * exec_examples.py integration with __repr__ changes
34 lines
719 B
Python
34 lines
719 B
Python
# output-json
|
|
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'
|
|
|
|
# this is equivilant of json.dumps(MainModel.schema(), indent=2):
|
|
print(MainModel.schema_json(indent=2))
|