如何使用 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 );
像这样:
[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 )
{
//
}
}
我的招摇 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 );
像这样:
[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 )
{
//
}
}