Skip to content

Commit

Permalink
[go-server] Set default values in object properties
Browse files Browse the repository at this point in the history
When a default value is set for an object property, ensure it is set
into the struct before decoding the JSON body.

Fix OpenAPITools#4579
  • Loading branch information
rledisez committed Apr 29, 2024
1 parent 5f13655 commit 2aa455b
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,25 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
{{paramName}}Param := r.Header.Get("{{baseName}}")
{{/isHeaderParam}}
{{#isBodyParam}}
{{paramName}}Param := {{dataType}}{}
{{paramName}}Param := {{dataType}}{
{{#vars}}
{{#defaultValue}}
{{^isArray}}
{{#isBoolean}}
{{name}}: {{{.}}},
{{/isBoolean}}
{{#isNumeric}}
{{name}}: {{{.}}},
{{/isNumeric}}
{{^isBoolean}}
{{^isNumeric}}
{{name}}: "{{{.}}}",
{{/isNumeric}}
{{/isBoolean}}
{{/isArray}}
{{/defaultValue}}
{{/vars}}
}
d := json.NewDecoder(r.Body)
{{^isAdditionalPropertiesTrue}}
d.DisallowUnknownFields()
Expand Down

0 comments on commit 2aa455b

Please sign in to comment.