Skip to content

Commit 2491454

Browse files
committed
Schema deprecated value
1 parent 943ca12 commit 2491454

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

openapi_core/schemas.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Schema(object):
3030
def __init__(
3131
self, schema_type, model=None, properties=None, items=None,
3232
spec_format=None, required=False, default=None, nullable=False,
33-
enum=None):
33+
enum=None, deprecated=False):
3434
self.type = schema_type
3535
self.model = model
3636
self.properties = properties and dict(properties) or {}
@@ -40,6 +40,7 @@ def __init__(
4040
self.default = default
4141
self.nullable = nullable
4242
self.enum = enum
43+
self.deprecated = deprecated
4344

4445
def __getitem__(self, name):
4546
return self.properties[name]
@@ -77,6 +78,9 @@ def cast(self, value):
7778

7879
def unmarshal(self, value):
7980
"""Unmarshal parameter from the value."""
81+
if self.deprecated:
82+
warnings.warn(
83+
"The schema is deprecated", DeprecationWarning)
8084
casted = self.cast(value)
8185

8286
if casted is None and not self.required:
@@ -149,6 +153,7 @@ def create(self, schema_spec):
149153
items_spec = schema_deref.get('items', None)
150154
nullable = schema_deref.get('nullable', False)
151155
enum = schema_deref.get('enum', None)
156+
deprecated = schema_deref.get('deprecated', False)
152157

153158
properties = None
154159
if properties_spec:
@@ -161,6 +166,7 @@ def create(self, schema_spec):
161166
return Schema(
162167
schema_type, model=model, properties=properties, items=items,
163168
required=required, nullable=nullable, enum=enum,
169+
deprecated=deprecated,
164170
)
165171

166172
@property

tests/unit/test_schemas.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import mock
2+
import warnings
23
import pytest
34

45
from openapi_core.exceptions import InvalidValueType, InvalidValue
@@ -23,6 +24,15 @@ def test_valid(self, schema):
2324

2425
class TestSchemaUnmarshal(object):
2526

27+
def test_deprecated(self):
28+
schema = Schema('string', deprecated=True)
29+
value = 'test'
30+
31+
with pytest.warns(DeprecationWarning):
32+
result = schema.unmarshal(value)
33+
34+
assert result == value
35+
2636
def test_string_valid(self):
2737
schema = Schema('string')
2838
value = 'test'

0 commit comments

Comments
 (0)