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 Add
gem ‘swagger-docs‘ 然后bundle 或者直接gem install
Swagger-docs
2、cd rails项目目录; vim
CONFIG/INITIALIZERS/SWAGGER_DOCS.RB, and add the following to save:
Swagger::D Ocs::config.register_apis ({
"1.0" + = {: Base_path = "http://localhost:3000",: Api_file_path = "public"}
})
3. Add in a 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
To modify the URL to 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. Enter http://localhost:3000/swagger-ui/dist/index.html in the browser
To view and test the API
If the page is turned on slowly, vim public/swagger-ui/dist/index.html,
To Fonts.googleapis.com/css ... This line of code is commented out.
Note: config/routes.rb in swagger corresponding route do not use match, otherwise will error
Visual Grape Swagger-ui