Skip to content
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

[Python] remove default content-type in the request #10782

Merged
merged 11 commits into from
Feb 24, 2022

Conversation

kevchentw
Copy link
Contributor

@kevchentw kevchentw commented Nov 4, 2021

Before this fix, the content-type of the request defaults to "application/json".

With this fix, we no longer set such default.

fix #8116, relate to #10769

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) @arun-nalla (2019/11) @spacether (2019/11)

@kevchentw kevchentw changed the title [Pytonn] remove default content-type in the request [Python] remove default content-type in the request Nov 4, 2021
@spacether
Copy link
Contributor

Can you add a test that checks that 1 or two content types are set when they are included in the spec?
Should we allow users to select a specific content type that is present in the given content_types?

@kevchentw
Copy link
Contributor Author

Can you add a test that checks that 1 or two content types are set when they are included in the spec? Should we allow users to select a specific content type that is present in the given content_types?

Sure. Let me add some tests.

I think we cannot let the user to specific content type right now. It defaults to use the first one. Maybe we can create another issue for this?

@spacether spacether added this to the 5.3.1 milestone Nov 5, 2021
@kevchentw
Copy link
Contributor Author

@spacether
I think those tests are enough?

def test_select_header_content_type(self):
content_types = ['APPLICATION/JSON', 'APPLICATION/XML']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['application/json', 'application/xml']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['application/xml', 'application/json']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['text/plain', 'application/xml']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'text/plain')
content_types = []
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, None)

@spacether
Copy link
Contributor

This PR and #10686 (review) are both seeking to solve the same problem

@@ -552,7 +552,7 @@ class ApiClient(object):
:return: Content-Type (e.g. application/json).
"""
if not content_types:
return 'application/json'
Copy link
Contributor

@spacether spacether Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned that this could be a breaking change for servers/client that depended upon this functionality.
How about adding a generator argument useJsonAsDefaultContentType and default it to True.
With that we could put your PR in a patch release.
If you want to default it to False, then this will need to be released as a minor release because it would be a breaking change with a fallback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concerned that this could be a breaking change for servers/client that depended upon this functionality.
How about adding a generator argument useJsonAsDefaultContentType and default it to True.

We've done something similar in other generators (e.g. Ruby) to remove such default behaviour (which was added before I worked on this project). No complains so far.

@spacether
Copy link
Contributor

@spacether I think those tests are enough?

def test_select_header_content_type(self):
content_types = ['APPLICATION/JSON', 'APPLICATION/XML']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['application/json', 'application/xml']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['application/xml', 'application/json']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['text/plain', 'application/xml']
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'text/plain')
content_types = []
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, None)

Thank you for adding those tests

@wing328 wing328 modified the milestones: 5.3.1, 5.4.0 Dec 29, 2021
@wing328 wing328 modified the milestones: 5.4.0, 6.0.0 Jan 31, 2022
@wing328
Copy link
Member

wing328 commented Feb 14, 2022

@kevchentw can you please resolve the merge conflicts when you've time and then PM me via Slack?

https://join.slack.com/t/openapi-generator/shared_invite/zt-12jxxd7p2-XUeQM~4pzsU9x~eGLQqX2g

@wing328 wing328 merged commit ab63786 into OpenAPITools:master Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQ] Fix default Content-Type Header in Python client
3 participants