如何设置“参数内容类型"使用Swashbuckle吗? [英] How do I set "Parameter content type" using Swashbuckle?
问题描述
我的招摇用户界面显示参数内容类型",其中包含各种条目:"application/json-patch+json"
,"text/json"
,"application/json"
和"application/*+json"
.
My swagger ui shows "Parameter content type" with various entries: "application/json-patch+json"
, "text/json"
, "application/json"
, and "application/*+json"
.
我只想要"application/json"
.
回购协议上有一个相似未解决的问题,该问题使用了这种视觉效果(旧版ui ,但想法相同):
There's a similar unsolved issue on the repo, which uses this visual (older ui, but same idea):
有什么设置方法吗?
Swashbuckle.AspNetCore
版本4.0.1
Swashbuckle.AspNetCore.Filters
版本4.5.5
Swashbuckle.AspNetCore
version 4.0.1
Swashbuckle.AspNetCore.Filters
version 4.5.5
推荐答案
使用[Produces]
和[Consumes]
属性. Swashbuckle(以及其他类似NSwag的人)会将它们转换为适当的Swagger文档.
Use the [Produces]
and [Consumes]
attributes. Swashbuckle (and others, like NSwag) will convert them into the appropriate Swagger documentation.
[Consumes]
属性的构造函数的第一个参数是String contentType
:
The [Consumes]
attribute's constructor's first parameter is 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 )
{
//
}
}
这篇关于如何设置“参数内容类型"使用Swashbuckle吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!