Title: feat: Support responses with multiple media types in `content` by nkrishnaswami · Pull Request #1293 · openapi-generators/openapi-python-client · GitHub
Open Graph Title: feat: Support responses with multiple media types in `content` by nkrishnaswami · Pull Request #1293 · openapi-generators/openapi-python-client
X Title: feat: Support responses with multiple media types in `content` by nkrishnaswami · Pull Request #1293 · openapi-generators/openapi-python-client
Description: This PR modifies openapi-python-client to recognize multiple media types in OpenAPI response objects and to differentially parse HTTP responses based on their Content-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 the end_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 existing UnexpectedStatus 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 in python-mimeparse Uncovered diff lines: 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 any MediaType instances with a null prop. for media_type in response.content: if not media_type.prop: # pragma: no cover continue endpoint.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)
Open Graph Description: This PR modifies openapi-python-client to recognize multiple media types in OpenAPI response objects and to differentially parse HTTP responses based on their Content-Type header values. (Today, it...
X Description: This PR modifies openapi-python-client to recognize multiple media types in OpenAPI response objects and to differentially parse HTTP responses based on their Content-Type header values. (Today, it...
Opengraph URL: https://github.com/openapi-generators/openapi-python-client/pull/1293
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:fcf5a702-195a-dfc4-86bf-0c4f911d4fa7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E818:3B7141:2EB28D:40968C:6980ED27 |
| html-safe-nonce | e29d48615e5678bf22768b8a97366a5373258da27a1ae2b0b7ffd11769fc6ed7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODE4OjNCNzE0MToyRUIyOEQ6NDA5NjhDOjY5ODBFRDI3IiwidmlzaXRvcl9pZCI6Ijc3Mjk0MTk0MTQ3NzIxODIzMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0596ecdaed6ba26ba93c333bec4ceb0685ca73194781bfb4bc079f3018fbfa88 |
| hovercard-subject-tag | pull_request:2714138045 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/openapi-generators/openapi-python-client/pull/1293/files |
| twitter:image | https://avatars.githubusercontent.com/u/5997156?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/5997156?s=400&v=4 |
| og:image:alt | This PR modifies openapi-python-client to recognize multiple media types in OpenAPI response objects and to differentially parse HTTP responses based on their Content-Type header values. (Today, it... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cdeab60e665cf158f971f0b4329c9f8b2796cdbc03304a1f04aaa07e81bd107f |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/openapi-generators/openapi-python-client git https://github.com/openapi-generators/openapi-python-client.git |
| octolytics-dimension-user_id | 84925606 |
| octolytics-dimension-user_login | openapi-generators |
| octolytics-dimension-repository_id | 240776275 |
| octolytics-dimension-repository_nwo | openapi-generators/openapi-python-client |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 240776275 |
| octolytics-dimension-repository_network_root_nwo | openapi-generators/openapi-python-client |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | abc7f12a1279d78087ac998532a2819581bc3ceb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width