Skip to content

any unmarshaller get types fix #555

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
Apr 13, 2023
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
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