From 92bd7d330fb73e5c4be9816124b2a9759df0fa0b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:26:37 +0000 Subject: [PATCH] feat: stop sending Accept Clients sent every media type their operation's responses declare, an error page's text/html too, which asked for what no caller wants and made every new response type a mismatch with the recording that taught it. Go's HTTP client sends no Accept, and the APIs these clients call answer the same without one, so the generated request no longer sets it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y --- README.md | 6 ++---- README/features.md | 6 ++---- ir/ir.go | 14 -------------- ir/ir_test.go | 17 ----------------- render/templates/client.gen.go.tmpl | 3 --- testdata/apikey/pkg/apikey/client.gen.go | 1 - testdata/auth/pkg/auth/client.gen.go | 2 -- testdata/debug/pkg/debug/client.gen.go | 5 ----- testdata/golden/pkg/golden/client.gen.go | 19 ------------------- 9 files changed, 4 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index ee904586..086ca403 100644 --- a/README.md +++ b/README.md @@ -210,10 +210,8 @@ How the specification maps onto Go: like. A query parameter of the format is sent and read the same way. - **Ignored header parameters** — a header parameter named `Accept`, `Content-Type` or `Authorization` is ignored, as OpenAPI 3.1 says: the client - sends the request body's media type and the credential of the security scheme. -- **Accept** — each request sends the media types its operation's responses - declare, each once, such as `application/json`, or none where no response has - a body. + sends the request body's media type and the credential of the security scheme, + and no Accept, as Go's HTTP client does not. - **Unknown formats** — a format the generator does not know, which OpenAPI 3.1 allows, gives the plain type: an `int`, a `float64` or a `string`. - **Empty dates** — an empty string, which an API may send for a date or diff --git a/README/features.md b/README/features.md index 51551144..c4b59416 100644 --- a/README/features.md +++ b/README/features.md @@ -165,10 +165,8 @@ How the specification maps onto Go: like. A query parameter of the format is sent and read the same way. - **Ignored header parameters** — a header parameter named `Accept`, `Content-Type` or `Authorization` is ignored, as OpenAPI 3.1 says: the client - sends the request body's media type and the credential of the security scheme. -- **Accept** — each request sends the media types its operation's responses - declare, each once, such as `application/json`, or none where no response has - a body. + sends the request body's media type and the credential of the security scheme, + and no Accept, as Go's HTTP client does not. - **Unknown formats** — a format the generator does not know, which OpenAPI 3.1 allows, gives the plain type: an `int`, a `float64` or a `string`. - **Empty dates** — an empty string, which an API may send for a date or diff --git a/ir/ir.go b/ir/ir.go index a8a196e4..3349c0b8 100644 --- a/ir/ir.go +++ b/ir/ir.go @@ -666,20 +666,6 @@ type Response struct { BodyDescription string `json:"bodyDescription,omitzero"` } -// Accept is the Accept header the operation sends: the media types its responses declare, in their order, or "" where -// none has a body. -func (op Operation) Accept() string { - var types []string - - for _, r := range op.Responses { - if r.ContentType != "" && !slices.Contains(types, r.ContentType) { - types = append(types, r.ContentType) - } - } - - return strings.Join(types, ", ") -} - // SuccessDescription is what the specification says beside the reference to the schema of the body the operation // returns, if anything. func (op Operation) SuccessDescription() string { diff --git a/ir/ir_test.go b/ir/ir_test.go index b7701be0..50dee4dc 100644 --- a/ir/ir_test.go +++ b/ir/ir_test.go @@ -30,20 +30,3 @@ func TestZeroVal(t *testing.T) { } } } - -// An operation accepts the media types its responses declare, each once, in their order; one without a body adds none. -func TestOperation_Accept(t *testing.T) { - op := Operation{Responses: Responses{ - {StatusCode: "200", ContentType: "application/json"}, - {StatusCode: "204"}, - {StatusCode: "400", ContentType: "application/problem+json"}, - {StatusCode: "500", ContentType: "application/json"}, - }} - if got, want := op.Accept(), "application/json, application/problem+json"; got != want { - t.Errorf("Accept() = %q, want %q", got, want) - } - - if got := (Operation{Responses: Responses{{StatusCode: "204"}}}).Accept(); got != "" { - t.Errorf("no body: Accept() = %q, want none", got) - } -} diff --git a/render/templates/client.gen.go.tmpl b/render/templates/client.gen.go.tmpl index b9b36401..1efe28bd 100644 --- a/render/templates/client.gen.go.tmpl +++ b/render/templates/client.gen.go.tmpl @@ -332,9 +332,6 @@ func (c *Client) {{.Name}}(ctx context.Context{{range .PathParams}}, {{.GoName}} {{ range .FixedHeaders -}} "{{ .JSONName }}": []string{ {{- .Value -}} }, {{ end -}} - {{ with .Accept -}} - "Accept": []string{ {{- printf "%q" . -}} }, - {{ end -}} "User-Agent": []string{c.userAgent}, {{ if and .RequestBody .RequestBody.Required -}} "Content-Type": []string{ {{printf "%q" .RequestBody.ContentType}} }, diff --git a/testdata/apikey/pkg/apikey/client.gen.go b/testdata/apikey/pkg/apikey/client.gen.go index 25fcaab6..4f434e26 100644 --- a/testdata/apikey/pkg/apikey/client.gen.go +++ b/testdata/apikey/pkg/apikey/client.gen.go @@ -118,7 +118,6 @@ func (c *Client) GetQuote(ctx context.Context) (*Quote, error) { u := c.baseURL.JoinPath("quote") req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, diff --git a/testdata/auth/pkg/auth/client.gen.go b/testdata/auth/pkg/auth/client.gen.go index ced33dbf..7250bff8 100644 --- a/testdata/auth/pkg/auth/client.gen.go +++ b/testdata/auth/pkg/auth/client.gen.go @@ -141,7 +141,6 @@ func (c *Client) ListItems(ctx context.Context) ([]string, error) { "Authorization": []string{c.bearer}, "X-Api-Key": []string{c.apiKey}, "X-Client": []string{c.client}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -191,7 +190,6 @@ func (c *Client) GetFeed(ctx context.Context) ([]string, error) { "Authorization": []string{c.bearer}, "X-Api-Key": []string{c.apiKey}, "X-Client": []string{c.client}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, diff --git a/testdata/debug/pkg/debug/client.gen.go b/testdata/debug/pkg/debug/client.gen.go index bd414c88..7136dd51 100644 --- a/testdata/debug/pkg/debug/client.gen.go +++ b/testdata/debug/pkg/debug/client.gen.go @@ -121,7 +121,6 @@ func (c *Client) GetItem(ctx context.Context) (*Item, error) { req := (&http.Request{ Header: http.Header{ "Authorization": []string{c.bearer}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -187,7 +186,6 @@ func (c *Client) ListItems(ctx context.Context) (Items, error) { req := (&http.Request{ Header: http.Header{ "Authorization": []string{c.bearer}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -238,7 +236,6 @@ func (c *Client) GetBlock(ctx context.Context) (*Block, error) { req := (&http.Request{ Header: http.Header{ "Authorization": []string{c.bearer}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -289,7 +286,6 @@ func (c *Client) GetPet(ctx context.Context) (*Pet, error) { req := (&http.Request{ Header: http.Header{ "Authorization": []string{c.bearer}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -342,7 +338,6 @@ func (c *Client) Ping(ctx context.Context) error { req := (&http.Request{ Header: http.Header{ "Authorization": []string{c.bearer}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, diff --git a/testdata/golden/pkg/golden/client.gen.go b/testdata/golden/pkg/golden/client.gen.go index f79781a0..00a27c48 100644 --- a/testdata/golden/pkg/golden/client.gen.go +++ b/testdata/golden/pkg/golden/client.gen.go @@ -86,7 +86,6 @@ func (c *Client) GetPage(ctx context.Context, id string) (*Page, error) { u := c.baseURL.JoinPath("pages", escapePathSegment(id)) req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -158,7 +157,6 @@ func (c *Client) Search(ctx context.Context, body PropertyFilter) (PageOrPartial pr, pw := io.Pipe() req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, "Content-Type": []string{"application/json"}, }, @@ -207,7 +205,6 @@ func (c *Client) GetTrial(ctx context.Context, id string) (*Trial, error) { u := c.baseURL.JoinPath("trials", escapePathSegment(id)) req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -249,7 +246,6 @@ func (c *Client) UpdateUser(ctx context.Context, id string, body User) (*User, e pr, pw := io.Pipe() req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, "Content-Type": []string{"application/json"}, }, @@ -298,7 +294,6 @@ func (c *Client) PatchUser(ctx context.Context, id string, body *User) error { u := c.baseURL.JoinPath("users", escapePathSegment(id)) req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -363,7 +358,6 @@ func (c *Client) QueryEntries(ctx context.Context, body QueryEntries) (*QueryEnt pr, pw := io.Pipe() req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, "Content-Type": []string{"application/json"}, }, @@ -444,7 +438,6 @@ func (c *Client) ListEntries(ctx context.Context, params *ListEntriesParams) (*L req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -514,7 +507,6 @@ func (c *Client) CreateEntry(ctx context.Context, body Entry) (*Entry, error) { pr, pw := io.Pipe() req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, "Content-Type": []string{"application/json"}, }, @@ -563,7 +555,6 @@ func (c *Client) GetValue(ctx context.Context, id string) (*Value, error) { u := c.baseURL.JoinPath("values", escapePathSegment(id)) req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -604,7 +595,6 @@ func (c *Client) GetBlock(ctx context.Context, id string) (*Block, error) { u := c.baseURL.JoinPath("blocks", escapePathSegment(id)) req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -646,7 +636,6 @@ func (c *Client) CreateDatabase(ctx context.Context, body CreateDatabaseParent) pr, pw := io.Pipe() req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, "Content-Type": []string{"application/json"}, }, @@ -693,7 +682,6 @@ func (c *Client) GetProperty(ctx context.Context, id string) (*NestedValue, erro u := c.baseURL.JoinPath("properties", escapePathSegment(id)) req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -778,7 +766,6 @@ func (c *Client) ListReports(ctx context.Context, params ListReportsParams) (Rep req := (&http.Request{ Header: http.Header{ "X-Version": []string{params.XVersion}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -821,7 +808,6 @@ func (c *Client) ListPeople(ctx context.Context) (*ListPeopleOk, error) { u := c.baseURL.JoinPath("people") req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -863,7 +849,6 @@ func (c *Client) CreateSchedule(ctx context.Context, body Schedule) (*CreateSche pr, pw := io.Pipe() req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, "Content-Type": []string{"application/json"}, }, @@ -925,7 +910,6 @@ func (c *Client) DownloadReport(ctx context.Context, format ScheduleFormat) (io. u := c.baseURL.JoinPath("reports", escapePathSegment(string(format))) req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/pdf"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -973,7 +957,6 @@ func (c *Client) DeleteSchedule(ctx context.Context, id string) error { req := (&http.Request{ Header: http.Header{ "Api-Version": []string{"2"}, - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -1082,7 +1065,6 @@ func (c *Client) GetRanges(ctx context.Context) ([]string, error) { u := c.baseURL.JoinPath("ranges") req := (&http.Request{ Header: http.Header{ - "Accept": []string{"application/json"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host, @@ -1128,7 +1110,6 @@ func (c *Client) GetStatus(ctx context.Context) ([]byte, error) { u := c.baseURL.JoinPath("status") req := (&http.Request{ Header: http.Header{ - "Accept": []string{"text/plain"}, "User-Agent": []string{c.userAgent}, }, Host: u.Host,