码迷,mamicode.com
首页 > 其他好文 > 详细

可视化grape swagger-ui

时间:2015-02-28 18:32:29      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

swagger-docs : 

    https://github.com/richhollis/swagger-docs
swagger-docs-sample:   https://github.com/richhollis/swagger-docs-sample/blob/master/README.md
swagger-ui: https://github.com/wordnik/swagger-ui

1、vim Gemfile 添加  gem ‘swagger-docs‘ 然后 bundle    或者直接 gem install swagger-docs
2、cd rails项目目录;   vim config/initializers/swagger_docs.rb , 并添加保存如下内容:
 Swagger::Docs::Config.register_apis({
    "1.0" => {:base_path => "http://localhost:3000", :api_file_path => "public"}
  })
3、在某个controller中添加:
   swagger_controller :user_api, "UserApi"
 
   swagger_api :index do
    summary "test"
    response :unauthorized
    response :not_acceptable
   end

   def index
     render :json => {result:"Success"}, :status => 200
   end

4、rake swagger:docs
5、rails s
6、cd public
7、git clone https://github.com/wordnik/swagger-ui.git
8、vim swagger-ui/dist/index.html
   将 url 修改为 http://localhost:3000/api-docs.json
   window.swaggerUi = new SwaggerUi({
      url: "http://localhost:3000/api-docs.json",
           //http://petstore.swagger.wordnik.com/api/api-docs     
      dom_id: "swagger-ui-container",
      supportedSubmitMethods: [‘get‘, ‘post‘, ‘put‘, ‘delete‘],
      ... ... ...
9、浏览器中输入 http://localhost:3000/swagger-ui/dist/index.html
即可查看并测试api
技术分享

如果页面打开慢,vim public/swagger-ui/dist/index.html ,
将 ...fonts.googleapis.com/css...这行代码注释掉。

注: config/routes.rb 中 swagger对应的route 不要用match, 否则会报错

可视化grape swagger-ui

标签:

原文地址:http://www.cnblogs.com/qinyan20/p/4305968.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!