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 #4579
  • Loading branch information
rledisez committed Apr 29, 2024
1 parent 5f13655 commit 8c714c8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,11 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
{{/isHeaderParam}}
{{#isBodyParam}}
{{paramName}}Param := {{dataType}}{}
{{#vars}}
{{#defaultValue}}
{{paramName}}Param.{{^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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions samples/server/petstore/go-api-server/go/api_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions samples/server/petstore/go-chi-server/go/api_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c714c8

Please sign in to comment.