Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Support responses with multiple media types incontent#1293

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
nkrishnaswami wants to merge5 commits intoopenapi-generators:main
base:main
Choose a base branch
Loading
fromnkrishnaswami:multiple-media-types

Conversation

@nkrishnaswami
Copy link
Contributor

@nkrishnaswaminkrishnaswami commentedAug 1, 2025
edited
Loading

This PR modifiesopenapi-python-client to recognize multiple media types in OpenAPI response objects and to differentially parse HTTP responses based on theirContent-Type header values. (Today, it generates code for a single content media type of the ones it encounters in the OpenAPI document.) This is useful eg for modeling services where a load balancer can send a 429 with plain text but the service behind it might send one with a schematized JSON response type.

Feedback is welcome, especially on the overall approach.

This PR adds unit tests and one end-to-end test, the latter of which includes sample generated code in theend_to_end_tests/multiple-media-types-golden-record/ subdirectory.

To maintain backward compatibility and minimize impact on existing callers, unexpected response content types raise the existingUnexpectedStatus error, rather than introducing a new error class

This uses exact string matching to compare returned content types with the media types from the schema. This offers only a subset of the available OpenAPI functionality: this PR does not provide support for wildcards, case insensitivity, or parameters. To add proper range matching (wildcard) support, we'd need something like the logic inpython-mimeparse

Uncovered diff lines:

  1. openapi_python_client/parser/openapi.py:204: This is a "belt-and-suspenders" check to avoid accessing an optional field if it is null. However, responses.py will not actually populate anyMediaType instances with a nullprop.
formedia_typeinresponse.content:ifnotmedia_type.prop:# pragma: no covercontinueendpoint.relative_imports|=media_type.prop.get_lazy_imports(prefix=models_relative_prefix)endpoint.relative_imports|=media_type.prop.get_imports(prefix=models_relative_prefix)endpoint.responses.append(response)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@nkrishnaswami

[8]ページ先頭

©2009-2025 Movatter.jp