gpt4 book ai didi

java - 返回 InputStream 时生成 swagger 文档

转载 作者:行者123 更新时间:2023-11-30 08:40:08 26 4
gpt4 key购买 nike

我有一个将 InputStream 作为 InputStreamResource 返回的方法,当我让 swagger 生成文档时,它说返回类型是 InputStreamResource。如何更改此设置以便文档中的返回类型为 InputStream?

  @ApiOperation()
@RequestMapping(value = "/item/{id}", produces = "application/octet-stream", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getStream(
@PathVariable(value = "id") String id,
HttpServletResponse response
) {
InputStream stream = null;
try {
stream = getData(id);
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(new InputStreamResource(stream));
} catch (Exception e) {
IOUtils.closeQuietly(stream);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return null;
}
}

最佳答案

试试这个:

@ApiOperation(response = InputStream.class)

根据文档:

response : default response class from the operation

关于java - 返回 InputStream 时生成 swagger 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35796595/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com