mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
dd8d013e10
* starting field and model schemas * field.schema() * sub-models working * move default in Schema and tests * adding schema * tweak docs
35 lines
695 B
Python
35 lines
695 B
Python
import json
|
|
from enum import IntEnum
|
|
from pydantic import BaseModel, Schema
|
|
|
|
class FooBar(BaseModel):
|
|
count: int
|
|
size: float = None
|
|
|
|
class Gender(IntEnum):
|
|
male = 1
|
|
female = 2
|
|
other = 3
|
|
not_given = 4
|
|
|
|
class MainModel(BaseModel):
|
|
"""
|
|
This is the description of the main model
|
|
"""
|
|
foo_bar: FooBar = Schema(...)
|
|
gender: Gender = Schema(
|
|
None,
|
|
alias='Gender',
|
|
choice_names={3: 'Other Gender', 4: "I'd rather not say"}
|
|
)
|
|
snap: int = Schema(
|
|
42,
|
|
title='The Snap',
|
|
description='this is the value of snap'
|
|
)
|
|
|
|
class Config:
|
|
title = 'Main'
|
|
|
|
print(json.dumps(MainModel.schema(), indent=2))
|