zamkam
3 years agoFrequent Visitor
Swagger UI ignores custom response for 404 status
I have the following controller method in an ASP.NET Core Web API:
[SwaggerResponse(200, "Order canceled", typeof(ApiActionResult))]
[SwaggerResponseExample(200, typeof(VoidOrder200))]
[SwaggerResponse(404, "Order not found", typeof(ApiActionResult))]
[SwaggerResponseExample(404, typeof(OrderNotFound404))]
public IActionResult CancelOrder(Guid OrderId)
{
return _OrderService.CancelOrder(OrderId);
}
The classes passed to SwaggerResponseExample are simple custom responses:
public class OrderNotFound404 : IExamplesProvider<ApiActionResult>
{
public ApiActionResult GetExamples()
{
return new ApiActionResult
{
Success = false,
Message = "Order not found",
Data = null,
OperationResults = null
};
}
}
Now, when debugging the API on my computer, the 404 response behaves as expected:
But when it's running on a server, the custom response is not displayed:
Is there some setting that causes this behavior? As far as I can tell it only happens with the 404 status, I've tried 400, 403 and 406 and they all display the custom message correctly. All environments run Windows 10 and Windows Server 2019.