2
2
3
3
describe "a simple mounted api" do
4
4
before :all do
5
+ class CustomType ; end
6
+
5
7
class SimpleMountedApi < Grape ::API
6
8
desc "Document root"
7
9
get do
@@ -17,8 +19,8 @@ class SimpleMountedApi < Grape::API
17
19
18
20
desc 'this gets something else' , {
19
21
: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 }
22
24
} ,
23
25
:http_codes => {
24
26
403 => "invalid pony" ,
@@ -31,12 +33,21 @@ class SimpleMountedApi < Grape::API
31
33
32
34
desc 'this takes an array of parameters' , {
33
35
:params => {
34
- "items[]" => { : description => "array of items" }
36
+ "items[]" => { description : "array of items" }
35
37
}
36
38
}
37
39
post '/items' do
38
40
{ }
39
41
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
40
51
end
41
52
42
53
class SimpleApi < Grape ::API
@@ -58,6 +69,7 @@ def app; SimpleApi end
58
69
{ "path" => "/swagger_doc/simple.{format}" } ,
59
70
{ "path" => "/swagger_doc/simple_with_headers.{format}" } ,
60
71
{ "path" => "/swagger_doc/items.{format}" } ,
72
+ { "path" => "/swagger_doc/custom.{format}" } ,
61
73
{ "path" => "/swagger_doc/swagger_doc.{format}" }
62
74
]
63
75
}
@@ -81,59 +93,62 @@ def app; SimpleApi end
81
93
}
82
94
end
83
95
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
114
119
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
117
151
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
- }
138
152
end
153
+
139
154
end
0 commit comments