Skip to content

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

Merged
wing328 merged 11 commits intoOpenAPITools:masterfrom
kevchentw:fix-8116-2
Feb 24, 2022
Merged

[Python] remove default content-type in the request#10782
wing328 merged 11 commits intoOpenAPITools:masterfrom
kevchentw:fix-8116-2

Conversation

@kevchentw
Copy link
Copy Markdown
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
Comment thread modules/openapi-generator/src/main/resources/python-legacy/api.mustache Outdated
@spacether
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

:return: Content-Type (e.g. application/json).
"""
if not content_types:
return 'application/json'
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

wing328 commented Feb 14, 2022

@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