swagger-api / swagger-api/swagger-codegen
[Go] Go generated code does not return a response body on 202
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
202 HTTP Accepted allows returning a body, however the code generated for Go does not parse the body.
If you look at the generated code, there's no way body would be returned.
generated Go code
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
localVarHttpResponse.Body.Close()
if err != nil {
return localVarHttpResponse, err
}
if localVarHttpResponse.StatusCode >= 300 {
newErr := GenericSwaggerError{
body: localVarBody,
error: localVarHttpResponse.Status,
}
if localVarHttpResponse.StatusCode == 202 {
var v map[string]interface{}
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
if err != nil {
newErr.error = err.Error()
return localVarHttpResponse, newErr
}
newErr.model = v
return localVarHttpResponse, newErr
}
return localVarHttpResponse, newErr
}
return localVarHttpResponse, nil
Reading through the code, localVarHttpResponse.StatusCode will never be >= 300 and localVarHttpResponse.StatusCode == 202 at the same time.
Swagger-codegen version
2.4.15
Swagger declaration file content or url
https://gist.github.com/cd651d52dceb68fda8025e9b61ca37db
Command line used for generation
swagger-codegen-cli:2.4.15 generate -i /tmp/gate/swagger.json -l go -o /tmp/go/
Steps to reproduce
Use the swagger template provided and generate Go code.
Suggest a fix/enhancement
202, and pretty much all response bodies should always be returned back to the caller.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the Swagger template from the linked gist and the swagger-codegen-cli 2.4.15 command, then inspect the generated Go client code and the Go generation template that produced it. Compare the status-code branch with the documented 202 behavior. Done means generated Go clients return an available response body for 202 responses without an unreachable condition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100