Skip to content

Commit 4ff8c3a

Browse files
genestack-okunitsynOleg Kunitsyn
and
Oleg Kunitsyn
authored
[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>
1 parent 7d1e999 commit 4ff8c3a

File tree

10 files changed

+18
-12
lines changed

10 files changed

+18
-12
lines changed

modules/openapi-generator/src/main/resources/python/api_client.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class ApiClient:
417417
data = ""
418418
else:
419419
data = json.loads(response_text)
420-
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
420+
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
421421
data = response_text
422422
else:
423423
raise ApiException(

modules/openapi-generator/src/main/resources/python/rest.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class RESTClientObject:
215215
headers=headers,
216216
preload_content=False
217217
)
218-
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
218+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
219219
request_body = "true" if body else "false"
220220
r = self.pool_manager.request(
221221
method,

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
410410
data = ""
411411
else:
412412
data = json.loads(response_text)
413-
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
413+
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
414414
data = response_text
415415
else:
416416
raise ApiException(

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/rest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def request(
226226
headers=headers,
227227
preload_content=False
228228
)
229-
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
229+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
230230
request_body = "true" if body else "false"
231231
r = self.pool_manager.request(
232232
method,

samples/client/echo_api/python/openapi_client/api_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
410410
data = ""
411411
else:
412412
data = json.loads(response_text)
413-
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
413+
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
414414
data = response_text
415415
else:
416416
raise ApiException(

samples/client/echo_api/python/openapi_client/rest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def request(
226226
headers=headers,
227227
preload_content=False
228228
)
229-
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
229+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
230230
request_body = "true" if body else "false"
231231
r = self.pool_manager.request(
232232
method,

samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
412412
data = ""
413413
else:
414414
data = json.loads(response_text)
415-
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
415+
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
416416
data = response_text
417417
else:
418418
raise ApiException(

samples/openapi3/client/petstore/python/petstore_api/api_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
409409
data = ""
410410
else:
411411
data = json.loads(response_text)
412-
elif re.match(r'^text/plain\s*(;|$)', content_type, re.IGNORECASE):
412+
elif re.match(r'^text\/[a-z.+-]+\s*(;|$)', content_type, re.IGNORECASE):
413413
data = response_text
414414
else:
415415
raise ApiException(

samples/openapi3/client/petstore/python/petstore_api/rest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def request(
225225
headers=headers,
226226
preload_content=False
227227
)
228-
elif headers['Content-Type'] == 'text/plain' and isinstance(body, bool):
228+
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
229229
request_body = "true" if body else "false"
230230
r = self.pool_manager.request(
231231
method,

samples/openapi3/client/petstore/python/tests/test_deserialization.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,18 @@ def test_deserialize_content_type(self):
322322

323323
deserialized = self.deserialize(response, "str", 'text/plain')
324324
self.assertTrue(isinstance(deserialized, str))
325-
325+
326+
deserialized = self.deserialize(response, "str", 'text/csv')
327+
self.assertTrue(isinstance(deserialized, str))
328+
326329
deserialized = self.deserialize(response, "Dict[str, str]", 'APPLICATION/JSON')
327330
self.assertTrue(isinstance(deserialized, dict))
328-
331+
332+
with self.assertRaises(petstore_api.ApiException) as cm:
333+
deserialized = self.deserialize(response, "str", 'text')
334+
329335
with self.assertRaises(petstore_api.ApiException) as cm:
330-
deserialized = self.deserialize(response, "str", 'text/html')
336+
deserialized = self.deserialize(response, "str", 'text/n0t-exist!ng')
331337

332338
with self.assertRaises(petstore_api.ApiException) as cm:
333339
deserialized = self.deserialize(response, "Dict[str, str]", 'application/jsonnnnn')

0 commit comments

Comments
 (0)