forked from loafle/openapi-generator-original
Add handling for parsing optional bool params & regenerate samples (#14550)
This commit is contained in:
committed by
GitHub
parent
b538c2adf8
commit
8540c82d30
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user