C# 使用dotnet core的Swagger文档的返回文件类型

C# 使用dotnet core的Swagger文档的返回文件类型,c#,.net-core,swagger,asp.net-core-webapi,C#,.net Core,Swagger,Asp.net Core Webapi,我正在使用它来记录我的dotnet核心Web API 我已经阅读了文档,其中告诉我需要添加 [ProducesResponseType(typeof(XXXXX),200)]在控制器方法上方,以帮助swagger确定方法的响应类型 我有一个控制器方法可以返回一个文件,我正在尝试找出如何告诉swagger我正在返回一个文件 public class DocumentController : Controller { private readonly IDocumentService _do

我正在使用它来记录我的dotnet核心Web API

我已经阅读了文档,其中告诉我需要添加
[ProducesResponseType(typeof(XXXXX),200)]
在控制器方法上方,以帮助swagger确定方法的响应类型

我有一个控制器方法可以返回一个文件,我正在尝试找出如何告诉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);
    }
}
公共类文档控制器:控制器
{
私有只读IDocumentService\u documentService;
公共文档管理员(IDocumentService文档服务)
{
_documentService=documentService;
}
[HttpGet(“{documentId}”,Name=DocumentRoutes.Document)]
[ProductsResponseType(typeof(XXXXX),200)]//您需要的是,并指定内容类型作为参数(例如,pdf文件的“application/pdf”)


编辑:看来斯威格可能不会选择
ProducesAttribute
。我的建议是将
Type
设置为
ProducesResponseType
,并添加一个
///将请求的文件
注释返回到方法中。

您认为可以指定所有内容类型吗?我刚刚尝试了这个方法,但没有看起来已经使用过aspnetcore版本的Swashback。返回文件是一种响应,是一种内容类型,而不是表示json或xml文档架构的
ProducesResponseType
。如果Swagger没有在action方法上选择
ProducesAttribute
,那么我只需将
类型
留给de>ProducesResponseType
取消设置并使用
返回请求的文件
commentLink无效