grape-swagger 0.11.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +8 -1
  3. data/.rubocop.yml +3 -0
  4. data/.rubocop_todo.yml +14 -22
  5. data/.travis.yml +7 -4
  6. data/CHANGELOG.md +53 -26
  7. data/Gemfile +1 -1
  8. data/README.md +414 -327
  9. data/RELEASING.md +3 -4
  10. data/example/api/endpoints.rb +132 -0
  11. data/example/api/entities.rb +18 -0
  12. data/example/config.ru +36 -2
  13. data/example/example_requests.postman_collection +146 -0
  14. data/example/swagger-example.png +0 -0
  15. data/grape-swagger.gemspec +9 -6
  16. data/lib/grape-swagger.rb +69 -99
  17. data/lib/grape-swagger/doc_methods.rb +69 -544
  18. data/lib/grape-swagger/doc_methods/data_type.rb +77 -0
  19. data/lib/grape-swagger/doc_methods/extensions.rb +75 -0
  20. data/lib/grape-swagger/doc_methods/move_params.rb +153 -0
  21. data/lib/grape-swagger/doc_methods/operation_id.rb +27 -0
  22. data/lib/grape-swagger/doc_methods/optional_object.rb +15 -0
  23. data/lib/grape-swagger/doc_methods/parse_params.rb +113 -0
  24. data/lib/grape-swagger/doc_methods/path_string.rb +29 -0
  25. data/lib/grape-swagger/doc_methods/produces_consumes.rb +12 -0
  26. data/lib/grape-swagger/doc_methods/status_codes.rb +17 -0
  27. data/lib/grape-swagger/doc_methods/tag_name_description.rb +26 -0
  28. data/lib/grape-swagger/endpoint.rb +317 -0
  29. data/lib/grape-swagger/version.rb +1 -1
  30. data/spec/lib/data_type_spec.rb +57 -0
  31. data/spec/lib/endpoint_spec.rb +6 -0
  32. data/spec/lib/extensions_spec.rb +127 -0
  33. data/spec/lib/move_params_spec.rb +298 -0
  34. data/spec/lib/operation_id_spec.rb +24 -0
  35. data/spec/lib/optional_object_spec.rb +40 -0
  36. data/spec/lib/path_string_spec.rb +38 -0
  37. data/spec/lib/produces_consumes_spec.rb +98 -0
  38. data/spec/markdown/kramdown_adapter_spec.rb +2 -9
  39. data/spec/markdown/redcarpet_adapter_spec.rb +2 -16
  40. data/spec/spec_helper.rb +7 -13
  41. data/spec/support/api_swagger_v2_result.rb +204 -0
  42. data/spec/support/namespace_tags.rb +73 -0
  43. data/spec/support/the_api_entities.rb +52 -0
  44. data/spec/support/the_paths_definitions.rb +94 -0
  45. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +32 -0
  46. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +151 -0
  47. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +109 -0
  48. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +124 -0
  49. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +51 -0
  50. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +44 -0
  51. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +56 -0
  52. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +146 -0
  53. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +197 -0
  54. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +151 -0
  55. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +217 -0
  56. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +64 -0
  57. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +184 -0
  58. data/spec/swagger_v2/api_swagger_v2_spec.rb +207 -0
  59. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +121 -0
  60. data/spec/{boolean_params_spec.rb → swagger_v2/boolean_params_spec.rb} +2 -2
  61. data/spec/{default_api_spec.rb → swagger_v2/default_api_spec.rb} +40 -36
  62. data/spec/swagger_v2/description_not_initialized.rb +39 -0
  63. data/spec/{float_api_spec.rb → swagger_v2/float_api_spec.rb} +2 -2
  64. data/spec/{form_params_spec.rb → swagger_v2/form_params_spec.rb} +9 -9
  65. data/spec/{grape-swagger_spec.rb → swagger_v2/grape-swagger_spec.rb} +0 -0
  66. data/spec/swagger_v2/hide_api_spec.rb +131 -0
  67. data/spec/swagger_v2/mounted_target_class_spec.rb +76 -0
  68. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +84 -0
  69. data/spec/swagger_v2/namespace_tags_spec.rb +76 -0
  70. data/spec/{namespaced_api_spec.rb → swagger_v2/namespaced_api_spec.rb} +6 -26
  71. data/spec/{param_type_spec.rb → swagger_v2/param_type_spec.rb} +10 -8
  72. data/spec/{param_values_spec.rb → swagger_v2/param_values_spec.rb} +52 -22
  73. data/spec/swagger_v2/params_array_spec.rb +63 -0
  74. data/spec/swagger_v2/params_hash_spec.rb +65 -0
  75. data/spec/swagger_v2/params_nested_spec.rb +63 -0
  76. data/spec/{reference_entity.rb → swagger_v2/reference_entity.rb} +18 -23
  77. data/spec/swagger_v2/response_model_spec.rb +212 -0
  78. data/spec/swagger_v2/simple_mounted_api_spec.rb +264 -0
  79. metadata +175 -90
  80. data/example/api.rb +0 -66
  81. data/lib/grape-swagger/markdown.rb +0 -23
  82. data/spec/api_description_spec.rb +0 -43
  83. data/spec/api_global_models_spec.rb +0 -77
  84. data/spec/api_models_spec.rb +0 -364
  85. data/spec/api_paths_spec.rb +0 -128
  86. data/spec/api_root_spec.rb +0 -30
  87. data/spec/api_with_nil_types.rb +0 -50
  88. data/spec/api_with_path_versioning_spec.rb +0 -33
  89. data/spec/api_with_prefix_and_namespace_spec.rb +0 -32
  90. data/spec/api_with_standalone_namespace_spec.rb +0 -215
  91. data/spec/array_entity_spec.rb +0 -34
  92. data/spec/array_params_spec.rb +0 -85
  93. data/spec/grape-swagger_helper_spec.rb +0 -152
  94. data/spec/group_params_spec.rb +0 -31
  95. data/spec/hash_params_spec.rb +0 -30
  96. data/spec/hide_api_spec.rb +0 -124
  97. data/spec/i18n_spec.rb +0 -364
  98. data/spec/markdown/markdown_spec.rb +0 -27
  99. data/spec/mounted_target_class_spec.rb +0 -63
  100. data/spec/mutually_exclusive_spec.rb +0 -36
  101. data/spec/non_default_api_spec.rb +0 -733
  102. data/spec/response_model_spec.rb +0 -121
  103. data/spec/simple_mounted_api_spec.rb +0 -213
  104. data/spec/support/i18n_helper.rb +0 -8
@@ -0,0 +1,212 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'responseModel' do
4
+ before :all do
5
+ module ThisApi
6
+ module Entities
7
+ class Kind < Grape::Entity
8
+ expose :title, documentation: { type: 'string', desc: 'Title of the kind.' }
9
+ end
10
+
11
+ class Relation < Grape::Entity
12
+ expose :name, documentation: { type: 'string', desc: 'Name' }
13
+
14
+ end
15
+ class Tag < Grape::Entity
16
+ expose :name, documentation: { type: 'string', desc: 'Name' }
17
+
18
+ end
19
+ class Error < Grape::Entity
20
+ expose :code, documentation: { type: 'string', desc: 'Error code' }
21
+ expose :message, documentation: { type: 'string', desc: 'Error message' }
22
+ end
23
+
24
+ class Something < Grape::Entity
25
+ expose :text, documentation: { type: 'string', desc: 'Content of something.' }
26
+ expose :kind, using: Kind, documentation: { type: 'ThisApi::Kind', desc: 'The kind of this something.' }
27
+ expose :kind2, using: Kind, documentation: { desc: 'Secondary kind.' }
28
+ expose :kind3, using: ThisApi::Entities::Kind, documentation: { desc: 'Tertiary kind.' }
29
+ expose :tags, using: ThisApi::Entities::Tag, documentation: { desc: 'Tags.', is_array: true }
30
+ expose :relation, using: ThisApi::Entities::Relation, documentation: { type: 'ThisApi::Relation', desc: 'A related model.' }
31
+ end
32
+ end
33
+
34
+ class ResponseModelApi < Grape::API
35
+ format :json
36
+ desc 'This returns something',
37
+ is_array: true,
38
+ http_codes: [ { code: 200, message: 'OK', model: Entities::Something } ]
39
+ get '/something' do
40
+ something = OpenStruct.new text: 'something'
41
+ present something, with: Entities::Something
42
+ end
43
+
44
+ # something like an index action
45
+ desc 'This returns something or an error',
46
+ entity: Entities::Something,
47
+ http_codes: [
48
+ { code: 200, message: 'OK', model: Entities::Something },
49
+ { code: 403, message: 'Refused to return something', model: Entities::Error }
50
+ ]
51
+ params do
52
+ optional :id, type: Integer
53
+ end
54
+ get '/something/:id' do
55
+ if params[:id] == 1
56
+ something = OpenStruct.new text: 'something'
57
+ present something, with: Entities::Something
58
+ else
59
+ error = OpenStruct.new code: 'some_error', message: 'Some error'
60
+ present error, with: Entities::Error
61
+ end
62
+ end
63
+
64
+ add_swagger_documentation
65
+ end
66
+ end
67
+ end
68
+
69
+ def app
70
+ ThisApi::ResponseModelApi
71
+ end
72
+
73
+ subject do
74
+ get '/swagger_doc/something'
75
+ JSON.parse(last_response.body)
76
+ end
77
+
78
+ it "documents index action" do
79
+ expect(subject['paths']["/something"]["get"]["responses"]).to eq(
80
+ {
81
+ "200"=>{
82
+ "description"=>"OK",
83
+ "schema"=>{
84
+ "type"=>"array",
85
+ "items"=>{"$ref"=>"#/definitions/Something"}}
86
+ }}
87
+ )
88
+ end
89
+
90
+ it 'should document specified models as show action' do
91
+ expect(subject['paths']["/something/{id}"]["get"]["responses"]).to eq(
92
+ {
93
+ "200"=>{
94
+ "description"=>"OK",
95
+ "schema"=>{"$ref"=>"#/definitions/Something"}
96
+ },
97
+ "403"=>{
98
+ "description"=>"Refused to return something",
99
+ "schema"=>{"$ref"=>"#/definitions/Error"}
100
+ }}
101
+ )
102
+ expect(subject['definitions'].keys).to include 'Error'
103
+ expect(subject['definitions']['Error']).to eq(
104
+ {
105
+ "type"=>"object",
106
+ "description" => "This returns something or an error",
107
+ "properties"=>{
108
+ "code"=>{"type"=>"string"},
109
+ "message"=>{"type"=>"string"}
110
+ }}
111
+ )
112
+
113
+ expect(subject['definitions'].keys).to include 'Something'
114
+ expect(subject['definitions']['Something']).to eq(
115
+ { "type"=>"object",
116
+ "description" => "This returns something or an error",
117
+ "properties"=>
118
+ { "text"=>{"type"=>"string"},
119
+ "kind"=>{"$ref"=>"#/definitions/Kind"},
120
+ "kind2"=>{"$ref"=>"#/definitions/Kind"},
121
+ "kind3"=>{"$ref"=>"#/definitions/Kind"},
122
+ "tags"=>{"type"=>"array", "items"=>{"$ref"=>"#/definitions/Tag"}},
123
+ "relation"=>{"$ref"=>"#/definitions/Relation"}}}
124
+ )
125
+
126
+ expect(subject['definitions'].keys).to include 'Kind'
127
+ expect(subject['definitions']['Kind']).to eq(
128
+ "type"=>"object", "properties"=>{"title"=>{"type"=>"string"}}
129
+ )
130
+
131
+ expect(subject['definitions'].keys).to include 'Relation'
132
+ expect(subject['definitions']['Relation']).to eq(
133
+ "type"=>"object", "properties"=>{"name"=>{"type"=>"string"}}
134
+ )
135
+
136
+ expect(subject['definitions'].keys).to include 'Tag'
137
+ expect(subject['definitions']['Tag']).to eq(
138
+ "type"=>"object", "properties"=>{"name"=>{"type"=>"string"}}
139
+ )
140
+ end
141
+ end
142
+
143
+ describe 'should build definition from given entity' do
144
+ before :all do
145
+ module TheseApi
146
+ module Entities
147
+ class Kind < Grape::Entity
148
+ expose :id, documentation: { type: Integer, desc: 'Title of the kind.' }
149
+ end
150
+
151
+ class Relation < Grape::Entity
152
+ expose :name, documentation: { type: String, desc: 'Name' }
153
+
154
+ end
155
+ class Tag < Grape::Entity
156
+ expose :name, documentation: { type: 'string', desc: 'Name' }
157
+
158
+ end
159
+
160
+ class SomeEntity < Grape::Entity
161
+ expose :text, documentation: { type: 'string', desc: 'Content of something.' }
162
+ expose :kind, using: Kind, documentation: { type: 'TheseApi::Kind', desc: 'The kind of this something.' }
163
+ expose :kind2, using: Kind, documentation: { desc: 'Secondary kind.' }
164
+ expose :kind3, using: TheseApi::Entities::Kind, documentation: { desc: 'Tertiary kind.' }
165
+ expose :tags, using: TheseApi::Entities::Tag, documentation: { desc: 'Tags.', is_array: true }
166
+ expose :relation, using: TheseApi::Entities::Relation, documentation: { type: 'TheseApi::Relation', desc: 'A related model.' }
167
+ end
168
+ end
169
+
170
+ class ResponseEntityApi < Grape::API
171
+ format :json
172
+ desc 'This returns something',
173
+ is_array: true,
174
+ entity: Entities::SomeEntity
175
+ get '/some_entity' do
176
+ something = OpenStruct.new text: 'something'
177
+ present something, with: Entities::SomeEntity
178
+ end
179
+
180
+ add_swagger_documentation
181
+ end
182
+ end
183
+ end
184
+
185
+ def app
186
+ TheseApi::ResponseEntityApi
187
+ end
188
+
189
+ subject do
190
+ get '/swagger_doc'
191
+ JSON.parse(last_response.body)
192
+ end
193
+
194
+ it "it prefer entity over others" do
195
+ expect(subject['definitions']).to eql({
196
+ "Kind"=>{"type"=>"object", "properties"=>{"id"=>{"type"=>"integer", "format"=>"int32"}}},
197
+ "Tag"=>{"type"=>"object", "properties"=>{"name"=>{"type"=>"string"}}},
198
+ "Relation"=>{"type"=>"object", "properties"=>{"name"=>{"type"=>"string"}}},
199
+ "SomeEntity"=>{
200
+ "type"=>"object",
201
+ "properties"=>{
202
+ "text"=>{"type"=>"string"},
203
+ "kind"=>{"$ref"=>"#/definitions/Kind"},
204
+ "kind2"=>{"$ref"=>"#/definitions/Kind"},
205
+ "kind3"=>{"$ref"=>"#/definitions/Kind"},
206
+ "tags"=>{"type"=>"array", "items"=>{"$ref"=>"#/definitions/Tag"}},
207
+ "relation"=>{"$ref"=>"#/definitions/Relation"}
208
+ },
209
+ "description"=>"This returns something"
210
+ }})
211
+ end
212
+ end
@@ -0,0 +1,264 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'a simple mounted api' do
4
+ before :all do
5
+ class CustomType; end
6
+
7
+ class SimpleMountedApi < Grape::API
8
+ desc 'Document root'
9
+ get do
10
+ end
11
+
12
+ desc 'This gets something.',
13
+ notes: '_test_'
14
+
15
+ get '/simple' do
16
+ { bla: 'something' }
17
+ end
18
+
19
+ desc 'This gets something for URL using - separator.',
20
+ notes: '_test_'
21
+
22
+ get '/simple-test' do
23
+ { bla: 'something' }
24
+ end
25
+
26
+ desc 'this gets something else',
27
+ headers: {
28
+ 'XAuthToken' => { description: 'A required header.', required: true },
29
+ 'XOtherHeader' => { description: 'An optional header.', required: false }
30
+ },
31
+ http_codes: [
32
+ { code: 403, message: 'invalid pony' },
33
+ { code: 405, message: 'no ponies left!' }
34
+ ]
35
+
36
+ get '/simple_with_headers' do
37
+ { bla: 'something_else' }
38
+ end
39
+
40
+ desc 'this takes an array of parameters',
41
+ params: {
42
+ 'items[]' => { description: 'array of items', is_array: true }
43
+ }
44
+
45
+ post '/items' do
46
+ {}
47
+ end
48
+
49
+ desc 'this uses a custom parameter',
50
+ params: {
51
+ 'custom' => { type: CustomType, description: 'array of items', is_array: true }
52
+ }
53
+
54
+ get '/custom' do
55
+ {}
56
+ end
57
+ end
58
+
59
+ class SimpleApi < Grape::API
60
+ mount SimpleMountedApi
61
+ add_swagger_documentation
62
+ end
63
+ end
64
+
65
+ def app
66
+ SimpleApi
67
+ end
68
+
69
+ describe "retrieves swagger-documentation on /swagger_doc" do
70
+ subject do
71
+ get '/swagger_doc.json'
72
+ JSON.parse(last_response.body)
73
+ end
74
+
75
+ specify do
76
+ expect(subject).to eq({
77
+ "info"=>{"title"=>"API title", "version"=>"v1"},
78
+ "swagger"=>"2.0",
79
+ "produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
80
+ "host"=>"example.org",
81
+ "tags" => [{"name"=>"simple", "description"=>"Operations about simples"}, {"name"=>"simple-test", "description"=>"Operations about simple-tests"}, {"name"=>"simple_with_headers", "description"=>"Operations about simple_with_headers"}, {"name"=>"items", "description"=>"Operations about items"}, {"name"=>"custom", "description"=>"Operations about customs"}],
82
+ "schemes"=>["https", "http"],
83
+ "paths"=>{
84
+ "/simple"=>{
85
+ "get"=>{
86
+ "description"=>"This gets something.",
87
+ "produces"=>["application/json"],
88
+ "tags"=>["simple"],
89
+ "operationId"=>"getSimple",
90
+ "responses"=>{"200"=>{"description"=>"This gets something."}}}},
91
+ "/simple-test"=>{
92
+ "get"=>{
93
+ "description"=>"This gets something for URL using - separator.",
94
+ "produces"=>["application/json"],
95
+ "tags"=>["simple-test"],
96
+ "operationId"=>"getSimpleTest",
97
+ "responses"=>{"200"=>{"description"=>"This gets something for URL using - separator."}}}},
98
+ "/simple_with_headers"=>{
99
+ "get"=>{
100
+ "description"=>"this gets something else",
101
+ "headers"=>{
102
+ "XAuthToken"=>{"description"=>"A required header.", "required"=>true},
103
+ "XOtherHeader"=>{"description"=>"An optional header.", "required"=>false}},
104
+ "produces"=>["application/json"],
105
+ "tags"=>["simple_with_headers"],
106
+ "operationId"=>"getSimpleWithHeaders",
107
+ "responses"=>{
108
+ "200"=>{"description"=>"this gets something else"},
109
+ "403"=>{"description"=>"invalid pony"},
110
+ "405"=>{"description"=>"no ponies left!"}}
111
+ }},
112
+ "/items"=>{
113
+ "post"=>{
114
+ "description"=>"this takes an array of parameters",
115
+ "produces"=>["application/json"],
116
+ "consumes"=>["application/json"],
117
+ "parameters"=>[{"in"=>"formData", "name"=>"items[]", "description"=>"array of items", "required"=>false, "type"=>"array", "items"=>{"type"=>"string"}}],
118
+ "tags"=>["items"],
119
+ "operationId"=>"postItems",
120
+ "responses"=>{"201"=>{"description"=>"this takes an array of parameters", "schema"=>{"$ref"=>"#/definitions/Item"}}}
121
+ }},
122
+ "/custom"=>{
123
+ "get"=>{
124
+ "description"=>"this uses a custom parameter",
125
+ "produces"=>["application/json"],
126
+ "parameters"=>[{"in"=>"formData", "name"=>"custom", "description"=>"array of items", "required"=>false, "type"=>"array", "items"=>{"type"=>"CustomType"}}],
127
+ "tags"=>["custom"],
128
+ "operationId"=>"getCustom",
129
+ "responses"=>{"200"=>{"description"=>"this uses a custom parameter", "schema"=>{"$ref"=>"#/definitions/Custom"}}}}
130
+ }},
131
+ "definitions"=>{
132
+ "Item"=>{
133
+ "type"=>"object",
134
+ "properties"=>{"items[]"=>{"type"=>"string"}},
135
+ "description"=>"this takes an array of parameters"
136
+ },
137
+ "Custom"=>{
138
+ "type"=>"object",
139
+ "properties"=>{"custom"=>{"type"=>"CustomType"}},
140
+ "description"=>"this uses a custom parameter"
141
+ }}})
142
+ end
143
+ end
144
+
145
+ describe 'retrieves the documentation for mounted-api' do
146
+ subject do
147
+ get '/swagger_doc/simple.json'
148
+ JSON.parse(last_response.body)
149
+ end
150
+
151
+ specify do
152
+ expect(subject).to eq({
153
+ "info"=>{"title"=>"API title", "version"=>"v1"},
154
+ "swagger"=>"2.0",
155
+ "produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
156
+ "host"=>"example.org",
157
+ "tags" => [{"name"=>"simple", "description"=>"Operations about simples"}, {"name"=>"simple-test", "description"=>"Operations about simple-tests"}, {"name"=>"simple_with_headers", "description"=>"Operations about simple_with_headers"}, {"name"=>"items", "description"=>"Operations about items"}, {"name"=>"custom", "description"=>"Operations about customs"}],
158
+ "schemes"=>["https", "http"],
159
+ "paths"=>{
160
+ "/simple"=>{
161
+ "get"=>{
162
+ "description"=>"This gets something.",
163
+ "produces"=>["application/json"],
164
+ "tags"=>["simple"],
165
+ "operationId"=>"getSimple",
166
+ "responses"=>{"200"=>{"description"=>"This gets something."}}}}
167
+ }})
168
+ end
169
+ end
170
+
171
+ describe 'retrieves the documentation for mounted-api that' do
172
+ describe "contains '-' in URL" do
173
+ subject do
174
+ get '/swagger_doc/simple-test.json'
175
+ JSON.parse(last_response.body)
176
+ end
177
+
178
+ specify do
179
+ expect(subject).to eq({
180
+ "info"=>{"title"=>"API title", "version"=>"v1"},
181
+ "swagger"=>"2.0",
182
+ "produces"=>["application/xml", "application/json", "application/octet-stream", "text/plain"],
183
+ "host"=>"example.org",
184
+ "tags" => [{"name"=>"simple", "description"=>"Operations about simples"}, {"name"=>"simple-test", "description"=>"Operations about simple-tests"}, {"name"=>"simple_with_headers", "description"=>"Operations about simple_with_headers"}, {"name"=>"items", "description"=>"Operations about items"}, {"name"=>"custom", "description"=>"Operations about customs"}],
185
+ "schemes"=>["https", "http"],
186
+ "paths"=>{
187
+ "/simple-test"=>{
188
+ "get"=>{
189
+ "description"=>"This gets something for URL using - separator.",
190
+ "produces"=>["application/json"],
191
+ "tags"=>["simple-test"],
192
+ "operationId"=>"getSimpleTest",
193
+ "responses"=>{"200"=>{"description"=>"This gets something for URL using - separator."}}}}
194
+ }})
195
+ end
196
+ end
197
+
198
+ describe 'includes headers' do
199
+ subject do
200
+ get '/swagger_doc/simple_with_headers.json'
201
+ JSON.parse(last_response.body)
202
+ end
203
+
204
+ specify do
205
+ expect(subject['paths']).to eq({
206
+ "/simple_with_headers"=>{
207
+ "get"=>{
208
+ "description"=>"this gets something else",
209
+ "headers"=>{
210
+ "XAuthToken"=>{"description"=>"A required header.", "required"=>true},
211
+ "XOtherHeader"=>{"description"=>"An optional header.", "required"=>false}},
212
+ "produces"=>["application/json"],
213
+ "tags"=>["simple_with_headers"],
214
+ "operationId"=>"getSimpleWithHeaders",
215
+ "responses"=>{
216
+ "200"=>{"description"=>"this gets something else"},
217
+ "403"=>{"description"=>"invalid pony"},
218
+ "405"=>{"description"=>"no ponies left!"}}}
219
+ }})
220
+ end
221
+ end
222
+
223
+ describe 'supports array params' do
224
+ subject do
225
+ get '/swagger_doc/items.json'
226
+ JSON.parse(last_response.body)
227
+ end
228
+
229
+ specify do
230
+ expect(subject['paths']).to eq({
231
+ "/items"=>{
232
+ "post"=>{
233
+ "description"=>"this takes an array of parameters",
234
+ "produces"=>["application/json"],
235
+ "consumes"=>["application/json"],
236
+ "parameters"=>[{"in"=>"formData", "name"=>"items[]", "description"=>"array of items", "required"=>false, "type"=>"array", "items"=>{"type"=>"string"}}],
237
+ "tags"=>["items"],
238
+ "operationId"=>"postItems",
239
+ "responses"=>{"201"=>{"description"=>"this takes an array of parameters", "schema"=>{"$ref"=>"#/definitions/Item"}}}}
240
+ }})
241
+ end
242
+ end
243
+
244
+ describe 'supports custom params types' do
245
+ subject do
246
+ get '/swagger_doc/custom.json'
247
+ JSON.parse(last_response.body)
248
+ end
249
+
250
+ specify do
251
+ expect(subject['paths']).to eq({
252
+ "/custom"=>{
253
+ "get"=>{
254
+ "description"=>"this uses a custom parameter",
255
+ "produces"=>["application/json"],
256
+ "parameters"=>[{"in"=>"formData", "name"=>"custom", "description"=>"array of items", "required"=>false, "type"=>"array", "items"=>{"type"=>"CustomType"}}],
257
+ "tags"=>["custom"],
258
+ "operationId"=>"getCustom",
259
+ "responses"=>{"200"=>{"description"=>"this uses a custom parameter", "schema"=>{"$ref"=>"#/definitions/Custom"}}}}
260
+ }})
261
+ end
262
+ end
263
+ end
264
+ end