Skip to content

[Go] [Bug] APIResponse should not embed a pointer to *http.ResponseΒ #3691

@neilotoole

Description

@neilotoole
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions