Skip to content

Commit 444e989

Browse files
Merge pull request #6 from SpectraLogic/fix-optional-header-params
Fix Optional Header Parameters
2 parents f1e02ca + 31b6b30 commit 444e989

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

modules/openapi-generator/src/main/resources/go-server/controller-api.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
543543
{{paramName}}Param := getPointer({{paramName}}ParamValues[0])
544544
{{/required}}
545545
{{^required}}
546-
{{paramName}}Param := getPointerOrNilIfEmpty(r.Header.Get("{{baseName}}"))
546+
var {{paramName}}Param *string
547+
if len({{paramName}}ParamValues) != 0 {
548+
{{paramName}}Param = getPointer({{paramName}}ParamValues[0])
549+
}
547550
{{/required}}
548551
{{/isArray}}
549552
{{/isHeaderParam}}

samples/openapi3/server/petstore/go/go-petstore/go/api_pet.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) {
131131
return
132132
}
133133
apiKeyParamValues := r.Header.Values("api_key")
134-
apiKeyParam := getPointerOrNilIfEmpty(r.Header.Get("api_key"))
134+
var apiKeyParam *string
135+
if len(apiKeyParamValues) != 0 {
136+
apiKeyParam = getPointer(apiKeyParamValues[0])
137+
}
135138
result, err := c.service.DeletePet(r.Context(), *petIdParam, apiKeyParam)
136139
// If an error occurred, encode the error with the status code
137140
if err != nil {

samples/server/petstore/go-api-server/go/api_pet.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) {
157157
return
158158
}
159159
apiKeyParamValues := r.Header.Values("api_key")
160-
apiKeyParam := getPointerOrNilIfEmpty(r.Header.Get("api_key"))
160+
var apiKeyParam *string
161+
if len(apiKeyParamValues) != 0 {
162+
apiKeyParam = getPointer(apiKeyParamValues[0])
163+
}
161164
result, err := c.service.DeletePet(r.Context(), *petIdParam, apiKeyParam)
162165
// If an error occurred, encode the error with the status code
163166
if err != nil {

samples/server/petstore/go-chi-server/go/api_pet.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ func (c *PetAPIController) DeletePet(w http.ResponseWriter, r *http.Request) {
156156
return
157157
}
158158
apiKeyParamValues := r.Header.Values("api_key")
159-
apiKeyParam := getPointerOrNilIfEmpty(r.Header.Get("api_key"))
159+
var apiKeyParam *string
160+
if len(apiKeyParamValues) != 0 {
161+
apiKeyParam = getPointer(apiKeyParamValues[0])
162+
}
160163
result, err := c.service.DeletePet(r.Context(), *petIdParam, apiKeyParam)
161164
// If an error occurred, encode the error with the status code
162165
if err != nil {

0 commit comments

Comments
 (0)