Skip to content
GitLab
    • Explore Projects Groups Snippets
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 7 years ago by Administrator@rootContributor
  • New related issue

  • Report abuse to administrator

  • New related issue

  • Report abuse to administrator

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

Closed

[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)
  1. Oh no!

    You are trying to upload something other than an image. Please upload a .png, .jpg, .jpeg, .gif, .bmp, .tiff or .ico.

    Incoming!

    Drop your designs to start your upload.
Tasks
...

Linked items
0

Link issues together to show that they're related. Learn more.

Activity


Please register or sign in to reply
0 Assignees
None
Assign to
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
Due date
None
None
None
Time tracking
Confidentiality
Not confidential

You are going to turn on confidentiality. Only project members with at least the Reporter role, the author, and assignees can view or be notified about this issue.

Lock issue
Unlocked
1
1 participant
Administrator
Reference:

Menu

Explore Projects Groups Snippets