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>
17 lines
390 B
Python
17 lines
390 B
Python
from typing import List
|
|
import json
|
|
from pydantic import BaseModel
|
|
from pydantic.schema import schema
|
|
|
|
|
|
class Pets(BaseModel):
|
|
__root__: List[str]
|
|
|
|
|
|
print(Pets(__root__=['dog', 'cat']))
|
|
print(Pets(__root__=['dog', 'cat']).model_dump_json())
|
|
print(Pets.model_validate(['dog', 'cat']))
|
|
print(Pets.model_json_schema())
|
|
pets_schema = schema([Pets])
|
|
print(json.dumps(pets_schema, indent=2))
|