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
2 changes: 2 additions & 0 deletions http/codegen/server_encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func TestEncode(t *testing.T) {
{"empty-server-response", testdata.EmptyServerResponseDSL, testdata.EmptyServerResponseEncodeCode},
{"empty-server-response-with-tags", testdata.EmptyServerResponseWithTagsDSL, testdata.EmptyServerResponseWithTagsEncodeCode},

{"skip-response-body-encode-decode", testdata.ResponseEncoderSkipResponseBodyEncodeDecodeDSL, testdata.ResponseEncoderSkipResponseBodyEncodeDecodeCode},

{"result-with-custom-pkg-type", testdata.ResultWithCustomPkgTypeDSL, testdata.ResultWithCustomPkgTypeEncodeCode},
{"result-with-embedded-custom-pkg-type", testdata.EmbeddedCustomPkgTypeDSL, testdata.ResultWithEmbeddedCustomPkgTypeEncodeCode},
}
Expand Down
4 changes: 3 additions & 1 deletion http/codegen/templates/response_encoder.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func {{ .ResponseEncoder }}(encoder func(context.Context, http.ResponseWriter) g
{{- end }}
{{- else }}
{{- with (index .Result.Responses 0) }}
w.WriteHeader({{ .StatusCode }})
{{- if not $.Method.SkipResponseBodyEncodeDecode }}
w.WriteHeader({{ .StatusCode }})
{{- end }}
return nil
{{- end }}
{{- end }}
Expand Down
10 changes: 10 additions & 0 deletions http/codegen/testdata/result_encode_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,16 @@ func EncodeMethodEmptyServerResponseWithTagsResponse(encoder func(context.Contex
}
`

var ResponseEncoderSkipResponseBodyEncodeDecodeCode = `// EncodeMethodResponseEncoderSkipResponse returns an encoder for responses
// returned by the ServiceResponseEncoderSkip MethodResponseEncoderSkip
// endpoint.
func EncodeMethodResponseEncoderSkipResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error {
return func(ctx context.Context, w http.ResponseWriter, v any) error {
return nil
}
}
`

var ResultWithCustomPkgTypeEncodeCode = `// EncodeMethodResultWithCustomPkgTypeDSLResponse returns an encoder for
// responses returned by the ServiceResultWithCustomPkgTypeDSL
// MethodResultWithCustomPkgTypeDSL endpoint.
Expand Down
12 changes: 12 additions & 0 deletions http/codegen/testdata/server_dsls.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,15 @@ var ServerSkipResponseBodyEncodeDecodeDSL = func() {
})
})
}

var ResponseEncoderSkipResponseBodyEncodeDecodeDSL = func() {
Service("ServiceResponseEncoderSkip", func() {
Method("MethodResponseEncoderSkip", func() {
HTTP(func() {
GET("/")
SkipResponseBodyEncodeDecode()
Response(StatusOK)
})
})
})
}
Loading