Skip to content

Commit

Permalink
[Go] Format error message only when Kind is Struct (#15154)
Browse files Browse the repository at this point in the history
* Check if Kind is Struct

* Commit regenerated files

* Tabs indentation instead of 4-space

* Commit regenerated files
  • Loading branch information
gcatanese authored Apr 11, 2023
1 parent a17bb59 commit 2b796d5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
17 changes: 9 additions & 8 deletions modules/openapi-generator/src/main/resources/go/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,17 @@ func formatErrorMessage(status string, v interface{}) string {
str := ""
metaValue := reflect.ValueOf(v).Elem()
field := metaValue.FieldByName("Title")
if field != (reflect.Value{}) {
str = fmt.Sprintf("%s", field.Interface())
}
if metaValue.Kind() == reflect.Struct {
field := metaValue.FieldByName("Title")
if field != (reflect.Value{}) {
str = fmt.Sprintf("%s", field.Interface())
}
field = metaValue.FieldByName("Detail")
if field != (reflect.Value{}) {
str = fmt.Sprintf("%s (%s)", str, field.Interface())
field = metaValue.FieldByName("Detail")
if field != (reflect.Value{}) {
str = fmt.Sprintf("%s (%s)", str, field.Interface())
}
}
// status title (detail)
return strings.TrimSpace(fmt.Sprintf("%s %s", status, str))
}
17 changes: 9 additions & 8 deletions samples/client/petstore/go/go-petstore/client.go

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

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

17 changes: 9 additions & 8 deletions samples/openapi3/client/petstore/go/go-petstore/client.go

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

0 comments on commit 2b796d5

Please sign in to comment.