Color schema (#666)

* First attempt at adding Color in schema() generation

* Lint

* Add history

* Make docs pass

* Added format color

* Format color

* Making history...:)
This commit is contained in:
euri10
2019-07-24 11:52:05 +02:00
committed by Samuel Colvin
parent 1b4c1a884c
commit 1e83ac5137
4 changed files with 25 additions and 1 deletions
+1
View File
@@ -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)
....................
+8 -1
View File
@@ -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 = [
+2
View File
@@ -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'}),
)
+14
View File
@@ -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'],
}