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