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
  • #10064
Closed
Open
Issue created Jul 30, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][GO] `ineffectual assignment to err` in `decode`

Created by: brianlow

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

Golang client ignores a potential error. Phabricator Arcanist reports: ineffectual assignment to err.

openapi-generator version
  • 5.2.0
  • latest-release (Jul 29) on dockerhub
  • issue does not exist on 5.1.1
OpenAPI declaration file content or url

This is from the swagger homepage:

swagger: "2.0"
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
  - https
paths:
  /users:
    get:
      summary: Returns a list of users.
      description: Optional extended description in Markdown.
      produces:
        - application/json
      responses:
        200:
          description: OK
Generation Details
docker run --rm \
    -v $PWD:/local \
    openapitools/openapi-generator-cli:v5.2.0 generate \
    -i /local/swagger.yaml \
    -g go \
    -o /local/myclient
Steps to reproduce

The generated myclient/client.go has this code:

if f, ok := v.(**os.File); ok {
	*f, err = ioutil.TempFile("", "HttpClientFile")
	if err != nil {
		return
	}
	_, err = (*f).Write(b)                  // <--- ineffectual assignment to err
	_, err = (*f).Seek(0, io.SeekStart)
	return
}

The err assignment from the Write call is overwritten by the next call to Seek

Related issues/PRs

Introduced in #9812

Suggest a fix
  if f, ok := v.(**os.File); ok {
  	*f, err = ioutil.TempFile("", "HttpClientFile")
  	if err != nil {
  		return
  	}
  	_, err = (*f).Write(b)
+ 	if err != null {
+ 		return
+ 	}
  	_, err = (*f).Seek(0, io.SeekStart)
  	return
  }
Assignee
Assign to
Time tracking