如何使用 Swashbuckle 设置 "Parameter content type"?

How do I set "Parameter content type" using Swashbuckle?

我的招摇 ui 显示 "Parameter content type" 有各种条目:"application/json-patch+json""text/json""application/json""application/*+json".

我只要"application/json".

回购中有一个 similar 未解决的问题,它使用了这个视觉效果(较旧的 ui,但想法相同):

有什么方法可以设置吗?

Swashbuckle.AspNetCore版本4.0.1
Swashbuckle.AspNetCore.Filters版本4.5.5

使用 [Produces][Consumes] 属性。 Swashbuckle(和其他人,如 NSwag)会将它们转换成适当的 Swagger 文档。

[Consumes] 属性的构造函数的第一个参数是 String contentType:

public ConsumesAttribute ( string contentType, params string[] otherContentTypes );

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.consumesattribute.-ctor?view=aspnetcore-2.2#Microsoft_AspNetCore_Mvc_ConsumesAttribute__ctor_System_String_System_String___

像这样:

[ApiController]
public class MyController : ControllBase
{
    [HttpPost( "/foo/bar" )]
    [Consumes( MediaTypeNames.Application.Json )] // "application/json"
    [Produces( typeof(MyResponseDto) ) ]
    public async Task<IActionResult> Post( [FromBody] MyRequestDto dto )
    {
        // 
    }
}