Skip to content

Commit 3c97783

Browse files
committed
Get rid of NoValue type
1 parent 38ab5a0 commit 3c97783

File tree

4 files changed

+7
-54
lines changed

4 files changed

+7
-54
lines changed

openapi_core/casting/schemas/casters.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import division
22

33
from openapi_core.casting.schemas.exceptions import CastError
4-
from openapi_core.types import NoValue
54

65

76
class PrimitiveCaster(object):
@@ -11,7 +10,7 @@ def __init__(self, schema, caster_callable):
1110
self.caster_callable = caster_callable
1211

1312
def __call__(self, value):
14-
if value in (None, NoValue):
13+
if value is None:
1514
return value
1615
try:
1716
return self.caster_callable(value)
@@ -36,6 +35,6 @@ def items_caster(self):
3635
return self.casters_factory.create(self.schema / 'items')
3736

3837
def __call__(self, value):
39-
if value in (None, NoValue):
38+
if value is None:
4039
return value
4140
return list(map(self.items_caster, value))

openapi_core/types.py

-1
This file was deleted.

openapi_core/unmarshalling/schemas/unmarshallers.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from openapi_core.schema.schemas import (
1515
get_all_properties, get_all_properties_names
1616
)
17-
from openapi_core.types import NoValue
1817
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
1918
from openapi_core.unmarshalling.schemas.exceptions import (
2019
UnmarshalError, ValidateError, InvalidSchemaValue,
@@ -38,9 +37,7 @@ def __init__(self, formatter, validator, schema):
3837
self.validator = validator
3938
self.schema = schema
4039

41-
def __call__(self, value=NoValue):
42-
if value is NoValue:
43-
value = self.schema.getkey('default')
40+
def __call__(self, value):
4441
if value is None:
4542
return
4643

@@ -145,7 +142,7 @@ class ArrayUnmarshaller(ComplexUnmarshaller):
145142
def items_unmarshaller(self):
146143
return self.unmarshallers_factory.create(self.schema / 'items')
147144

148-
def __call__(self, value=NoValue):
145+
def __call__(self, value):
149146
value = super(ArrayUnmarshaller, self).__call__(value)
150147
if value is None and self.schema.getkey('nullable', False):
151148
return None
@@ -172,7 +169,7 @@ def unmarshal(self, value):
172169
else:
173170
return self._unmarshal_object(value)
174171

175-
def _unmarshal_object(self, value=NoValue):
172+
def _unmarshal_object(self, value):
176173
if 'oneOf' in self.schema:
177174
properties = None
178175
for one_of_schema in self.schema / 'oneOf':
@@ -199,7 +196,7 @@ def _unmarshal_object(self, value=NoValue):
199196

200197
return properties
201198

202-
def _unmarshal_properties(self, value=NoValue, one_of_schema=None):
199+
def _unmarshal_properties(self, value, one_of_schema=None):
203200
all_props = get_all_properties(self.schema)
204201
all_props_names = get_all_properties_names(self.schema)
205202

@@ -255,7 +252,7 @@ class AnyUnmarshaller(ComplexUnmarshaller):
255252
'integer', 'number', 'string',
256253
]
257254

258-
def unmarshal(self, value=NoValue):
255+
def unmarshal(self, value):
259256
one_of_schema = self._get_one_of_schema(value)
260257
if one_of_schema:
261258
return self.unmarshallers_factory.create(one_of_schema)(value)

tests/unit/unmarshalling/test_unmarshal.py

-42
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66

77
from openapi_core.spec.paths import SpecPath
8-
from openapi_core.types import NoValue
98
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
109
from openapi_core.unmarshalling.schemas.exceptions import (
1110
InvalidSchemaFormatValue, InvalidSchemaValue, UnmarshalError,
@@ -158,34 +157,6 @@ def test_string_float_invalid(self, unmarshaller_factory):
158157
with pytest.raises(InvalidSchemaValue):
159158
unmarshaller_factory(schema)(value)
160159

161-
def test_string_default(self, unmarshaller_factory):
162-
default_value = 'default'
163-
spec = {
164-
'type': 'string',
165-
'default': default_value,
166-
}
167-
schema = SpecPath.from_spec(spec)
168-
value = NoValue
169-
170-
result = unmarshaller_factory(schema)(value)
171-
172-
assert result == default_value
173-
174-
@pytest.mark.parametrize('default_value', ['default', None])
175-
def test_string_default_nullable(
176-
self, default_value, unmarshaller_factory):
177-
spec = {
178-
'type': 'string',
179-
'default': default_value,
180-
'nullable': True,
181-
}
182-
schema = SpecPath.from_spec(spec)
183-
value = NoValue
184-
185-
result = unmarshaller_factory(schema)(value)
186-
187-
assert result == default_value
188-
189160
def test_string_format_date(self, unmarshaller_factory):
190161
spec = {
191162
'type': 'string',
@@ -361,19 +332,6 @@ def test_integer_enum_string_invalid(self, unmarshaller_factory):
361332
with pytest.raises(UnmarshalError):
362333
unmarshaller_factory(schema)(value)
363334

364-
def test_integer_default(self, unmarshaller_factory):
365-
default_value = 123
366-
spec = {
367-
'type': 'integer',
368-
'default': default_value,
369-
}
370-
schema = SpecPath.from_spec(spec)
371-
value = NoValue
372-
373-
result = unmarshaller_factory(schema)(value)
374-
375-
assert result == default_value
376-
377335
def test_integer_default_nullable(self, unmarshaller_factory):
378336
default_value = 123
379337
spec = {

0 commit comments

Comments
 (0)