在Swagger UI中,是否可以配置Swashbuckle为特定HTTP错误代码401生成不同的媒体类型?
我希望400错误代码的媒体类型是application/JSON,但对于401,它是text/HTML。有什么方法可以实现这一点吗?
控制器上方注解,
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Route("[controller]")]
[Route("v{version:apiVersion}/[controller]")]
[Produces("application/json")]
public class MyController : ControllerBase
{
}
我的方法上面的注解,
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpPost]
public async Task<ActionResult<MyModel>> PostAsync(MyRequest myRequest)
{
}
1条答案
按热度按时间92vpleto1#
您是否尝试过SwaggerResponse属性,它派生自ProducesResponseType,并已增强为支持添加内容媒体类型:
它是核心包的一部分:
Swashbuckle.AspNetCore.Annotations