Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ How the specification maps onto Go:
- **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.
- **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
Expand Down
3 changes: 3 additions & 0 deletions README/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ How the specification maps onto Go:
- **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.
- **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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/MarkRosemaker/openapi-codegen
go 1.27

require (
github.com/MarkRosemaker/cassette v0.0.0-20261124170238-3b0b504cc01a
github.com/MarkRosemaker/cassette v0.0.0-20261125180804-407fe91b7b7d
github.com/MarkRosemaker/errpath v0.0.0-20261118230255-99e20cb3445a
github.com/MarkRosemaker/openapi v0.0.0-20261124050252-52a60c76de04
github.com/MarkRosemaker/openapi-compress v0.0.0-20261124050556-094155f0b064
github.com/MarkRosemaker/openapi-edit v0.0.0-20261124050336-02af6fa36ba9
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261124050336-684f3610d8d7
github.com/MarkRosemaker/ordmap v0.0.0-20261124050216-f3096eb875be
github.com/ettle/strcase v0.2.0
github.com/go-api-libs/api v0.0.0-20261115172114-130f6fc73195
github.com/go-api-libs/api v0.0.0-20261125182139-0f507257dcd7
github.com/spf13/afero v1.15.0
mvdan.cc/gofumpt v0.12.0
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE=
cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU=
github.com/MarkRosemaker/cassette v0.0.0-20261124170238-3b0b504cc01a h1:iMV+JecKObVuGDQw0YhgsChj9Q8JZXVAk0tsyw1vCq0=
github.com/MarkRosemaker/cassette v0.0.0-20261124170238-3b0b504cc01a/go.mod h1:mIy1SlNqKDRALYBqZGjj+MWPU9dASkyP1d1X+I1HP6k=
github.com/MarkRosemaker/cassette v0.0.0-20261125180804-407fe91b7b7d h1:QJ5PKBI67moq/DdVbA2yxn+TC+MKNAnGqA/KPaHp0TM=
github.com/MarkRosemaker/cassette v0.0.0-20261125180804-407fe91b7b7d/go.mod h1:mIy1SlNqKDRALYBqZGjj+MWPU9dASkyP1d1X+I1HP6k=
github.com/MarkRosemaker/errpath v0.0.0-20261118230255-99e20cb3445a h1:C7Oyg94gPC6/nfCR8ev9FqyxQb5d+GEpU4Oz+rGcoww=
github.com/MarkRosemaker/errpath v0.0.0-20261118230255-99e20cb3445a/go.mod h1:VnXpUlsS3n1gSToedcQl2FCARGoA16CyitbCanUIv+I=
github.com/MarkRosemaker/json2yaml v0.0.0-20261118230255-853c75cf2bf9 h1:NVTLiOVHTQ/PSq3ihG3kT/P1UqNjJiBHHCGbgNq2rP8=
Expand Down Expand Up @@ -30,8 +30,8 @@ github.com/MarkRosemaker/yaml2json v0.0.0-20261118230255-06c4fe76a5b8 h1:D4cujGs
github.com/MarkRosemaker/yaml2json v0.0.0-20261118230255-06c4fe76a5b8/go.mod h1:DxNA9SDFrzw+RHsnxjIxjUzHy0I4+3hZg7R13u3SBvE=
github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q=
github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A=
github.com/go-api-libs/api v0.0.0-20261115172114-130f6fc73195 h1:+QFVvV0eav8ZKBJiyJhjkp46SkuRg8C+RVUvm/D4/MQ=
github.com/go-api-libs/api v0.0.0-20261115172114-130f6fc73195/go.mod h1:4Ls/f+97MK0jpUbKa713C/itwrFlVvHwxt+CWLXdsr0=
github.com/go-api-libs/api v0.0.0-20261125182139-0f507257dcd7 h1:BMgkSz7tviqSK2Gg3ZQeyuMYgi4G33RK/UcqiozHfoE=
github.com/go-api-libs/api v0.0.0-20261125182139-0f507257dcd7/go.mod h1:dHyiZnevRGCtsIQZlq9LKKJyNQGizbsac/IEG7/qeSo=
github.com/go-api-libs/types v0.0.0-20261118230255-0e16a3d7de5d h1:WJpz1GJEMd/4zdJ1ElOXCSswW8BQzsWGRz27Y1TivrI=
github.com/go-api-libs/types v0.0.0-20261118230255-0e16a3d7de5d/go.mod h1:z0z6qkZc45AvoRnluq7PkVSlSSF25sT0diJ+vrubYfA=
github.com/go-quicktest/qt v1.102.0 h1:HSQxCeh5YZH3EL3W39ixjtyaEhcWSXQHtHnMBzSs474=
Expand Down
14 changes: 14 additions & 0 deletions ir/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,20 @@ 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 {
Expand Down
17 changes: 17 additions & 0 deletions ir/ir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,20 @@ 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)
}
}
3 changes: 3 additions & 0 deletions render/templates/client.gen.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ 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}} },
Expand Down
1 change: 1 addition & 0 deletions testdata/apikey/pkg/apikey/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions testdata/auth/pkg/auth/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions testdata/debug/pkg/debug/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions testdata/golden/pkg/golden/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/MarkRosemaker/cassette/replay.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/go-api-libs/api/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions vendor/github.com/go-api-libs/api/apitest/replay.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading