[英]How can I hide response code 200 with Swashbuckle.AspNetCore?
Ciao, 再见,
I'm working on a asp.net web api core (target framework .NET Core 2.1). 我正在研究一个ASP.NET Web API核心(目标框架.NET Core 2.1)。 I'm documenting my API using Swagger specifications.
我正在使用Swagger规范记录我的API。 I chose to use Swashbuckle.AspNetCore library.
我选择使用Swashbuckle.AspNetCore库。
I have one simple create action like the following: 我有一个简单的创建动作,如下所示:
/// <summary>
/// My summary
/// </summary>
/// <remarks>My remarks</remarks>
/// <param name="value">value</param>
/// <response code="201">Created</response>
/// <response code="400">Data not valid</response>
/// <response code="500">Internal Server Error</response>
[HttpPost]
public IActionResult Post([FromBody, BindRequired] EntityDto value)
{
...
}
The problem is that my generated swagger.json automatically created a "200 response". 问题是我生成的swagger.json自动创建了“ 200响应”。 But because my action only creates entities it only returns 201 response.
但是因为我的操作仅创建实体,所以它仅返回201响应。 This is the following json fragment:
这是以下json片段:
{
...
"responses": {
"200": {
"description": "Success"
},
"201": {
"description": "Created"
},
"400": {
"description": "Data not valid"
},
"500": {
"description": "Internal Server Error"
}
}
...
}
Surfing on internet I've found SwaggerResponseRemoveDefaults attribute but seems that it is only supported in Full Framework projects. 在Internet上冲浪时,我发现了SwaggerResponseRemoveDefaults属性,但似乎仅在Full Framework项目中受支持。
How can I remove 200 response? 如何删除200条回复?
In order not to include default response code into swagger, you can declare possible return codes 为了不将默认响应代码包括在内,您可以声明可能的返回码
/// <summary>
/// My summary
/// </summary>
/// <remarks>My remarks</remarks>
/// <param name="value">value</param>
/// <returns>A newly created TodoItem</returns>
/// <response code="201">Created</response>
/// <response code="400">Data not valid</response>
/// <response code="500">Internal Server Error</response>
[HttpPost]
[ProducesResponseType(201)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public void Post([FromBody] string value)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.