Skip to content

Commit d3a010d

Browse files
anakinjpeter scholz
authored and
peter scholz
committed
Fix for tags for path versioned endpoints (#447)
* Test for tags in a versioned endpoint * Use the version from route when tagging endpoints * Updated the CHANGELOG
1 parent 87dcdc4 commit d3a010d

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#### Fixes
88

99
* [#450](https://github.com/ruby-grape/grape-swagger/pull/438): Do not add :description to definitions if :description is missing on path - [@texpert](https://github.com/texpert).
10-
* Your contribution here.
10+
* [#447](https://github.com/ruby-grape/grape-swagger/pull/447): Version part of the url is now ignored when generating tags for endpoint - [@anakinj](https://github.com/anakinj).
1111

1212
### 0.21.0 (June 1, 2016)
1313

lib/grape-swagger/endpoint.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def method_object(route, options, path)
109109
method[:consumes] = consumes_object(route, options[:format])
110110
method[:parameters] = params_object(route)
111111
method[:responses] = response_object(route, options[:markdown])
112-
method[:tags] = tag_object(route, options[:version].to_s)
112+
method[:tags] = tag_object(route)
113113
method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path)
114114
method.delete_if { |_, value| value.blank? }
115115

@@ -194,8 +194,8 @@ def response_object(route, markdown)
194194
end
195195
end
196196

197-
def tag_object(route, version)
198-
Array(route.path.split('{')[0].split('/').reject(&:empty?).delete_if { |i| ((i == route.prefix.to_s) || (i == version)) }.first)
197+
def tag_object(route)
198+
Array(route.path.split('{')[0].split('/').reject(&:empty?).delete_if { |i| ((i == route.prefix.to_s) || (i == route.version)) }.first)
199199
end
200200

201201
private
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
require 'spec_helper'
22

33
describe 'Grape::Endpoint#path_and_definitions' do
4-
before do
5-
module API
6-
module V1
7-
class Item < Grape::API
8-
version 'v1', using: :path
4+
let(:api) do
5+
item = Class.new(Grape::API) do
6+
version 'v1', using: :path
97

10-
resource :item do
11-
get '/'
12-
end
13-
end
14-
end
15-
16-
class Root < Grape::API
17-
mount API::V1::Item
18-
add_swagger_documentation add_version: true
8+
resource :item do
9+
get '/'
1910
end
2011
end
2112

22-
@options = { add_version: true }
23-
@target_routes = API::Root.combined_namespace_routes
13+
Class.new(Grape::API) do
14+
mount item
15+
add_swagger_documentation add_version: true
16+
end
2417
end
2518

19+
let(:options) { { add_version: true } }
20+
let(:target_routes) { api.combined_namespace_routes }
21+
22+
subject { api.endpoints[0].path_and_definition_objects(target_routes, options) }
23+
2624
it 'is returning a versioned path' do
27-
expect(API::V1::Item.endpoints[0]
28-
.path_and_definition_objects(@target_routes, @options)[0].keys[0]).to eql '/v1/item'
25+
expect(subject[0].keys[0]).to eq '/v1/item'
26+
end
27+
28+
it 'tags the endpoint with the resource name' do
29+
expect(subject.first['/v1/item'][:get][:tags]).to eq ['item']
2930
end
3031
end

0 commit comments

Comments
 (0)