How to preview API JSON response in swagger when using content-disposition: attachment; filename="api.json"

Viewed 254

I am using Java, Swagger 2.

I need to use content-disposition: attachment; filename="file.json" in the response header of the APIs but when I use this header, I see the Download file button link and the file includes the response. When I use the APIs in UI(React) or any other rest API client, I get JSON response rather than download file link which is expected.

enter image description here

This is how I am setting header in CORS filter.

private void setHeaders(HttpServletResponse response, HttpServletRequest request){
    response.setHeader("Content-Disposition", "attachment; filename=\"file.json\"");
  }

Setting application/json

@GetMapping(path="/xyz", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)

I want swagger also to preview the response JSON rather than showing up the Download link button.

0 Answers
Related