Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include in regex to capture URL with '-' in name #62

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rvmrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# First we specify our desired <ruby>[@<gemset>], 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
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] ||= []
Expand Down
27 changes: 27 additions & 0 deletions spec/simple_mounted_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -37,6 +45,7 @@ class SimpleMountedApi < Grape::API
post '/items' do
{}
end

end

class SimpleApi < Grape::API
Expand All @@ -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}" }
Expand All @@ -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 == {
Expand Down