Skip to content

Commit

Permalink
any unmarshaller types fix
Browse files Browse the repository at this point in the history
  • Loading branch information
p1c2u committed Apr 13, 2023
1 parent 0ff6315 commit 706ea03
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions openapi_core/unmarshalling/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@

oas30_unmarshallers_dict = OrderedDict(
[
("string", PrimitiveUnmarshaller),
("object", ObjectUnmarshaller),
("array", ArrayUnmarshaller),
("boolean", PrimitiveUnmarshaller),
("integer", PrimitiveUnmarshaller),
("number", PrimitiveUnmarshaller),
("boolean", PrimitiveUnmarshaller),
("array", ArrayUnmarshaller),
("object", ObjectUnmarshaller),
("string", PrimitiveUnmarshaller),
]
)
oas31_unmarshallers_dict = oas30_unmarshallers_dict.copy()
Expand Down
14 changes: 4 additions & 10 deletions openapi_core/unmarshalling/schemas/unmarshallers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,9 @@ def _get_best_unmarshaller(self, value: Any) -> "PrimitiveUnmarshaller":


class AnyUnmarshaller(MultiTypeUnmarshaller):
SCHEMA_TYPES_ORDER = [
"object",
"array",
"boolean",
"integer",
"number",
"string",
]

@property
def type(self) -> List[str]:
return self.SCHEMA_TYPES_ORDER
return self.schema_unmarshaller.types_unmarshaller.get_types()


class TypesUnmarshaller:
Expand All @@ -195,6 +186,9 @@ def __init__(
self.default = default
self.multi = multi

def get_types(self) -> List[str]:
return list(self.unmarshallers.keys())

def get_unmarshaller(
self,
schema_type: Optional[Union[Iterable[str], str]],
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/unmarshalling/test_unmarshallers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2059,3 +2059,12 @@ def test_nultiple_types_invalid(self, unmarshallers_factory, types, value):
unmarshaller.unmarshal(value)
assert len(exc_info.value.schema_errors) == 1
assert "is not of type" in exc_info.value.schema_errors[0].message

def test_any_null(self, unmarshallers_factory):
schema = {}
spec = Spec.from_dict(schema, validator=None)
unmarshaller = unmarshallers_factory.create(spec)

result = unmarshaller.unmarshal(None)

assert result is None

0 comments on commit 706ea03

Please sign in to comment.