Add handling for parsing optional bool params & regenerate samples (#14550)

This commit is contained in:
Sebastian Cevallos
2023-01-30 03:35:19 -05:00
committed by GitHub
parent b538c2adf8
commit 8540c82d30
5 changed files with 37 additions and 5 deletions

View File

@@ -124,7 +124,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
}
{{/isInteger}}
{{#isBoolean}}
{{paramName}}Param, err := parseBoolParameter(query.Get("{{baseName}}"))
{{paramName}}Param, err := parseBoolParameter(query.Get("{{baseName}}"), {{required}})
if err != nil {
w.WriteHeader(500)
return

View File

@@ -199,7 +199,15 @@ func parseInt32Parameter(param string, required bool) (int32, error) {
}
// parseBoolParameter parses a string parameter to a bool
func parseBoolParameter(param string) (bool, error) {
func parseBoolParameter(param string, required bool) (bool, error) {
if param == "" {
if required {
return false, errors.New(errMsgRequiredMissing)
}
return false, nil
}
val, err := strconv.ParseBool(param)
if err != nil {
return false, err

View File

@@ -167,7 +167,15 @@ func parseInt32Parameter(param string, required bool) (int32, error) {
}
// parseBoolParameter parses a string parameter to a bool
func parseBoolParameter(param string) (bool, error) {
func parseBoolParameter(param string, required bool) (bool, error) {
if param == "" {
if required {
return false, errors.New(errMsgRequiredMissing)
}
return false, nil
}
val, err := strconv.ParseBool(param)
if err != nil {
return false, err

View File

@@ -163,7 +163,15 @@ func parseInt32Parameter(param string, required bool) (int32, error) {
}
// parseBoolParameter parses a string parameter to a bool
func parseBoolParameter(param string) (bool, error) {
func parseBoolParameter(param string, required bool) (bool, error) {
if param == "" {
if required {
return false, errors.New(errMsgRequiredMissing)
}
return false, nil
}
val, err := strconv.ParseBool(param)
if err != nil {
return false, err

View File

@@ -163,7 +163,15 @@ func parseInt32Parameter(param string, required bool) (int32, error) {
}
// parseBoolParameter parses a string parameter to a bool
func parseBoolParameter(param string) (bool, error) {
func parseBoolParameter(param string, required bool) (bool, error) {
if param == "" {
if required {
return false, errors.New(errMsgRequiredMissing)
}
return false, nil
}
val, err := strconv.ParseBool(param)
if err != nil {
return false, err