I have an ASP.NET Core Web API 3 app that implements a REST API and uses a JWT bearer token for authorization, and Swagger (Swashbuckle).
My controller has the [Authorize] filter on it, like:
[ApiController]
[Route("api/[controller]")]
[Authorize]
public class MyController : ControllerBase
{
}
Swagger works with my API, and I can generate a JWT token and give to Swagger and it all works well.
But if I try to use Swagger to hit one of my REST endpoints without a JWT token or invalid JWT token, the Swagger UI is showing an error 401 Undocumented, but all the examples I see out on the web show that I should be getting 401 Unauthorized.
(When I hit the same URL with Postman, it does show 401 Unauthorized.)
Before I start ripping out things, any ideas why I might be getting Undocumented instead of Unauthorized?
This is what I see:
When I add the attribute suggested below
(ProducesResponseType(typeof(ProblemDetails), (int)HttpStatusCode.Unauthorized)])
I see this:
You can add app.UseStatusCodePages() in the Startup.cs.
This will then return a response body
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With