mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
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:
@@ -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)
|
||||
....................
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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'}),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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'],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user