3
我使用Swagger for dotnet core来记录我的dotnet核心Web API。使用dotnet核心的Swagger文档的返回类型
我已阅读文档,告诉我需要在控制器方法上方添加 [ProducesResponseType(typeof(XXXXX),200)]
以帮助确定方法的响应类型。
我有一个控制器方法,返回一个文件,我想解决如何我可以告诉swagger我返回一个文件。
public class DocumentController : Controller
{
private readonly IDocumentService _documentService;
public DocumentController(IDocumentService documentService)
{
_documentService = documentService;
}
[HttpGet("{documentId}", Name= DocumentRoutes.Document)]
[ProducesResponseType(typeof(XXXXX), 200)] // <== What goes here?
public async Task<IActionResult> GetDocument(Guid documentId)
{
DocumentAdto documentAdto = await _documentService.GetAsync(documentId);
return File(documentAdto.DocumentBytes, documentAdto.ContentType, documentAdto.Name);
}
}
有没有人有任何想法?
我想过byte [],但只是说返回类型是“字节”。
你认为你可以指定所有的内容类型吗? – chris31389
我刚刚尝试过这一点,它看起来没有使用aspnetcore版本的swashbuckle。 – chris31389
返回一个文件是一个响应是一种内容类型,而不是'ProducesResponseType',它表示一个json或xml文档模式。如果Swagger没有选择Action方法中的'ProducesAttribute',那么我会简单地将'Type'替换为'ProducesResponseType'并且使用'返回请求的文件 'comment –
Moho