ppb
ppb

Reputation: 2633

Hide some api in swagger ui

Is it possible in hapi-swagger to hide some APIs from documentation (swagger ui) based on user role. I mean suppose I have /employee and /admin two APIs so whenever admin login to swagger ui or swagger documentation so both /employee and /admin API should display on page and if employee login to swagger ui then it should display only /employee API.

Upvotes: 7

Views: 5464

Answers (1)

dhj
dhj

Reputation: 4805

You can hide routes by omitting the ['tag'] value in the configuration, but you cannot have this on a user based role without considerable reworking. The documentation is generated at server start not on the fly, which is why you need to reload the server to reflect changes.

I had a similar use case, and in the end I decided it made more sense to have a different endpoint for the two difference services (in your case employee and admin). So perhaps something like api.domain.com/internal and api.domain.com/external and if so desired its easy to wrap authentication around either of these. It also leads to advantages should you ever want to grant access to developers to work on one API group rather than open access to both.

Upvotes: 4

Related Questions