Skip to content

Commit 4368776

Browse files
[api] No body for 204 responses (#1891)
1 parent 39c88b5 commit 4368776

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎cmds/dummy-oauth/api/common.gen.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ type Authorizer interface {
4545
// --- Utilities ---
4646

4747
func WriteJSON(w http.ResponseWriter, code int, obj interface{}) {
48+
// A 204 response has no body
49+
if code == http.StatusNoContent {
50+
w.WriteHeader(code)
51+
return
52+
}
4853
w.Header().Set("Content-Type", "application/json; charset=utf-8")
4954
w.WriteHeader(code)
5055
if err := json.NewEncoder(w).Encode(obj); err != nil {

‎interfaces/openapi-to-go-server/example/api/common.gen.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ type Authorizer interface {
4545
// --- Utilities ---
4646

4747
func WriteJSON(w http.ResponseWriter, code int, obj interface{}) {
48+
// A 204 response has no body
49+
if code == http.StatusNoContent {
50+
w.WriteHeader(code)
51+
return
52+
}
4853
w.Header().Set("Content-Type", "application/json; charset=utf-8")
4954
w.WriteHeader(code)
5055
if err := json.NewEncoder(w).Encode(obj); err != nil {

‎interfaces/openapi-to-go-server/templates/common.go.template‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ type Authorizer interface {
4242
// --- Utilities ---
4343

4444
func WriteJSON(w http.ResponseWriter, code int, obj interface{}) {
45+
// A 204 response has no body
46+
if code == http.StatusNoContent {
47+
w.WriteHeader(code)
48+
return
49+
}
4550
w.Header().Set("Content-Type", "application/json; charset=utf-8")
4651
w.WriteHeader(code)
4752
if err := json.NewEncoder(w).Encode(obj); err != nil {

‎pkg/api/common.gen.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ type Authorizer interface {
4545
// --- Utilities ---
4646

4747
func WriteJSON(w http.ResponseWriter, code int, obj interface{}) {
48+
// A 204 response has no body
49+
if code == http.StatusNoContent {
50+
w.WriteHeader(code)
51+
return
52+
}
4853
w.Header().Set("Content-Type", "application/json; charset=utf-8")
4954
w.WriteHeader(code)
5055
if err := json.NewEncoder(w).Encode(obj); err != nil {

0 commit comments

Comments
 (0)