[BUG] [Go] Generated client code does not pass golint and has several style antipatterns
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 generates code which does not pass golint. Passing golint checks is important because it can detect Go anti-patterns. I listed some of the output below
api_health.go:27:6: type `HealthApiService` should be `HealthAPIService` (golint)
type HealthApiService service
^
api_public.go:1270:2: don't use underscores in Go names; struct field error_ should be error (golint)
error_ *string
^
api_public.go:1273:49: don't use underscores in Go names; method Error_ should be Error (golint)
func (r PublicApiApiGetSelfServiceErrorRequest) Error_(error_ string) PublicApiApiGetSelfServiceErrorRequest {
^
errcheck
is not golint but detects missing error checks:
client.go:245:18: Error return value of `w.WriteField` is not checked (errcheck)
w.WriteField(k, iv)
^
client.go:115:6: SA6005: should use strings.EqualFold instead (staticcheck)
if strings.ToLower(a) == strings.ToLower(needle) {
^
Other code-"smells" not detected by golint or golangci-lint are:
-
non-nilable errors #8483 (closed) -
Abbreviated names are not capitalized ( struct{ Id string `json:"id"` }
) but should be (e.g.struct {ID string `json:"id"`}
) -
Slice fields are referenced as pointers ( struct Foo { Bar *[]Bar }
) but should be referenced as regular slices (e.g.struct Foo { Bar []Bar }
.
openapi-generator version
5.0.0
OpenAPI declaration file content or url
Any valid OpenAPI 3.0 schema.
Generation Details
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