swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.76k stars 270 forks source link

No Authorization header provided when accessing Swagger UI on browser #236

Open rockey5520 opened 2 years ago

rockey5520 commented 2 years ago

When i am trying to access swagger for a situation when handlers are protects by Authorization as middle-ware I am seeing error as "No Authorization header provided" how can i protect my routes but still able to see swagger information on UI ?

Any suggestion or example would be super helpful. thanks in advance

ubogdan commented 2 years ago

You can mount the API controllers on a subgroup "api/v1" via subgroup and add the authorization middleware there and mount swagger UI as the standard example.

rockey5520 commented 2 years ago

Thanks, @ubogdan would you be able to point me to a sample code implemented in the approach you suggested I can refer to please?