-
Notifications
You must be signed in to change notification settings - Fork 6k
Open
Milestone
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
.
marians