swagger-api / swagger-api/swagger-codegen
[Go] [Bug] APIResponse should not embed a pointer to *http.Response
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
APIResponse currently embeds a *http.Response, which leads to unexpected behavior. If including a http.Response, then it should be a named field. As it currently stands, one can receive a *APIResponse object which is not nil, but in which the http.Response pointer is nil. This leads to behavior where myAPIResponse != nil evaluates to true, but myAPIResponse.Status results in a panic.
Swagger-codegen version
master
Suggest a Fix
Instead of embedding the *http.Response, it should be a named element. That is, instead of:
// WRONG
type APIResponse struct {
*http.Response
Message string `json:"message,omitempty"`
}
We should do:
// BETTER
type APIResponse struct {
Response *http.Response
Message string `json:"message,omitempty"`
}
That is to say, the generated code should always return an APIResponse, but sometimes (e.g. in the case of a network error), there's no http.Response.
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 locating the Go generation template that defines APIResponse and the generated response-handling path. Confirm how network errors are represented, then update the response shape so the HTTP response is named and verify that callers receive a non-nil APIResponse with no embedded Status access when no HTTP response exists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100