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
  • #464
Closed
Open
Issue created Jul 05, 2018 by Administrator@rootContributor

[Golang][client] ineffectual assignment in client.go / client.mustache

Created by: grokify

Description

client.go and client.mustache has an ineffectual assignment that triggers a Go Report Card ineffassign error.

Specifically, the following assignment is never used:

if err != nil { 
    expires = now 
}

because it is immediately followed by:

expires = now.Add(lifetime)

client.mustache:

https://github.com/OpenAPITools/openapi-generator/blob/00354d3264a2c7502ab09b21a66da4baae50445f/modules/openapi-generator/src/main/resources/go/client.mustache#L427-L431

client.go (Petstore sample):

https://github.com/OpenAPITools/openapi-generator/blob/00354d3264a2c7502ab09b21a66da4baae50445f/samples/client/petstore/go/go-petstore/client.go#L438-L442

openapi-generator version

3.0.3

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/00354d3264a2c7502ab09b21a66da4baae50445f/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml

Command line used for generation
$ bin/go-petstore.sh
Steps to reproduce

Generate client.

Error is seen in Go Report Card which uses ineffassign.

An example is here:

https://goreportcard.com/report/github.com/grokify/go-stackexchange#ineffassign

screen shot 2018-07-04 at 9 11 51 pm
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/466

Suggest a fix/enhancement

If an error is encountered, lifetime should not be valid so we can use the following:

lifetime, err := time.ParseDuration(maxAge + "s") 
if err != nil {
    expires = now
} else {
    expires = now.Add(lifetime)
}

Technically, the following can be used as well since an error will result in a lifetime duration of 0s but it requires a bit more to understand, and it's better to not rely on a value not mean to be used. This is essentially what is happening now without the extra if.

lifetime, _ := time.ParseDuration(maxAge + "s")
expires = now.Add(lifetime)
Assignee
Assign to
Time tracking