diff --git a/HISTORY.rst b/HISTORY.rst index 35ed1df..e4b7991 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,6 +9,7 @@ v0.17.0 (unreleased) * prevent validators being called repeatedly after inheritance, #327 by @samuelcolvin * prevent duplicate validator check in ipython, fix #312 by @samuelcolvin * add "Using Pydantic" section to docs, #323 by @tiangolo & #326 by @samuelcolvin +* fix schema generation for fields annotated as ``: dict``, #330 by @nkonin v0.16.1 (2018-12-10) .................... diff --git a/pydantic/schema.py b/pydantic/schema.py index 9525ce1..5997469 100644 --- a/pydantic/schema.py +++ b/pydantic/schema.py @@ -558,6 +558,7 @@ field_class_to_schema_enum_enabled = ( (UUID5, {'type': 'string', 'format': 'uuid5'}), (UUID, {'type': 'string', 'format': 'uuid'}), (NameEmail, {'type': 'string', 'format': 'name-email'}), + (dict, {'type': 'object'}), ) diff --git a/tests/test_schema.py b/tests/test_schema.py index 31ca55a..2489dff 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -308,6 +308,18 @@ def test_bool(): } +def test_dict(): + class Model(BaseModel): + a: dict + + assert Model.schema() == { + 'title': 'Model', + 'type': 'object', + 'properties': {'a': {'title': 'A', 'type': 'object'}}, + 'required': ['a'], + } + + class Foo(BaseModel): a: float