Skip to content

Unify emitter/consumer mediatype filter#2420

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-2389
Jun 21, 2026
Merged

Unify emitter/consumer mediatype filter#2420
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:fix/issue-2389

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Closes: #2389

A response component exposing the same schema under multiple content types (e.g. application/json + application/xml) generated client wrapper fields typed as undefined per-content-type names (*ErrorResponseApplicationJSON / *ErrorResponseApplicationXML), breaking compilation.

The type declarer (GenerateTypesForResponses) and the wrapper-field consumer (GetResponseTypeDefinitions) independently decided when to append a media-type suffix to a response type name, and the two had drifted apart: the consumer suffixed for every supported content type while the declarer only declared a suffixed name when a response carried more than one JSON content type.

Both now route that decision through a single responseMediaTypeSuffix helper, so they cannot disagree. Non-JSON content types reuse the base type name, and JSON entries are suffixed only when a response has more than one JSON content type. The now-unused isMediaTypeSupported helper is removed, and a regression test is added under internal/test/issues/issue-2389.

@mromaszewicz
mromaszewicz requested a review from a team as a code owner June 21, 2026 01:16
@mromaszewicz mromaszewicz added regression bug Something isn't working labels Jun 21, 2026
@greptile-apps

greptile-apps Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR aligns response media-type naming between generated component types and client response wrappers. It changes:

  • Adds a shared helper for response media-type suffix decisions.
  • Uses the helper when declaring component response types.
  • Uses the same helper when selecting client wrapper field types.
  • Keeps non-JSON component response fields tied to their own schema-derived types.
  • Adds regression coverage for JSON/XML response components from issue 2389.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
pkg/codegen/operations.go Adds the shared suffix helper and applies JSON-only component response type reuse in client wrapper fields.
pkg/codegen/codegen.go Updates component response type declaration naming to use the shared media-type suffix decision.
internal/test/issues/issue-2389/issue_2389_test.go Adds compile-time regression checks for shared and distinct response component media schemas.

Reviews (2): Last reviewed commit: "Unify emitter/consumer mediatype filter" | Re-trigger Greptile

Comment thread pkg/codegen/operations.go
Closes: oapi-codegen#2389

A response component exposing the same schema under multiple content types
(e.g. application/json + application/xml) generated client wrapper fields
typed as undefined per-content-type names (*ErrorResponseApplicationJSON /
*ErrorResponseApplicationXML), breaking compilation.

The type declarer (GenerateTypesForResponses) and the wrapper-field consumer
(GetResponseTypeDefinitions) independently decided when to append a media-type
suffix to a response type name, and the two had drifted apart: the consumer
suffixed for every supported content type while the declarer only declared a
suffixed name when a response carried more than one JSON content type.

Both now route that decision through a single responseMediaTypeSuffix helper,
so they cannot disagree. Non-JSON content types reuse the base type name, and
JSON entries are suffixed only when a response has more than one JSON content
type. The now-unused isMediaTypeSupported helper is removed, and a regression
test is added under internal/test/issues/issue-2389.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mromaszewicz
mromaszewicz merged commit 4fc9db2 into oapi-codegen:main Jun 21, 2026
14 checks passed
lwc pushed a commit to lwc/oapi-codegen that referenced this pull request Jun 23, 2026
Closes: oapi-codegen#2389

A response component exposing the same schema under multiple content types
(e.g. application/json + application/xml) generated client wrapper fields
typed as undefined per-content-type names (*ErrorResponseApplicationJSON /
*ErrorResponseApplicationXML), breaking compilation.

The type declarer (GenerateTypesForResponses) and the wrapper-field consumer
(GetResponseTypeDefinitions) independently decided when to append a media-type
suffix to a response type name, and the two had drifted apart: the consumer
suffixed for every supported content type while the declarer only declared a
suffixed name when a response carried more than one JSON content type.

Both now route that decision through a single responseMediaTypeSuffix helper,
so they cannot disagree. Non-JSON content types reuse the base type name, and
JSON entries are suffixed only when a response has more than one JSON content
type. The now-unused isMediaTypeSupported helper is removed, and a regression
test is added under internal/test/issues/issue-2389.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Response component with multiple content types generates undefined per-content-type type names

1 participant