From 754e820c4f8d055c01fe7b686a8493cecbf1ce42 Mon Sep 17 00:00:00 2001 From: Adriano Dadario Date: Thu, 19 Sep 2013 14:33:03 -0300 Subject: [PATCH 1/2] Removing patch level from .rvmrc Not necessary fix patch level in .rvmrc file. Let use the current installed ruby patch level Adriano Dadario Vagas Tecnologia --- .rvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rvmrc b/.rvmrc index a7a9441f..5931c328 100644 --- a/.rvmrc +++ b/.rvmrc @@ -6,7 +6,7 @@ # First we specify our desired [@], the @gemset name is optional, # Only full ruby name is supported here, for short names use: # echo "rvm use 1.9.3" > .rvmrc -environment_id="ruby-1.9.3-p125@grape-swagger" +environment_id="ruby-1.9.3@grape-swagger" # Uncomment the following lines if you want to verify rvm version per project # rvmrc_rvm_version="1.14.3 (stable)" # 1.10.1 seams as a safe start From 350e1abe7b08109593b250a437fc10825e44f958 Mon Sep 17 00:00:00 2001 From: Adriano Dadario Date: Thu, 19 Sep 2013 14:44:49 -0300 Subject: [PATCH 2/2] Include in regex to capture URL with '-' in name Some URL with names that contains the character '-' were not captured by the regex. Example name /simple-test(:format) Adriano Dadario Vagas Tecnologia --- lib/grape-swagger.rb | 2 +- spec/simple_mounted_api_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/grape-swagger.rb b/lib/grape-swagger.rb index 481e1c80..3dff2961 100644 --- a/lib/grape-swagger.rb +++ b/lib/grape-swagger.rb @@ -13,7 +13,7 @@ def add_swagger_documentation(options={}) @combined_routes = {} routes.each do |route| - resource = route.route_path.match('\/(\w*?)[\.\/\(]').captures.first + resource = route.route_path.match('\/([\w|-]*?)[\.\/\(]').captures.first next if resource.empty? resource.downcase! @combined_routes[resource] ||= [] diff --git a/spec/simple_mounted_api_spec.rb b/spec/simple_mounted_api_spec.rb index 451ee0de..f62bbe52 100644 --- a/spec/simple_mounted_api_spec.rb +++ b/spec/simple_mounted_api_spec.rb @@ -15,6 +15,14 @@ class SimpleMountedApi < Grape::API { bla: 'something' } end + desc 'This gets something for URL using - separator.', { + :notes => '_test_' + } + + get '/simple-test' do + { bla: 'something' } + end + desc 'this gets something else', { :headers => { "XAuthToken" => {description: "A required header.", required: true}, @@ -37,6 +45,7 @@ class SimpleMountedApi < Grape::API post '/items' do {} end + end class SimpleApi < Grape::API @@ -56,6 +65,7 @@ def app; SimpleApi end "operations" => [], "apis" => [ { "path" => "/swagger_doc/simple.{format}" }, + { "path" => "/swagger_doc/simple-test.{format}" }, { "path" => "/swagger_doc/simple_with_headers.{format}" }, { "path" => "/swagger_doc/items.{format}" }, { "path" => "/swagger_doc/swagger_doc.{format}" } @@ -81,6 +91,23 @@ def app; SimpleApi end } end + it "retrieves the documentation for mounted-api with '-' in URL" do + get '/swagger_doc/simple-test.json' + JSON.parse(last_response.body).should == { + "apiVersion" => "0.1", + "swaggerVersion" => "1.1", + "basePath" => "http://example.org", + "resourcePath" => "", + "apis" => [ + { + "path" => "/simple-test.{format}", + "operations" => [ + { "notes" => "_test_", "summary" => "This gets something for URL using - separator.", "nickname" => "GET-simple-test---format-", "httpMethod" => "GET", "parameters" => [] } + ] + } + ] + } + end it "retrieves the documentation for mounted-api that includes headers" do get '/swagger_doc/simple_with_headers.json' JSON.parse(last_response.body).should == {