diff --git a/HISTORY.rst b/HISTORY.rst index d90b845..6a6b6dd 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,7 @@ v0.31 (unreleased) * add advanced exclude support for ``dict``, ``json`` and ``copy``, #648 by @MrMrRobat * add documentation for Literal type, #651 by @dmontagu * use ``inspect.cleandoc`` internally to get model description, #657 by @tiangolo +* add Color to schema generation, by @euri10 v0.30.1 (2019-07-15) .................... diff --git a/docs/schema_mapping.py b/docs/schema_mapping.py index a38fcb1..8046752 100755 --- a/docs/schema_mapping.py +++ b/docs/schema_mapping.py @@ -433,7 +433,14 @@ table = [ '', 'JSON Schema Core', 'All the properties defined will be defined with standard JSON Schema, including submodels.' - ] + ], + [ + 'Color', + 'string', + '{"format": "color"}', + 'Pydantic standard "format" extension', + '', + ], ] headings = [ diff --git a/pydantic/schema.py b/pydantic/schema.py index 80ab2a5..edb7e85 100644 --- a/pydantic/schema.py +++ b/pydantic/schema.py @@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Sequence, from uuid import UUID import pydantic +from pydantic.color import Color from .fields import Field, Shape from .json import pydantic_encoder @@ -692,6 +693,7 @@ field_class_to_schema_enum_enabled: Tuple[Tuple[Any, Dict[str, Any]], ...] = ( (list, {'type': 'array', 'items': {}}), (tuple, {'type': 'array', 'items': {}}), (set, {'type': 'array', 'items': {}, 'uniqueItems': True}), + (Color, {'type': 'string', 'format': 'color'}), ) diff --git a/tests/test_schema.py b/tests/test_schema.py index 4d77488..bc01835 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -11,6 +11,7 @@ from uuid import UUID import pytest from pydantic import BaseModel, Schema, ValidationError, validator +from pydantic.color import Color from pydantic.schema import ( get_flat_models_from_model, get_flat_models_from_models, @@ -1458,3 +1459,16 @@ def test_literal_schema(): 'title': 'Model', 'type': 'object', } + + +def test_color_type(): + class Model(BaseModel): + color: Color + + model_schema = Model.schema() + assert model_schema == { + 'title': 'Model', + 'type': 'object', + 'properties': {'color': {'title': 'Color', 'type': 'string', 'format': 'color'}}, + 'required': ['color'], + }