Skip to content

Commit

Permalink
Extract single_doc route for single version documentations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuzanna Stolińska committed Aug 3, 2017
1 parent 67f53ed commit a16b233
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ You can define your main documentation url in a hash value (same way as in the v
# config/initializers/swagger_ui_engine.rb
SwaggerUiEngine.configure do |config|
config.swagger_url = 'api/v1/swagger.yaml'
config.swagger_url = 'api/swagger.yaml'
end
```
and place your main documentation file under `/public/api/v1` path. The `v1` filepath is required for single API documentation.

### Configure
Config Name | Swagger parameter name | Description
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/swagger_ui_engine/swagger_docs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def oauth2

def index
# backward compatibility for defining single doc url in strings
redirect_to swagger_doc_path('v1') if single_doc_url?
redirect_to single_swagger_doc_path if single_doc_url?
redirect_to swagger_doc_path(@swagger_url.keys.first) if single_doc_url_hash?
end

Expand All @@ -22,6 +22,10 @@ def show
@swagger_url = @swagger_url[params[:id].to_sym] unless single_doc_url?
end

def single_doc
render 'show'
end

private

def set_configs
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
end
end

get 'single_swagger_doc', to: 'swagger_docs#single_doc', format: false
root to: 'swagger_docs#index'
end
end

0 comments on commit a16b233

Please sign in to comment.