[python] json like str response (#18069)

* [python] json like str response

* [python] fix response deserialize

* [python] update sample

* [python] fix echo_api test quotes
This commit is contained in:
ふぁ
2024-03-11 21:27:26 +09:00
committed by GitHub
parent 82fcf28a2b
commit 678db1e4af
21 changed files with 8054 additions and 7 deletions

View File

@@ -313,7 +313,10 @@ class ApiClient:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
encoding = match.group(1) if match else "utf-8"
response_text = response_data.data.decode(encoding)
return_data = self.deserialize(response_text, response_type)
if response_type in ["bytearray", "str"]:
return_data = self.__deserialize_primitive(response_text, response_type)
else:
return_data = self.deserialize(response_text, response_type)
finally:
if not 200 <= response_data.status <= 299:
raise ApiException.from_response(

View File

@@ -174,7 +174,7 @@ class TestManual(unittest.TestCase):
n = openapi_client.Pet.from_dict({"name": "testing", "photoUrls": ["http://1", "http://2"]})
api_instance = openapi_client.BodyApi()
api_response = api_instance.test_echo_body_pet_response_string(n)
self.assertEqual(api_response, "{'name': 'testing', 'photoUrls': ['http://1', 'http://2']}")
self.assertEqual(api_response, '{"name": "testing", "photoUrls": ["http://1", "http://2"]}')
t = openapi_client.Tag()
api_response = api_instance.test_echo_body_tag_response_string(t)