Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #8485
Closed
Open
Issue created Jan 20, 2021 by Administrator@rootContributor5 of 9 checklist items completed5/9 checklist items

[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

Assignee
Assign to
Time tracking