-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[python] fix deserialize on basic str fails #18800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
50e2575
952bacd
b49bce1
965d7d4
bdda142
8d943de
581b347
334a7d0
e77545e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,17 +174,17 @@ def testBodyParameter(self): | |
| 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) | ||
| self.assertEqual(api_response, "{}") # assertion to ensure {} is sent in the body | ||
|
|
||
| api_response = api_instance.test_echo_body_tag_response_string(None) | ||
| self.assertEqual(api_response, "") # assertion to ensure emtpy string is sent in the body | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails because None is not a json.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the test is for optional body parameter (e.g. Pet). shall we keep it instead?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If that's the case, this test should be performed in Since an empty string is not in JSON format, it conflicts with the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Pet just an example. It can be any models (which will be serialized to JSON string before sending to the server).
Understood as confirmed in https://stackoverflow.com/questions/40614416/is-empty-body-correct-if-content-type-is-application-json. but please take a look at axios/axios#4146 as well, which is also a "use case" presented to use previously (and that's why we've added a test to cover it) With this change, if None is provided, what will be sent to the server? just empty JSON string
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this case,
Ok, add a process to prevent json deserialize if the response is empty.
This change does not change what is sent to the server. An empty json is sent. Currently, the client may send an empty json request.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allow empty json in response |
||
|
|
||
| api_response = api_instance.test_echo_body_free_form_object_response_string({}) | ||
| self.assertEqual(api_response, "{}") # assertion to ensure {} is sent in the body | ||
|
|
||
| api_response = api_instance.test_echo_body_tag_response_string(None) | ||
| self.assertEqual(api_response, "") # assertion to ensure emtpy string is sent in the body | ||
|
|
||
| def testAuthHttpBasic(self): | ||
| api_instance = openapi_client.AuthApi() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None for content_type is allowed to maintain backward compatibility, but this is deprecated and may return an incorrect response.