Pydantic: Schema of dynamic models do not have properties

Created on 24 Apr 2020  路  2Comments  路  Source: samuelcolvin/pydantic

Bug

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: []
bug

Most helpful comment

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.

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashears picture ashears  路  3Comments

engstrom picture engstrom  路  3Comments

nav picture nav  路  3Comments

ashpreetbedi picture ashpreetbedi  路  3Comments

sbv-trueenergy picture sbv-trueenergy  路  3Comments