forked from loafle/openapi-generator-original
[Python][Client] Allow all content-types with text/ prefix (#19802)
* ODM-12108: allow all content-types with text/ prefix * ODM-12108: Update deserialization tests --------- Co-authored-by: Oleg Kunitsyn <you@example.com>
This commit is contained in:
@@ -417,7 +417,7 @@ class ApiClient:
|
|||||||
data = ""
|
data = ""
|
||||||
else:
|
else:
|
||||||
data = json.loads(response_text)
|
data = json.loads(response_text)
|
||||||
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
|
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
|
||||||
data = response_text
|
data = response_text
|
||||||
else:
|
else:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ class RESTClientObject:
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
preload_content=False
|
preload_content=False
|
||||||
)
|
)
|
||||||
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
|
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
||||||
request_body = "true" if body else "false"
|
request_body = "true" if body else "false"
|
||||||
r = self.pool_manager.request(
|
r = self.pool_manager.request(
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ class ApiClient:
|
|||||||
data = ""
|
data = ""
|
||||||
else:
|
else:
|
||||||
data = json.loads(response_text)
|
data = json.loads(response_text)
|
||||||
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
|
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
|
||||||
data = response_text
|
data = response_text
|
||||||
else:
|
else:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ class RESTClientObject:
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
preload_content=False
|
preload_content=False
|
||||||
)
|
)
|
||||||
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
|
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
||||||
request_body = "true" if body else "false"
|
request_body = "true" if body else "false"
|
||||||
r = self.pool_manager.request(
|
r = self.pool_manager.request(
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ class ApiClient:
|
|||||||
data = ""
|
data = ""
|
||||||
else:
|
else:
|
||||||
data = json.loads(response_text)
|
data = json.loads(response_text)
|
||||||
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
|
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
|
||||||
data = response_text
|
data = response_text
|
||||||
else:
|
else:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ class RESTClientObject:
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
preload_content=False
|
preload_content=False
|
||||||
)
|
)
|
||||||
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
|
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
||||||
request_body = "true" if body else "false"
|
request_body = "true" if body else "false"
|
||||||
r = self.pool_manager.request(
|
r = self.pool_manager.request(
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -412,7 +412,7 @@ class ApiClient:
|
|||||||
data = ""
|
data = ""
|
||||||
else:
|
else:
|
||||||
data = json.loads(response_text)
|
data = json.loads(response_text)
|
||||||
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
|
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
|
||||||
data = response_text
|
data = response_text
|
||||||
else:
|
else:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
|
|||||||
@@ -409,7 +409,7 @@ class ApiClient:
|
|||||||
data = ""
|
data = ""
|
||||||
else:
|
else:
|
||||||
data = json.loads(response_text)
|
data = json.loads(response_text)
|
||||||
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
|
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
|
||||||
data = response_text
|
data = response_text
|
||||||
else:
|
else:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ class RESTClientObject:
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
preload_content=False
|
preload_content=False
|
||||||
)
|
)
|
||||||
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
|
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
|
||||||
request_body = "true" if body else "false"
|
request_body = "true" if body else "false"
|
||||||
r = self.pool_manager.request(
|
r = self.pool_manager.request(
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -323,11 +323,17 @@ class DeserializationTests(unittest.TestCase):
|
|||||||
deserialized = self.deserialize(response, "str", 'text/plain')
|
deserialized = self.deserialize(response, "str", 'text/plain')
|
||||||
self.assertTrue(isinstance(deserialized, str))
|
self.assertTrue(isinstance(deserialized, str))
|
||||||
|
|
||||||
|
deserialized = self.deserialize(response, "str", 'text/csv')
|
||||||
|
self.assertTrue(isinstance(deserialized, str))
|
||||||
|
|
||||||
deserialized = self.deserialize(response, "Dict[str, str]", 'APPLICATION/JSON')
|
deserialized = self.deserialize(response, "Dict[str, str]", 'APPLICATION/JSON')
|
||||||
self.assertTrue(isinstance(deserialized, dict))
|
self.assertTrue(isinstance(deserialized, dict))
|
||||||
|
|
||||||
with self.assertRaises(petstore_api.ApiException) as cm:
|
with self.assertRaises(petstore_api.ApiException) as cm:
|
||||||
deserialized = self.deserialize(response, "str", 'text/html')
|
deserialized = self.deserialize(response, "str", 'text')
|
||||||
|
|
||||||
|
with self.assertRaises(petstore_api.ApiException) as cm:
|
||||||
|
deserialized = self.deserialize(response, "str", 'text/n0t-exist!ng')
|
||||||
|
|
||||||
with self.assertRaises(petstore_api.ApiException) as cm:
|
with self.assertRaises(petstore_api.ApiException) as cm:
|
||||||
deserialized = self.deserialize(response, "Dict[str, str]", 'application/jsonnnnn')
|
deserialized = self.deserialize(response, "Dict[str, str]", 'application/jsonnnnn')
|
||||||
|
|||||||
Reference in New Issue
Block a user