The generated schema of dynamic models do not reflect the properties:
from pydantic import create_model
from pydantic.schema import model_schema, model_process_schema
Test = create_model('Test', id=int, name=str)
print(model_schema(Test))
print(model_process_schema(Test, model_name_map='Test'))
outputs:
{'title': 'Test', 'type': 'object', 'properties': {}}
({'title': 'Test', 'type': 'object', 'properties': {}}, {}, set())
should be:
{'title': 'Test', 'type': 'object', 'properties': {'id': {'title': 'Id', 'type': 'integer'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['id', 'name']}
({'title': 'Test', 'type': 'object', 'properties': {'id': {'title': 'Id', 'type': 'integer'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['id', 'name']}, {}, set())
pydantic version: 1.5
pydantic compiled: True
install path: /Users/tga/miniconda3/envs/polimi/lib/python3.7/site-packages/pydantic
python version: 3.7.7 (default, Mar 26 2020, 10:32:53) [Clang 4.0.1 (tags/RELEASE_401/final)]
platform: Darwin-19.3.0-x86_64-i386-64bit
optional deps. installed: []
Hi @tgaudin
You should write
Test = create_model('Test', id=(int, ...), name=(str, ...))`
Each field is a tuple (type, default value) (see the doc for more info)
And we already consider single values as the default value and not the type.
thanks for helping out with answers @PrettyWood
Most helpful comment
Hi @tgaudin
You should write
Each field is a tuple
(type, default value)(see the doc for more info)And we already consider single values as the default value and not the type.