OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.75k stars 6.56k forks source link

[BUG] [Go] Generated client code does not pass golint and has several style antipatterns #8485

Closed aeneasr closed 2 years ago

aeneasr commented 3 years ago

Bug Report Checklist

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:

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

auto-labeler[bot] commented 3 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

aeneasr commented 2 years ago

Fixed