Skip to content

Commit df410c5

Browse files
committed
Invert header & body conditions so Header override works on both functional options and direct call
1 parent 3b33253 commit df410c5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

internal/build/cmd/generate/commands/gensource/generator.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ import (
3030
)
3131

3232
// Generator represents the "gensource" generator.
33-
//
3433
type Generator struct {
3534
b bytes.Buffer
3635

3736
Endpoint *Endpoint
3837
}
3938

4039
// Output returns the generator output.
41-
//
4240
func (g *Generator) Output() (io.Reader, error) {
4341
g.genHeader()
4442
g.genConstructor()
@@ -52,7 +50,6 @@ func (g *Generator) Output() (io.Reader, error) {
5250
}
5351

5452
// OutputFormatted returns a formatted generator output.
55-
//
5653
func (g *Generator) OutputFormatted() (io.Reader, error) {
5754
out, err := g.Output()
5855
if err != nil {
@@ -794,12 +791,6 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
794791
req.URL.RawQuery = q.Encode()
795792
}` + "\n\n")
796793

797-
if g.Endpoint.Body != nil {
798-
g.w(`if r.Body != nil && req.Header.Get(headerContentType) == "" {
799-
req.Header[headerContentType] = headerContentTypeJSON
800-
}` + "\n\n")
801-
}
802-
803794
g.w(`if len(r.Header) > 0 {
804795
if len(req.Header) == 0 {
805796
req.Header = r.Header
@@ -812,6 +803,12 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(ctx context.Context,
812803
}
813804
}` + "\n\n")
814805

806+
if g.Endpoint.Body != nil {
807+
g.w(`if r.Body != nil && req.Header.Get(headerContentType) == "" {
808+
req.Header[headerContentType] = headerContentTypeJSON
809+
}` + "\n\n")
810+
}
811+
815812
g.w(`if ctx != nil {
816813
req = req.WithContext(ctx)
817814
}` + "\n\n")

0 commit comments

Comments
 (0)