Skip to content

Get rid of NoValue type #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions openapi_core/casting/schemas/casters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import division

from openapi_core.casting.schemas.exceptions import CastError
from openapi_core.types import NoValue


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

def __call__(self, value):
if value in (None, NoValue):
if value is None:
return value
try:
return self.caster_callable(value)
Expand All @@ -36,6 +35,6 @@ def items_caster(self):
return self.casters_factory.create(self.schema / 'items')

def __call__(self, value):
if value in (None, NoValue):
if value is None:
return value
return list(map(self.items_caster, value))
1 change: 0 additions & 1 deletion openapi_core/types.py

This file was deleted.

13 changes: 5 additions & 8 deletions openapi_core/unmarshalling/schemas/unmarshallers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from openapi_core.schema.schemas import (
get_all_properties, get_all_properties_names
)
from openapi_core.types import NoValue
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
from openapi_core.unmarshalling.schemas.exceptions import (
UnmarshalError, ValidateError, InvalidSchemaValue,
Expand All @@ -38,9 +37,7 @@ def __init__(self, formatter, validator, schema):
self.validator = validator
self.schema = schema

def __call__(self, value=NoValue):
if value is NoValue:
value = self.schema.getkey('default')
def __call__(self, value):
if value is None:
return

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

def __call__(self, value=NoValue):
def __call__(self, value):
value = super(ArrayUnmarshaller, self).__call__(value)
if value is None and self.schema.getkey('nullable', False):
return None
Expand All @@ -172,7 +169,7 @@ def unmarshal(self, value):
else:
return self._unmarshal_object(value)

def _unmarshal_object(self, value=NoValue):
def _unmarshal_object(self, value):
if 'oneOf' in self.schema:
properties = None
for one_of_schema in self.schema / 'oneOf':
Expand All @@ -199,7 +196,7 @@ def _unmarshal_object(self, value=NoValue):

return properties

def _unmarshal_properties(self, value=NoValue, one_of_schema=None):
def _unmarshal_properties(self, value, one_of_schema=None):
all_props = get_all_properties(self.schema)
all_props_names = get_all_properties_names(self.schema)

Expand Down Expand Up @@ -255,7 +252,7 @@ class AnyUnmarshaller(ComplexUnmarshaller):
'integer', 'number', 'string',
]

def unmarshal(self, value=NoValue):
def unmarshal(self, value):
one_of_schema = self._get_one_of_schema(value)
if one_of_schema:
return self.unmarshallers_factory.create(one_of_schema)(value)
Expand Down
42 changes: 0 additions & 42 deletions tests/unit/unmarshalling/test_unmarshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest

from openapi_core.spec.paths import SpecPath
from openapi_core.types import NoValue
from openapi_core.unmarshalling.schemas.enums import UnmarshalContext
from openapi_core.unmarshalling.schemas.exceptions import (
InvalidSchemaFormatValue, InvalidSchemaValue, UnmarshalError,
Expand Down Expand Up @@ -158,34 +157,6 @@ def test_string_float_invalid(self, unmarshaller_factory):
with pytest.raises(InvalidSchemaValue):
unmarshaller_factory(schema)(value)

def test_string_default(self, unmarshaller_factory):
default_value = 'default'
spec = {
'type': 'string',
'default': default_value,
}
schema = SpecPath.from_spec(spec)
value = NoValue

result = unmarshaller_factory(schema)(value)

assert result == default_value

@pytest.mark.parametrize('default_value', ['default', None])
def test_string_default_nullable(
self, default_value, unmarshaller_factory):
spec = {
'type': 'string',
'default': default_value,
'nullable': True,
}
schema = SpecPath.from_spec(spec)
value = NoValue

result = unmarshaller_factory(schema)(value)

assert result == default_value

def test_string_format_date(self, unmarshaller_factory):
spec = {
'type': 'string',
Expand Down Expand Up @@ -361,19 +332,6 @@ def test_integer_enum_string_invalid(self, unmarshaller_factory):
with pytest.raises(UnmarshalError):
unmarshaller_factory(schema)(value)

def test_integer_default(self, unmarshaller_factory):
default_value = 123
spec = {
'type': 'integer',
'default': default_value,
}
schema = SpecPath.from_spec(spec)
value = NoValue

result = unmarshaller_factory(schema)(value)

assert result == default_value

def test_integer_default_nullable(self, unmarshaller_factory):
default_value = 123
spec = {
Expand Down