Skip to content

Commit 38c4678

Browse files
committed
More media types supported
1 parent efdc5be commit 38c4678

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Diff for: openapi_core/deserializing/media_types/__init__.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from json import loads
1+
from json import loads as json_loads
2+
from xml.etree.ElementTree import fromstring as xml_loads
23

34
from openapi_core.deserializing.media_types.datatypes import (
45
MediaTypeDeserializersDict,
@@ -7,12 +8,18 @@
78
MediaTypeDeserializersFactory,
89
)
910
from openapi_core.deserializing.media_types.util import data_form_loads
11+
from openapi_core.deserializing.media_types.util import plain_loads
1012
from openapi_core.deserializing.media_types.util import urlencoded_form_loads
1113

1214
__all__ = ["media_type_deserializers_factory"]
1315

1416
media_type_deserializers: MediaTypeDeserializersDict = {
15-
"application/json": loads,
17+
"text/html": plain_loads,
18+
"text/plain": plain_loads,
19+
"application/json": json_loads,
20+
"application/vnd.api+json": json_loads,
21+
"application/xml": xml_loads,
22+
"application/xhtml+xml": xml_loads,
1623
"application/x-www-form-urlencoded": urlencoded_form_loads,
1724
"multipart/form-data": data_form_loads,
1825
}

Diff for: openapi_core/deserializing/media_types/util.py

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
from urllib.parse import parse_qsl
66

77

8+
def plain_loads(value: Union[str, bytes]) -> str:
9+
if isinstance(value, bytes):
10+
value = value.decode("ASCII", errors="surrogateescape")
11+
return value
12+
13+
814
def urlencoded_form_loads(value: Any) -> Dict[str, Any]:
915
return dict(parse_qsl(value))
1016

Diff for: tests/integration/test_petstore.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ def test_get_pets_response_no_schema(self, spec):
233233
data = "<html></html>"
234234
response = MockResponse(data, status_code=404, mimetype="text/html")
235235

236-
with pytest.warns(UserWarning):
237-
response_result = unmarshal_response(request, response, spec=spec)
236+
response_result = unmarshal_response(request, response, spec=spec)
238237

239238
assert response_result.errors == []
240239
assert response_result.data == data

Diff for: tests/integration/unmarshalling/test_request_unmarshaller.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ def test_post_pets_plain_no_schema(self, request_unmarshaller):
352352
mimetype="text/plain",
353353
)
354354

355-
with pytest.warns(UserWarning):
356-
result = request_unmarshaller.unmarshal(request)
355+
result = request_unmarshaller.unmarshal(request)
357356

358357
assert result.errors == []
359358
assert result.parameters == Parameters(

0 commit comments

Comments
 (0)