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

added support for nicknamed routes #483

Merged
merged 6 commits into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def method_object(route, options, path)
method[:parameters] = params_object(route)
method[:responses] = response_object(route, options[:markdown])
method[:tags] = tag_object(route)
method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path)
method[:operationId] = operation_id(route, path)
method.delete_if { |_, value| value.blank? }

[route.request_method.downcase.to_sym, method]
Expand All @@ -133,6 +133,12 @@ def description_object(route, markdown)

description
end

def operation_id(route, path)
operation_id = route.options[:nickname] || GrapeSwagger::DocMethods::OperationId.build(route, path)

operation_id
end

def produces_object(route, format)
mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format)
Expand Down
30 changes: 30 additions & 0 deletions spec/swagger_v2/nicknamed_api_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'

describe 'a nicknamed mounted api' do
before :all do
Copy link
Contributor

@kzaitsev kzaitsev Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use let!(:app)

class NicknamedMountedApi < Grape::API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should be Class.new(Grape::API) do, thanks

desc 'Show this endpoint', nickname: 'simple'
get '/simple' do
{ foo: 'bar' }
end
end

class NicknamedApi < Grape::API
mount NicknamedMountedApi
add_swagger_documentation
end
end

def app
NicknamedApi
end

subject do
get '/swagger_doc.json'
JSON.parse(last_response.body)
end

it "uses the nickname as the operationId" do
expect(subject['paths']['/simple']['get']['operationId']).to eql('simple')
end
end