Skip to content

Better handling of cookie in python clients#24383

Merged
wing328 merged 3 commits into
masterfrom
python-cookie2
Jul 22, 2026
Merged

Better handling of cookie in python clients#24383
wing328 merged 3 commits into
masterfrom
python-cookie2

Conversation

@wing328

@wing328 wing328 commented Jul 22, 2026

Copy link
Copy Markdown
Member

a follow up pr to #24149

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.

Summary by cubic

Improve cookie handling in Python clients by percent-encoding cookie auth values while preserving RFC 6265–safe characters (including +/=) so base64 and other valid cookies aren’t broken. This prevents malformed Cookie headers when values contain spaces or special characters.

  • Bug Fixes
    • Replace quote-wrapping with urllib.parse.quote(..., safe="!#$%&'()*+-./:<=>?@[]^_`{|}~%+/=") when building the Cookie header.
    • Update python/api_client.mustache and regenerate Python samples (python, python-httpx, python-httpx-sync, python-aiohttp, python-lazyImports, legacy).

Written for commit 00bf923. 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.

All reported issues were addressed across 9 files

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

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/python/api_client.mustache Outdated
Comment thread samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py Outdated
Comment thread samples/client/echo_api/python/openapi_client/api_client.py Outdated
Comment thread samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py Outdated

Copilot AI 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.

Pull request overview

This PR updates the Python client generator’s cookie auth handling to percent-encode cookie values (while attempting to preserve base64 delimiters), and regenerates the affected Python sample clients to reflect the template change.

Changes:

  • Switch cookie auth value handling from quote-wrapping/escaping to urllib.parse.quote(..., safe='+/=') in the Python api_client template.
  • Regenerate multiple Python sample clients (python, python-httpx, python-httpx-sync, python-aiohttp, python-lazyImports, legacy, and echo-api variants) to match the updated template.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
modules/openapi-generator/src/main/resources/python/api_client.mustache Updates the cookie auth value formatting logic in the Python generator template.
samples/openapi3/client/petstore/python/petstore_api/api_client.py Regenerated Petstore Python sample with updated cookie auth handling.
samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py Regenerated lazy-imports Petstore Python sample with updated cookie auth handling.
samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py Regenerated httpx Petstore Python sample with updated cookie auth handling.
samples/openapi3/client/petstore/python-httpx-sync/petstore_api/api_client.py Regenerated httpx-sync Petstore Python sample with updated cookie auth handling.
samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py Regenerated aiohttp Petstore Python sample with updated cookie auth handling.
samples/client/others/python-legacy-model-dictionaries/legacy_model_dict_client/api_client.py Regenerated legacy-model-dictionaries Python sample with updated cookie auth handling.
samples/client/echo_api/python/openapi_client/api_client.py Regenerated echo-api Python sample with updated cookie auth handling.
samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py Regenerated echo-api variant Python sample with updated cookie auth handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +843 to 845
# Account for cookie value containing spaces and special characters, excluding base64 delimiters
cookie_value = quote(str(auth_setting['value']), safe='+/=')
headers['Cookie'] += f"{auth_setting['key']}={cookie_value}"

@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.

All reported issues were addressed across 9 files (changes from recent commits).

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

Comment thread samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py Outdated
Comment thread samples/openapi3/client/petstore/python/petstore_api/api_client.py Outdated
Comment thread modules/openapi-generator/src/main/resources/python/api_client.mustache Outdated
@wing328
wing328 merged commit 2f194fe into master Jul 22, 2026
57 checks passed
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.

2 participants