Closed
Description
Actual Behavior
An exception is raised when passing a null value even though the spec says it's a valid type.
openapi_core.unmarshalling.schemas.exceptions.UnmarshallerError: Unmarshaller not found for type(s)
Traceback:
Traceback (most recent call last):
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/validation/decorators.py", line 31, in wrapper
return f(*args, **kwds)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/validation/request/validators.py", line 253, in _get_body
return self._get_content_value(raw_body, mimetype, content)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/unmarshallers.py", line 113, in _get_content_value
return self._unmarshal_schema(schema, casted)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/unmarshallers.py", line 90, in _unmarshal_schema
return unmarshaller.unmarshal(value)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 299, in unmarshal
typed = type_unmarshaller(value)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 57, in __call__
properties = self._unmarshal_properties(value)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 111, in _unmarshal_properties
properties[prop_name] = self.schema_unmarshaller.evolve(
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 299, in unmarshal
typed = type_unmarshaller(value)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 145, in __call__
unmarshaller = self._get_best_unmarshaller(value)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 169, in _get_best_unmarshaller
raise UnmarshallerError("Unmarshaller not found for type(s)")
openapi_core.unmarshalling.schemas.exceptions.UnmarshallerError: Unmarshaller not found for type(s)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/user1/example_bug.py", line 41, in <module>
unmarshal_request(request, spec)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/shortcuts.py", line 173, in unmarshal_request
return unmarshal_apicall_request(
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/shortcuts.py", line 117, in unmarshal_apicall_request
result.raise_for_errors()
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/datatypes.py", line 14, in raise_for_errors
raise error
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/unmarshalling/request/unmarshallers.py", line 154, in _unmarshal
body = self._get_body(request.body, request.mimetype, operation)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/validation/decorators.py", line 35, in wrapper
self._raise_error(exc, self.err_cls, f, *args, **kwds)
File "/Users/user1/venv/lib/python3.8/site-packages/openapi_core/validation/decorators.py", line 58, in _raise_error
raise init(**kw) from exc
openapi_core.validation.request.exceptions.RequestBodyValidationError: Request body validation error
Expected Behavior
Should not raise an exception.
Steps to Reproduce
I believe the issue is that
class AnyUnmarshaller(MultiTypeUnmarshaller):
SCHEMA_TYPES_ORDER = [
"object",
"array",
"boolean",
"integer",
"number",
"string",
]
in openapi_core/unmarshalling/schemas/unmarshallers.py
doesn't contain the "null" type.
Minimal example to reproduce the issue:
from openapi_core import Spec
from openapi_core.testing import MockRequest
from openapi_core import unmarshal_request
spec = Spec.from_dict(
{
"openapi": "3.1.0",
"info": {"title": "test", "version": "0"},
"paths": {
"/test": {
"post": {
"requestBody": {
"required": True,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"oneOf": [
{"type": "string"},
{"type": "null"}
],
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
},
}
)
request = MockRequest(
host_url="http://localhost/",
method="post",
path="/test",
data=json.dumps({"name": None})
)
unmarshal_request(request, spec)
OpenAPI Core Version
0.17.1
OpenAPI Core Integration
none
Affected Area(s)
unmarshalling
References
No response
Anything else we need to know?
Adding "null" to the array mentioned above seems to fix the issue. I can add a PR for that but I'm not sure what's the protocol to do that.
Thanks!
Would you like to implement a fix?
Yes