Skip to content

Commit

Permalink
[go-server] fix addResponseHeaders tpl option typo (OpenAPITools#9814)
Browse files Browse the repository at this point in the history
According to the [documentation](https://openapi-generator.tech/docs/generators/go-server) the go-server generator should support an `addResponseHeaders` option but a template uses an `addResponseHeader` option in some places which this PR fixes.

Closes OpenAPITools#9795

Signed-off-by: Max Goltzsche <[email protected]>
  • Loading branch information
mgoltzsche authored Jun 21, 2021
1 parent 939b5f6 commit 2e85ccd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewRouter(routers ...Router) {{#routers}}{{#mux}}*mux.Router{{/mux}}{{#chi}

// EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
func EncodeJSONResponse(i interface{}, status *int,{{#addResponseHeaders}} headers map[string][]string,{{/addResponseHeaders}} w http.ResponseWriter) error {
{{#addResponseHeader}}
{{#addResponseHeaders}}
wHeader := w.Header()
if headers != nil {
for key, values := range headers {
Expand All @@ -98,10 +98,10 @@ func EncodeJSONResponse(i interface{}, status *int,{{#addResponseHeaders}} heade
}
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8")
{{/addResponseHeader}}
{{^addResponseHeader}}
{{/addResponseHeaders}}
{{^addResponseHeaders}}
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
{{/addResponseHeader}}
{{/addResponseHeaders}}
if status != nil {
w.WriteHeader(*status)
} else {
Expand Down
10 changes: 9 additions & 1 deletion samples/server/petstore/go-api-server/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ func NewRouter(routers ...Router) *mux.Router {

// EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
wHeader := w.Header()
if headers != nil {
for key, values := range headers {
for _, value := range values {
wHeader.Add(key, value)
}
}
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8")
if status != nil {
w.WriteHeader(*status)
} else {
Expand Down
10 changes: 9 additions & 1 deletion samples/server/petstore/go-chi-server/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ func NewRouter(routers ...Router) chi.Router {

// EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code
func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string, w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
wHeader := w.Header()
if headers != nil {
for key, values := range headers {
for _, value := range values {
wHeader.Add(key, value)
}
}
}
wHeader.Set("Content-Type", "application/json; charset=UTF-8")
if status != nil {
w.WriteHeader(*status)
} else {
Expand Down

0 comments on commit 2e85ccd

Please sign in to comment.