swagger-axios-codegen icon indicating copy to clipboard operation
swagger-axios-codegen copied to clipboard

Feature request: allow configuration of response, only data, or AxiosResponse<data>

Open wimdetroyer opened this issue 2 years ago • 3 comments

Currently, all responses are automatically resolved to axios.response.data, however, sometimes it is useful to have the wrapping AxiosResponse:

export interface AxiosResponse<T = any>  {
  data: T;
  status: number;
  statusText: string;
  headers: any;
  config: AxiosRequestConfig;
  request?: any;
}

For example: say I make a PUT request to create an entity, my API will return a status code 201 with a HTTP location header filled in like: www.example.com/api/v1/entity/123. Having access to this header would make my life a bit easier, however, only the response data is returned now.

I understand this might be an edge case and for 99% of requests, simply returning the data itself is sufficient, but allowing configuration of this might be interesting.

Something like:

export interface ISwaggerOptions = {
 [...]
  methodReturnsWrappedInAxiosResponse: boolean; // Default: false
}

wimdetroyer avatar Aug 11 '21 07:08 wimdetroyer

it mean , you need full axios response?

Manweill avatar Aug 11 '21 14:08 Manweill

@Manweill Yes.

wimdetroyer avatar Aug 12 '21 12:08 wimdetroyer

#144

Manweill avatar Aug 19 '21 08:08 Manweill