Hide some api in swagger ui
Asked Answered
D

1

7

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.

Dante answered 5/4, 2018 at 22:16 Comment(0)
I
4

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.

Industrialism answered 9/8, 2018 at 12:9 Comment(1)
If I omit the tag key or put its value as blank, then in both of the scenarios, the method is created with a default tag.Lib

© 2022 - 2024 — McMap. All rights reserved.