fix(go-server): Allow optional request bodies (#16579)

* fix(go-server): Allow optional request bodies

Closes #16578

* chore: Run scripts

* chore: Remove unnecessary whitespace change

* fix: Use correct error
This commit is contained in:
Alex Kucksdorf 2023-09-18 07:59:28 +02:00 committed by GitHub
parent 8c8be7482b
commit 352182a7b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,12 @@ package {{packageName}}
import (
"encoding/json"
{{#isBodyParam}}
{{^required}}
"errors"
"io"
{{/required}}
{{/isBodyParam}}
"net/http"
"strings"
@ -403,7 +409,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
{{^isAdditionalPropertiesTrue}}
d.DisallowUnknownFields()
{{/isAdditionalPropertiesTrue}}
if err := d.Decode(&{{paramName}}Param); err != nil {
if err := d.Decode(&{{paramName}}Param); err != nil {{^required}}&& !errors.Is(err, io.EOF) {{/required}}{
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}