22
33describe "a simple mounted api" do
44 before :all do
5+ class CustomType ; end
6+
57 class SimpleMountedApi < Grape ::API
68 desc "Document root"
79 get do
@@ -17,8 +19,8 @@ class SimpleMountedApi < Grape::API
1719
1820 desc 'this gets something else' , {
1921 :headers => {
20- "XAuthToken" => { description : "A required header." , required : true } ,
21- "XOtherHeader" => { description : "An optional header." , required : false }
22+ "XAuthToken" => { description : "A required header." , required : true } ,
23+ "XOtherHeader" => { description : "An optional header." , required : false }
2224 } ,
2325 :http_codes => {
2426 403 => "invalid pony" ,
@@ -31,12 +33,21 @@ class SimpleMountedApi < Grape::API
3133
3234 desc 'this takes an array of parameters' , {
3335 :params => {
34- "items[]" => { : description => "array of items" }
36+ "items[]" => { description : "array of items" }
3537 }
3638 }
3739 post '/items' do
3840 { }
3941 end
42+
43+ desc 'this uses a custom parameter' , {
44+ :params => {
45+ "custom" => { type : CustomType , description : "array of items" }
46+ }
47+ }
48+ get '/custom' do
49+ { }
50+ end
4051 end
4152
4253 class SimpleApi < Grape ::API
@@ -58,6 +69,7 @@ def app; SimpleApi end
5869 { "path" => "/swagger_doc/simple.{format}" } ,
5970 { "path" => "/swagger_doc/simple_with_headers.{format}" } ,
6071 { "path" => "/swagger_doc/items.{format}" } ,
72+ { "path" => "/swagger_doc/custom.{format}" } ,
6173 { "path" => "/swagger_doc/swagger_doc.{format}" }
6274 ]
6375 }
@@ -81,59 +93,62 @@ def app; SimpleApi end
8193 }
8294 end
8395
84- it "retrieves the documentation for mounted-api that includes headers" do
85- get '/swagger_doc/simple_with_headers.json'
86- JSON . parse ( last_response . body ) . should == {
87- "apiVersion" => "0.1" ,
88- "swaggerVersion" => "1.1" ,
89- "basePath" => "http://example.org" ,
90- "resourcePath" => "" ,
91- "apis" => [
92- {
93- "path" => "/simple_with_headers.{format}" ,
94- "operations" => [
95- {
96- "notes" => nil ,
97- "summary" => "this gets something else" ,
98- "nickname" => "GET-simple_with_headers---format-" ,
99- "httpMethod" => "GET" ,
100- "parameters" => [
101- { "paramType" => "header" , "name" => "XAuthToken" , "description" => "A required header." , "dataType" => "String" , "required" => true } ,
102- { "paramType" => "header" , "name" => "XOtherHeader" , "description" => "An optional header." , "dataType" => "String" , "required" => false }
103- ] ,
104- "errorResponses" => [
105- { "code" => 403 , "reason" => "invalid pony" } ,
106- { "code" => 405 , "reason" => "no ponies left!" }
107- ]
108- }
109- ]
110- }
111- ]
112- }
113- end
96+ context "retrieves the documentation for mounted-api that" do
97+ it "includes headers" do
98+ get '/swagger_doc/simple_with_headers.json'
99+ JSON . parse ( last_response . body ) [ "apis" ] . should == [ {
100+ "path" => "/simple_with_headers.{format}" ,
101+ "operations" => [
102+ {
103+ "notes" => nil ,
104+ "summary" => "this gets something else" ,
105+ "nickname" => "GET-simple_with_headers---format-" ,
106+ "httpMethod" => "GET" ,
107+ "parameters" => [
108+ { "paramType" => "header" , "name" => "XAuthToken" , "description" => "A required header." , "dataType" => "String" , "required" => true } ,
109+ { "paramType" => "header" , "name" => "XOtherHeader" , "description" => "An optional header." , "dataType" => "String" , "required" => false }
110+ ] ,
111+ "errorResponses" => [
112+ { "code" => 403 , "reason" => "invalid pony" } ,
113+ { "code" => 405 , "reason" => "no ponies left!" }
114+ ]
115+ }
116+ ]
117+ } ]
118+ end
114119
115- it "retrieves the documentation for mounted-api that supports multiple parameters" do
116- get '/swagger_doc/items.json'
120+ it "retrieves the documentation for mounted-api that supports multiple parameters" do
121+ get '/swagger_doc/items.json'
122+ JSON . parse ( last_response . body ) [ "apis" ] . should == [ {
123+ "path" => "/items.{format}" ,
124+ "operations" => [
125+ {
126+ "notes" => nil ,
127+ "summary" => "this takes an array of parameters" ,
128+ "nickname" => "POST-items---format-" ,
129+ "httpMethod" => "POST" ,
130+ "parameters" => [ { "paramType" => "form" , "name" => "items[]" , "description" => "array of items" , "dataType" => "String" , "required" => false } ]
131+ }
132+ ]
133+ } ]
134+ end
135+
136+ it "supports custom types" do
137+ get '/swagger_doc/custom.json'
138+ JSON . parse ( last_response . body ) [ "apis" ] . should == [ {
139+ "path" => "/custom.{format}" ,
140+ "operations" => [
141+ {
142+ "notes" => nil ,
143+ "summary" => "this uses a custom parameter" ,
144+ "nickname" => "GET-custom---format-" ,
145+ "httpMethod" => "GET" ,
146+ "parameters" => [ { "paramType" => "query" , "name" => "custom" , "description" => "array of items" , "dataType" => "CustomType" , "required" => false } ]
147+ }
148+ ]
149+ } ]
150+ end
117151
118- JSON . parse ( last_response . body ) . should == {
119- "apiVersion" => "0.1" ,
120- "swaggerVersion" => "1.1" ,
121- "basePath" => "http://example.org" ,
122- "resourcePath" => "" ,
123- "apis" => [
124- {
125- "path" => "/items.{format}" ,
126- "operations" => [
127- {
128- "notes" => nil ,
129- "summary" => "this takes an array of parameters" ,
130- "nickname" => "POST-items---format-" ,
131- "httpMethod" => "POST" ,
132- "parameters" => [ { "paramType" => "form" , "name" => "items[]" , "description" => "array of items" , "dataType" => "String" , "required" => false } ]
133- }
134- ]
135- }
136- ]
137- }
138152 end
153+
139154end
0 commit comments