mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
f55515820a
* renaming .json -> .model_dump_json * renaming .dict -> .model_dump * renaming .__fields__ -> .model_fields * renaming .schema -> .model_json_schema * renaming .construct -> .model_construct * renaming .parse_obj -> .model_validate * make linters happy * add changes md-file Co-authored-by: Samuel Colvin <s@muelcolvin.com>
39 lines
735 B
Python
39 lines
735 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 equivalent to json.dumps(MainModel.model_json_schema(), indent=2):
|
|
print(MainModel.schema_json(indent=2))
|