Cur*_*son 2 rspec ruby-on-rails devise
我有一组API文档页面,我想使用设计密码保护.使用rspec_api_documentation生成文档.gem使用rspec来执行API方法并创建html或json doc文件.我正在生成json并使用另一个gem,apitome作为查看器.
这一切都很漂亮,我的api文档可以在/ api/docs找到,但我无法弄清楚如何要求身份验证来查看文档.
通过apitome查看文档,因此它使用rails.routes.rb中没有路由,但apitom初始化程序会安装文档.
从apitom初始化器:
# This determines where the Apitome routes will be mounted. Changing this to "/api/documentation" for instance would
# allow you to browse to http://localhost:3000/api/documentation to see your api documentation. Set to nil and mount
# it yourself if you need to.
config.mount_at = "/api/docs"
Run Code Online (Sandbox Code Playgroud)
https://github.com/zipmark/rspec_api_documentation
https://github.com/modeset/apitome
我发现这个How-to应该会使网站上的每个页面都需要进行身份验证,但我仍然可以在不登录的情况下点击文档URL.
#https://github.com/plataformatec/devise/wiki/How-To:-Require-authentication-for-all-pages
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
您可以控制Apitome控制器并请求身份验证.
控制器实现如下:
class ApidocsController < Apitome::DocsController
before_filter :authenticate_user!
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1176 次 |
| 最近记录: |