Skip to content

Commit c92893d

Browse files
committed
[go-server] Set default values in object properties
When a default value is set for an object property, ensure it is set into the struct before decoding the JSON body. Fix #4579
1 parent 5f13655 commit c92893d

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
588588
{{/isHeaderParam}}
589589
{{#isBodyParam}}
590590
{{paramName}}Param := {{dataType}}{}
591+
{{#vars}}
592+
{{#defaultValue}}
593+
{{paramName}}Param.{{^isArray}}{{#isBoolean}}{{name}} = {{{.}}}{{/isBoolean}}{{#isNumeric}}{{name}} = {{{.}}}{{/isNumeric}}{{^isBoolean}}{{^isNumeric}}{{name}} = "{{{.}}}"{{/isNumeric}}{{/isBoolean}}{{/isArray}}
594+
{{/defaultValue}}
595+
{{/vars}}
591596
d := json.NewDecoder(r.Body)
592597
{{^isAdditionalPropertiesTrue}}
593598
d.DisallowUnknownFields()

samples/documentation/html2/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9512,19 +9512,19 @@ <h3 id="examples-User-loginUser-title-200"></h3>
95129512
<th>Description</th>
95139513
</tr>
95149514
<tr>
9515-
<td>SetMinusCookie</td>
9515+
<td>SetDashCookie</td>
95169516
<td>String</td>
95179517
<td></td>
95189518
<td>Cookie authentication key for use with the &#x60;api_key&#x60; apiKey authentication.</td>
95199519
</tr>
95209520
<tr>
9521-
<td>XMinusRateMinusLimit</td>
9521+
<td>XDashRateDashLimit</td>
95229522
<td>Integer</td>
95239523
<td>int32</td>
95249524
<td>calls per hour allowed by the user</td>
95259525
</tr>
95269526
<tr>
9527-
<td>XMinusExpiresMinusAfter</td>
9527+
<td>XDashExpiresDashAfter</td>
95289528
<td>Date</td>
95299529
<td>date-time</td>
95309530
<td>date in UTC when token expires</td>

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)