Skip to content

[BUG][PYTHON] Account for content-type parameters on request preparation - #23992

Merged
wing328 merged 5 commits into
OpenAPITools:masterfrom
MarcelKonrad:issue-23990
Jul 30, 2026
Merged

[BUG][PYTHON] Account for content-type parameters on request preparation#23992
wing328 merged 5 commits into
OpenAPITools:masterfrom
MarcelKonrad:issue-23990

Conversation

@MarcelKonrad

@MarcelKonrad MarcelKonrad commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Fixes #23990. A description and a guide on how to reproduce the issue can be found there.

The proposed changes include a new helper function called contenttype_matches that returns true when a given content-type string matches the given type and subtype, otherwise it returns false. Mime type parameters are ignored, but can be optionally be present in the provided string. It also allows for vendor specifications. For example, application/vendor+json is also considered valid against type=application, subtype=json.

@cbornet @tomplus @krjakbrjak @fa0311 @multani


Summary by cubic

Fixes #23990 by making the Python client’s Content-Type matching robust during request prep. We now ignore parameters (including optional whitespace) and accept vendor-suffixed types so request bodies use the right encoder.

  • Bug Fixes
    • Added contenttype_matches helper (case-insensitive, ignores MIME parameters/whitespace, supports vendor+subtype) and documented it at module scope.
    • Switched detection for JSON, application/x-www-form-urlencoded, multipart/form-data, and YAML (application/yaml, text/yaml, text/x-yaml) to use the helper.
    • Use content_type for text/* boolean handling; updated Python template and regenerated samples.

Written for commit d9e47c8. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/python/rest.mustache Outdated
@MarcelKonrad MarcelKonrad changed the title [BUG][PYTHON] Fix 23990: Account for content-type parameters on request preparation [BUG][PYTHON] Fix #23990: Account for content-type parameters on request preparation Jun 11, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread samples/openapi3/client/petstore/python/petstore_api/rest.py
Comment thread modules/openapi-generator/src/main/resources/python/rest.mustache
@MarcelKonrad

Copy link
Copy Markdown
Contributor Author

I rebased the branch to current master and incorporated the changes introduced in #24084.

@fa0311 fa0311 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix and the clear analysis in #23990!

I verified this end-to-end: built the generator, generated a client from the spec in #23990 (plus an application/x-www-form-urlencoded;charset=UTF-8 variant), and ran it against a local server.

@wing328 wing328 added Issue: Bug python Pull requests that update Python code Client: Python and removed python Pull requests that update Python code labels Jul 30, 2026
@wing328 wing328 added this to the 7.25.0 milestone Jul 30, 2026
@wing328
wing328 merged commit 4bb1c74 into OpenAPITools:master Jul 30, 2026
51 checks passed
@wing328 wing328 changed the title [BUG][PYTHON] Fix #23990: Account for content-type parameters on request preparation [BUG][PYTHON] Account for content-type parameters on request preparation Aug 24, 2026
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.

[BUG][PYTHON] Request preparation fails when content-type contains parameters (except for JSON)

3 participants