[BUG] [Go] Execution responses and errors are values not pointers
Created by: aeneasr
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generating a Go-client yields in code that does not adhere to Golang's error handling. Request executors return GenericOpenAPIError
as a value:
func (r AdminApiApiDeleteIdentityRequest) Execute() (*_nethttp.Response, GenericOpenAPIError) {
return r.ApiService.DeleteIdentityExecute(r)
}
which makes it impossible to check if err != nil
as the variable is a value (and thus always not nil) and not a pointer. Instead, this should read:
func (r AdminApiApiDeleteIdentityRequest) Execute() (*_nethttp.Response, *GenericOpenAPIError) {
return r.ApiService.DeleteIdentityExecute(r)
}
The same applies to return values which should also be pointers, not structs:
func (a *HealthApiService) IsInstanceReadyExecute(r HealthApiApiIsInstanceReadyRequest) (HealthStatus, *_nethttp.Response, GenericOpenAPIError) {
should be:
func (a *HealthApiService) IsInstanceReadyExecute(r *HealthApiApiIsInstanceReadyRequest) (HealthStatus, *_nethttp.Response, *GenericOpenAPIError) {
openapi-generator version
5.0.0
OpenAPI declaration file content or url
https://gist.github.com/aeneasr/3c11c5b454df6c5e4d8e7a3e16d04db7
Generation Details
# gen.go.yml
disallowAdditionalPropertiesIfNotPresent: false
packageName: kratos
generateInterfaces: false
isGoSubmodule: false
structPrefix: true
$ npm run openapi-generator-cli -- generate -i ".schema/api.openapi.json" \
-g go \
-o "internal/httpclient" \
--git-user-id ory \
--git-repo-id kratos-client-go \
--git-host github.com \
-c .schema/openapi/gen.go.yml
Steps to reproduce
See above.
Related issues/PRs
Suggest a fix
I know too little java and internals of how this system works. But basically calls to GenericOpenAPIError{/* ... */}
should always be pointers &GenericOpenAPIError{ /* ... */ }
. Same for API return values.