Skip to content

Commit f2ac684

Browse files
Create an actual nickname instead of generating a random number.
Not super beautiful, but at least the swagger-ui history works properly now.
1 parent a1c329a commit f2ac684

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

lib/grape-swagger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def self.setup(options)
8585
:operations => [{
8686
:notes => notes,
8787
:summary => route.route_description || '',
88-
:nickname => Random.rand(1000000),
88+
:nickname => route.route_method + route.route_path.gsub(/[\/:\(\)\.]/,'-'),
8989
:httpMethod => route.route_method,
9090
:parameters => parse_params(route.route_params, route.route_path, route.route_method)
9191
}]

spec/non_default_api_spec.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ def app; SimpleApiWithBasePath end
2626
end
2727

2828
it "retrieves the same given base-path for mounted-api" do
29-
Random.stub(:rand) { 0 }
3029
get '/swagger_doc/something'
31-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"#{SimpleApiWithBasePath::NON_DEFAULT_BASE_PATH}\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
30+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"#{SimpleApiWithBasePath::NON_DEFAULT_BASE_PATH}\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>\"GET-something---format-\", :httpMethod=>\"GET\", :parameters=>[]}]}]}"
3231
end
3332
end
3433

@@ -57,9 +56,8 @@ def app; SimpleApiWithApiVersion end
5756
end
5857

5958
it "retrieves the same api version for mounted-api" do
60-
Random.stub(:rand) { 0 }
6159
get '/swagger_doc/something'
62-
last_response.body.should == "{:apiVersion=>\"#{SimpleApiWithApiVersion::API_VERSION}\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
60+
last_response.body.should == "{:apiVersion=>\"#{SimpleApiWithApiVersion::API_VERSION}\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>\"GET-something---format-\", :httpMethod=>\"GET\", :parameters=>[]}]}]}"
6361
end
6462
end
6563

@@ -88,9 +86,8 @@ def app; SimpleApiWithDifferentMount end
8886
end
8987

9088
it "retrieves the same given base-path for mounted-api" do
91-
Random.stub(:rand) { 0 }
9289
get '/api_doc/something'
93-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
90+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something\", :nickname=>\"GET-something---format-\", :httpMethod=>\"GET\", :parameters=>[]}]}]}"
9491
end
9592

9693
it "does not respond to swagger_doc" do
@@ -119,9 +116,8 @@ class SimpleApiWithMarkdown < Grape::API
119116
def app; SimpleApiWithMarkdown end
120117

121118
it "parses markdown for a mounted-api" do
122-
Random.stub(:rand) { 0 }
123119
get '/swagger_doc/something'
124-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>\"<p><em>test</em></p>\\n\", :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
120+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/something.{format}\", :operations=>[{:notes=>\"<p><em>test</em></p>\\n\", :summary=>\"this gets something\", :nickname=>\"GET-something---format-\", :httpMethod=>\"GET\", :parameters=>[]}]}]}"
125121
end
126122
end
127123

spec/simple_mounted_api_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def app; SimpleApi end
2525
end
2626

2727
it "retrieves the documentation for mounted-api" do
28-
Random.stub(:rand) { 0 }
2928
get '/swagger_doc/simple'
30-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/simple.{format}\", :operations=>[{:notes=>\"_test_\", :summary=>\"this gets something\", :nickname=>0, :httpMethod=>\"GET\", :parameters=>[]}]}]}"
29+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/simple.{format}\", :operations=>[{:notes=>\"_test_\", :summary=>\"this gets something\", :nickname=>\"GET-simple---format-\", :httpMethod=>\"GET\", :parameters=>[]}]}]}"
3130
end
3231
end

0 commit comments

Comments
 (0)