Skip to content

Commit

Permalink
Revert removal of swagger_doc prefix in apis listing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Vandecasteele committed Feb 5, 2014
1 parent 1936d64 commit ff90e1c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
7 changes: 3 additions & 4 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ def self.setup(options)
routes_array = routes.keys.map do |local_route|
next if routes[local_route].all?(&:route_hidden)

parsed_path = route.route_version ? "/#{route.route_version}" : ""
parsed_path += "/#{local_route}"
parsed_path += '.{format}' unless @@hide_format
url_base = parse_path(route.route_path.gsub('(.:format)', ''), route.route_version) if include_base_url
url_format = '.{format}' unless @@hide_format
{
:path => parsed_path,
:path => "#{url_base}/#{local_route}#{url_format}",
#:description => "..."
}
end.compact
Expand Down
6 changes: 3 additions & 3 deletions spec/api_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def app; ModelsApi; end
"produces" => ["application/json"],
"operations" => [],
"apis" => [
{ "path" => "/something.{format}" },
{ "path" => "/thing.{format}" },
{ "path" => "/swagger_doc.{format}" }
{ "path" => "/swagger_doc/something.{format}" },
{ "path" => "/swagger_doc/thing.{format}" },
{ "path" => "/swagger_doc/swagger_doc.{format}" }
]
}
end
Expand Down
4 changes: 2 additions & 2 deletions spec/default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def app; NotAMountedApi; end
"produces" => ["application/json"],
"operations" => [],
"apis" => [
{ "path" => "/something.{format}" },
{ "path" => "/swagger_doc.{format}" }
{ "path" => "/swagger_doc/something.{format}" },
{ "path" => "/swagger_doc/swagger_doc.{format}" }
]
}
end
Expand Down
8 changes: 4 additions & 4 deletions spec/hide_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def app; HideApi end
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/simple.{format}" },
{ "path" => "/swagger_doc.{format}" }
{ "path" => "/swagger_doc/simple.{format}" },
{ "path" => "/swagger_doc/swagger_doc.{format}" }
]
}
end
Expand Down Expand Up @@ -76,8 +76,8 @@ def app; HideNamespaceApi end
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/simple.{format}" },
{ "path" => "/swagger_doc.{format}" }
{ "path" => "/swagger_doc/simple.{format}" },
{ "path" => "/swagger_doc/swagger_doc.{format}" }
]
}
end
Expand Down
19 changes: 13 additions & 6 deletions spec/non_default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def app; SimpleApiWithVersionInPath end
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/v1/something.{format}" },
{ "path" => "/v1/swagger_doc.{format}" }
{ "path" => "/v1/swagger_doc/something.{format}" },
{ "path" => "/v1/swagger_doc/swagger_doc.{format}" }
]
}
end
Expand Down Expand Up @@ -211,7 +211,7 @@ def app; SimpleApiWithHiddenDocumentation end
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/something.{format}" }
{ "path" => "/swagger_doc/something.{format}" }
]
}
end
Expand Down Expand Up @@ -326,6 +326,13 @@ class SimpleApiWithDifferentMount < Grape::API
def app; SimpleApiWithDifferentMount end


it "retrieves the given base-path on /api_doc" do
get '/api_doc.json'
JSON.parse(last_response.body)["apis"].each do |api|
api["path"].should start_with SimpleApiWithDifferentMount::MOUNT_PATH
end
end

it "retrieves the same given base-path for mounted-api" do
get '/api_doc/something.json'
JSON.parse(last_response.body)["apis"].each do |api|
Expand Down Expand Up @@ -500,12 +507,12 @@ def app; SimpleApiWithMultipleMountedDocumentations; end
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/first.{format}" }
{ "path" => "/first/swagger_doc/first.{format}" }
]
}
end

it "retrieves the first swagger-documentation on /second/swagger_doc" do
it "retrieves the second swagger-documentation on /second/swagger_doc" do
get '/second/swagger_doc.json'
JSON.parse(last_response.body).should == {
"apiVersion" => "0.1",
Expand All @@ -515,7 +522,7 @@ def app; SimpleApiWithMultipleMountedDocumentations; end
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/second.{format}" }
{ "path" => "/second/swagger_doc/second.{format}" }
]
}
end
Expand Down
12 changes: 6 additions & 6 deletions spec/simple_mounted_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def app; SimpleApi end
"produces" => ["application/xml", "application/json", "text/plain"],
"operations" => [],
"apis" => [
{ "path" => "/simple.{format}" },
{ "path" => "/simple-test.{format}" },
{ "path" => "/simple_with_headers.{format}" },
{ "path" => "/items.{format}" },
{ "path" => "/custom.{format}" },
{ "path" => "/swagger_doc.{format}" }
{ "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/custom.{format}" },
{ "path" => "/swagger_doc/swagger_doc.{format}" }
]
}
end
Expand Down

0 comments on commit ff90e1c

Please sign in to comment.