From d3cec7be5693276a0449c466cfd64495a42563d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9A=D0=BE=D0=BD?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Thu, 27 Dec 2018 12:48:11 +0300 Subject: [PATCH] Fix schema generation for fields annotated as `: dict` (#331) * #330 Fix schema generation for fields annotated as `: dict` * #330 update history.rst * #330 format on linter's advice --- HISTORY.rst | 1 + pydantic/schema.py | 1 + tests/test_schema.py | 12 ++++++++++++ 3 files changed, 14 insertions(+) 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