[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
}