You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
When an error response type has optional title and description fields, the generated Go client returns a pointer address instead of the actual message content.
Description
The generated Go client incorrectly formats error messages when the responded problem object contains optional title and detail fields.
Instead of displaying the string values of these fields, the client prints their memory addresses.
docker run --rm \
-u $(shell id -u):$(shell id -g) \
-v ${PWD}:/local openapitools/openapi-generator-cli:v7.11.0 generate \
-i /local/openapi.yaml \
-g go \
-o /local/openapi \
--git-user-id itotake-coconala --git-repo-id openapi-issue-pointeraddr/openapi \
--additional-properties=withGoMod=false
Steps to reproduce
generate OpenAPI client
run server like go run ./server/
run client like go run ./client/
Related issues/PRs
Suggest a fix
In the generated API client, formatErrorMessage function formats error message using title/detail field in the response.
If these fields are optional, their types are *string and formatErrorMessage prints the address of them instead of the value.
Current formatErrorMessage code:
// format error message using title and detail when model implements rfc7807funcformatErrorMessage(statusstring, vinterface{}) string {
str:=""metaValue:=reflect.ValueOf(v).Elem()
ifmetaValue.Kind() ==reflect.Struct {
field:=metaValue.FieldByName("Title")
iffield!= (reflect.Value{}) {
str=fmt.Sprintf("%s", field.Interface())
}
field=metaValue.FieldByName("Detail")
iffield!= (reflect.Value{}) {
str=fmt.Sprintf("%s (%s)", str, field.Interface())
}
}
returnstrings.TrimSpace(fmt.Sprintf("%s %s", status, str))
}
It should be like below to print the value of pointers.
// format error message using title and detail when model implements rfc7807funcformatErrorMessage(statusstring, vinterface{}) string {
str:=""metaValue:=reflect.ValueOf(v).Elem()
ifmetaValue.Kind() ==reflect.Struct {
field:=metaValue.FieldByName("Title")
iffield.Kind() ==reflect.Pointer {
field=field.Elem()
}
iffield!= (reflect.Value{}) {
str=fmt.Sprintf("%s", field.Interface())
}
field=metaValue.FieldByName("Detail")
iffield.Kind() ==reflect.Pointer {
field=field.Elem()
}
iffield!= (reflect.Value{}) {
str=fmt.Sprintf("%s (%s)", str, field.Interface())
}
}
returnstrings.TrimSpace(fmt.Sprintf("%s %s", status, str))
}
The output with modified client:
$ go run ./client400 Bad Request invalid request (This endpoint always returnes error)
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
When an error response type has optional
title
anddescription
fields, the generated Go client returns a pointer address instead of the actual message content.Description
The generated Go client incorrectly formats error messages when the responded problem object contains optional
title
anddetail
fields.Instead of displaying the string values of these fields, the client prints their memory addresses.
sample client code
output
sample server code
openapi-generator version
v7.11.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
go run ./server/
go run ./client/
Related issues/PRs
Suggest a fix
In the generated API client,
formatErrorMessage
function formats error message using title/detail field in the response.If these fields are optional, their types are
*string
andformatErrorMessage
prints the address of them instead of the value.Current
formatErrorMessage
code:It should be like below to print the value of pointers.
The output with modified client:
The text was updated successfully, but these errors were encountered: