Skip to content

[python] Support "default" responses in python client - #24309

Merged
wing328 merged 4 commits into
OpenAPITools:masterfrom
calcasa:python-support-default-responses
Jul 18, 2026
Merged

wing328 merged 4 commits into
OpenAPITools:masterfrom
calcasa:python-support-default-responses

Conversation

@EraYaN

@EraYaN EraYaN commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

This makes sure that the python client actually respects the default response type instead of returning None. Making is much more useful.

Would fix #11793 for the python generator.

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.

@cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10)


Summary by cubic

Honor OpenAPI default responses in Python clients by deserializing them when no explicit status mapping matches (including invalid or out-of-range statuses). Fixes #11793.

  • Bug Fixes
    • Fallback to 'default' only when no exact or Xxx class match exists, status is missing/invalid/out-of-range, and 'default' is defined in the map.
    • In partial_api.mustache, emit 'default' in _response_types_map for wildcard responses only when a schema is present.
    • Regenerated Python samples and petstore clients to include the 'default' mapping (aiohttp, httpx, httpx-sync, sync, lazyImports, echo_api, legacy-model-dictionaries).

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

Review in cubic

@EraYaN EraYaN changed the title Support "default" responses in python client [python] Support "default" responses in python client Jul 15, 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.

All reported issues were addressed across 20 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/petstore_api/api_client.py Outdated
Comment thread samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py Outdated
Comment thread samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py Outdated
Comment thread samples/openapi3/client/petstore/python-aiohttp/petstore_api/api/user_api.py Outdated
@EraYaN
EraYaN force-pushed the python-support-default-responses branch from d171522 to b670e10 Compare July 15, 2026 08:30
@EraYaN
EraYaN force-pushed the python-support-default-responses branch from b670e10 to edf2f14 Compare July 15, 2026 08:32
@EraYaN

EraYaN commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

I have added a small comment, it's essentially an inverse condition of the previous two statements

@EraYaN
EraYaN force-pushed the python-support-default-responses branch from b077e03 to a450ff9 Compare July 17, 2026 10:42
@wing328 wing328 added this to the 7.24.0 milestone Jul 18, 2026
@wing328
wing328 merged commit d3db8f9 into OpenAPITools:master Jul 18, 2026
57 checks passed
@EraYaN
EraYaN deleted the python-support-default-responses branch July 20, 2026 09:32
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-legacy] No return value if only 'default' response type specified

2 participants