Skip to content

Commit 033bc80

Browse files
committed
Fix: document default/root APIs.
1 parent 4a38969 commit 033bc80

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

CHANGELOG.markdown

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
### Next Release
2+
3+
* Added Rails 4 support - [@jrhe](https://github.com/jrhe).
4+
* Fix: document APIs at root level - [@dblock](https://github.com/dblock).
5+
6+
### 0.5.0 (March 28, 2013)
7+
8+
* Added Grape 0.5.0 support - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
9+
10+
### 0.4.0 (March 28, 2013)
11+
12+
* Support https - [@cutalion](https://github.com/cutalion).
13+
14+
### 0.3.0 (October 19, 2012)
15+
16+
* Added version support - [@agileanimal](https://github.com/agileanimal), [@fknappe](https://github.com/fknappe).
17+
* Added support for nested parameters - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
18+
* Added basic support for specifying parameters that need to be passed in the header - [@agileanimal](https://github.com/agileanimal).
19+
* Add possibility to hide the documentation paths in the generated swagger documentation - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
20+
21+
### 0.2.1 (August 17, 2012)
22+
23+
* Added support for markdown in notes field - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
24+
* Fix: compatibility with Rails - [@qwert666](https://github.com/qwert666).
25+
* Fix: swagger UI history - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
26+
27+
### 0.2.0 (July 27, 2012)
28+
29+
* Use resource as root for swagger - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
30+
* Added support for file uploads, and proper `paramType` - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
31+
* Added tests - [@nathanvda](https://github.com/nathanvda).
32+
33+
### 0.1.0 (July 19, 2012)
34+
35+
* Added some configurability to the generated documentation - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
36+
* Adapted to rails plugin structure - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
37+
* Allowed cross origin, so swagger can be used from official site - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
38+
39+
### 0.0.0 (July 19, 2012)
40+
41+
* Initial public release - [@tim-vandecasteele](https://github.com/tim-vandecasteele).

lib/grape-swagger.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@ class API
55
class << self
66
attr_reader :combined_routes
77

8-
alias original_mount mount
9-
10-
def mount(mounts)
11-
original_mount mounts
12-
@combined_routes ||= {}
13-
mounts::routes.each do |route|
14-
resource = route.route_path.match('\/(\w*?)[\.\/\(]').captures.first
15-
next if resource.empty?
16-
@combined_routes[resource.downcase] ||= []
17-
@combined_routes[resource.downcase] << route
18-
end
19-
end
20-
218
def add_swagger_documentation(options={})
229
documentation_class = create_documentation_class
2310

2411
documentation_class.setup({:target_class => self}.merge(options))
2512
mount(documentation_class)
13+
14+
@combined_routes = {}
15+
routes.each do |route|
16+
resource = route.route_path.match('\/(\w*?)[\.\/\(]').captures.first
17+
next if resource.empty?
18+
resource.downcase!
19+
@combined_routes[resource] ||= []
20+
@combined_routes[resource] << route
21+
end
22+
2623
end
2724

2825
private

spec/default_api_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'spec_helper'
2+
3+
describe "Default API" do
4+
5+
before(:all) do
6+
class NotAMountedApi < Grape::API
7+
desc 'this gets something'
8+
get '/something' do
9+
{:bla => 'something'}
10+
end
11+
add_swagger_documentation
12+
end
13+
end
14+
15+
def app; NotAMountedApi; end
16+
17+
it "should document something" do
18+
get '/swagger_doc'
19+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/something.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
20+
end
21+
22+
end

0 commit comments

Comments
 (0)