I'm building an API where I have a couple of endpoints where I need the User ID, so after getting the idea from the most voted answer (not the accepted one) from this post: ASP.NET MVC Pass object from Custom Action Filter to Action.
I created an Action Filter that I can set up just with the [UserIdFromToken]
attribute.
So I'm basically getting the User ID through this Action Filter that gets it from the authorization header this way:
[Authorize]
[UserIdFromToken]
public IActionResult Get(Guid userId /* Got from the [UserIdFromToken] filter */)
{
return Ok(_userService.Get(userId));
}
The only problem is now it's showing the parameter userId
as a Required parameter (and I don't want to show it at all) in my Swagger documentation, which is obviously false, since I don't need any input beyond the authorization header.
Is there any way to get my swagger documentation cleaner, without showing this parameter?
Do you think it would be better to try another approach to get the userId
such as the accepted option from the post I sent above?