Skip to content

feat(client): Add ContentType() to ClientWithResponses responses#2173

Merged
mromaszewicz merged 3 commits into
oapi-codegen:mainfrom
CJourneaux:add-content-type-method
Apr 23, 2026
Merged

feat(client): Add ContentType() to ClientWithResponses responses#2173
mromaszewicz merged 3 commits into
oapi-codegen:mainfrom
CJourneaux:add-content-type-method

Conversation

@CJourneaux

@CJourneaux CJourneaux commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Fix for issue #2149.
Similar approach as taken in #1780.

@CJourneaux CJourneaux force-pushed the add-content-type-method branch from d623014 to e843856 Compare December 3, 2025 20:02
@CJourneaux CJourneaux marked this pull request as ready for review December 3, 2025 20:08
@CJourneaux CJourneaux requested a review from a team as a code owner December 3, 2025 20:08
@CJourneaux CJourneaux force-pushed the add-content-type-method branch from e843856 to 1905682 Compare December 3, 2025 20:12
@CJourneaux CJourneaux force-pushed the add-content-type-method branch from 1905682 to b72509c Compare December 3, 2025 20:14
@mromaszewicz mromaszewicz added enhancement New feature or request labels Apr 23, 2026
mromaszewicz and others added 2 commits April 23, 2026 14:45
Flip the ContentType() method on ClientWithResponses response types
from opt-in to default-on. The output option is renamed from
`client-response-content-type-function` (enable) to
`skip-client-response-content-type` (disable).

- pkg/codegen/configuration.go: field renamed to SkipClientResponseContentType
- configuration-schema.json: key renamed, description inverted
- pkg/codegen/templates/client-with-responses.tmpl: condition inverted
- internal/test/issues/issue-240-2149: removed; issue240 restored from
  upstream/main (original issue 240 bytes-function test is still present
  and ContentType() is now exercised by every generated client)

Regenerated all affected .gen.go files. The resulting diff across
generated code is large but purely additive: each response type gains a
new ContentType() method; no existing declarations are modified or
removed, so downstream users cannot be broken by this change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mromaszewicz

Copy link
Copy Markdown
Member

@greptileai

@greptile-apps

greptile-apps Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a ContentType() convenience method to all ClientWithResponses response types that returns the Content-Type response header, generated by default with an opt-out via the new skip-client-response-content-type config flag. The implementation (template, Go struct, JSON schema) is internally consistent and the generated code is correct.

Confidence Score: 4/5

Safe to merge with minor concerns; the implementation is correct but the opt-out default is inconsistent with Bytes() and there is no dedicated test.

All findings are P2 — design inconsistency between opt-out ContentType() and opt-in Bytes(), and missing integration test. No correctness defects were found. The design inconsistency has a concrete risk (duplicate-method compilation failure for users who have hand-written a ContentType() method on a generated type), warranting a slight reduction from 5/5.

pkg/codegen/templates/client-with-responses.tmpl — the opt-out design choice should be confirmed intentional, and a dedicated test should be added.

Important Files Changed

Filename Overview
pkg/codegen/templates/client-with-responses.tmpl Adds ContentType() method to all response types, generated by default (opt-out), inconsistent with opt-in Bytes() method; no dedicated test exists for the new method or its skip option
pkg/codegen/configuration.go Adds SkipClientResponseContentType bool to OutputOptions with correct YAML tag; field name, YAML tag, and JSON schema are all consistent
configuration-schema.json Adds skip-client-response-content-type boolean field with accurate description; schema entry is correct and consistent with the Go struct

Reviews (1): Last reviewed commit: "Make ContentType() default on" | Re-trigger Greptile

@mromaszewicz mromaszewicz merged commit c6d77f2 into oapi-codegen:main Apr 23, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants