首先我們來看看swagger-bootstrap-ui的效果,如圖所示:
看起來是不是比Swagger要大氣的多。
回到重點上,為什么要給接口文檔加密呢?
只對內開放,不對外開放,防止被第三方非公司人員進行非法竊取。
那么我們如何給它加Basic校驗呢?
首先聲明,為什么要給它加Basic而不是oAuth2.0之類的驗證?
其實道理很簡單,避免重復造輪子,swagger-bootstrap里面集成有的,我們又何必為其多此一舉呢。
當然了,生產環境下,我們盡可能還是不要將其對外開放好一些,具體,swagger-bootstrap也提供對應的配置,如下所示:
application.properties:
swagger.production=true
application.yml:
swagger: production: true
效果圖,如下:
以使用SpringBoot為例
只需在application.yml配置如下內容即可:
swagger: basic: enable: true username: test password: test
如果是application.properties:
## 開啟Swagger的Basic認證功能,默認是false swagger.basic.enable=true ## Basic認證用戶名 swagger.basic.username=test ## Basic認證密碼 swagger.basic.password=test
效果圖,如下:
https://doc.xiaominfo.com/images/ac-pwd.png
更多資料,可以參考官方文檔:https://doc.xiaominfo.com/