diff --git a/openapi_core/unmarshalling/schemas/__init__.py b/openapi_core/unmarshalling/schemas/__init__.py index 9011bcc3..bb0aa65f 100644 --- a/openapi_core/unmarshalling/schemas/__init__.py +++ b/openapi_core/unmarshalling/schemas/__init__.py @@ -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() diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 2387541b..27c63179 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -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: @@ -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]], diff --git a/tests/integration/unmarshalling/test_unmarshallers.py b/tests/integration/unmarshalling/test_unmarshallers.py index 7574a59c..3040adda 100644 --- a/tests/integration/unmarshalling/test_unmarshallers.py +++ b/tests/integration/unmarshalling/test_unmarshallers.py @@ -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