Skip to content

Fix for tags for path versioned endpoints #447

New issue

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

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

Already on GitHub? # to your account

Merged
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#### Fixes

* [#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).
* Your contribution here.
* [#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).

### 0.21.0 (June 1, 2016)

Expand Down
6 changes: 3 additions & 3 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def method_object(route, options, path)
method[:consumes] = consumes_object(route, options[:format])
method[:parameters] = params_object(route)
method[:responses] = response_object(route, options[:markdown])
method[:tags] = tag_object(route, options[:version].to_s)
method[:tags] = tag_object(route)
method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path)
method.delete_if { |_, value| value.blank? }

Expand Down Expand Up @@ -194,8 +194,8 @@ def response_object(route, markdown)
end
end

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

private
Expand Down
37 changes: 19 additions & 18 deletions spec/swagger_v2/endpoint_versioned_path_spec.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
require 'spec_helper'

describe 'Grape::Endpoint#path_and_definitions' do
before do
module API
module V1
class Item < Grape::API
version 'v1', using: :path
let(:api) do
item = Class.new(Grape::API) do
version 'v1', using: :path

resource :item do
get '/'
end
end
end

class Root < Grape::API
mount API::V1::Item
add_swagger_documentation add_version: true
resource :item do
get '/'
end
end

@options = { add_version: true }
@target_routes = API::Root.combined_namespace_routes
Class.new(Grape::API) do
mount item
add_swagger_documentation add_version: true
end
end

let(:options) { { add_version: true } }
let(:target_routes) { api.combined_namespace_routes }

subject { api.endpoints[0].path_and_definition_objects(target_routes, options) }

it 'is returning a versioned path' do
expect(API::V1::Item.endpoints[0]
.path_and_definition_objects(@target_routes, @options)[0].keys[0]).to eql '/v1/item'
expect(subject[0].keys[0]).to eq '/v1/item'
end

it 'tags the endpoint with the resource name' do
expect(subject.first['/v1/item'][:get][:tags]).to eq ['item']
end
end