grape-swagger 0.26.1 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.rubocop_todo.yml +5 -11
  4. data/.travis.yml +1 -2
  5. data/CHANGELOG.md +20 -1
  6. data/Dangerfile +2 -0
  7. data/Gemfile +5 -2
  8. data/README.md +70 -17
  9. data/RELEASING.md +2 -2
  10. data/Rakefile +2 -1
  11. data/grape-swagger.gemspec +2 -0
  12. data/lib/grape-swagger.rb +3 -1
  13. data/lib/grape-swagger/doc_methods.rb +17 -2
  14. data/lib/grape-swagger/doc_methods/build_model_definition.rb +2 -0
  15. data/lib/grape-swagger/doc_methods/data_type.rb +2 -0
  16. data/lib/grape-swagger/doc_methods/extensions.rb +6 -0
  17. data/lib/grape-swagger/doc_methods/headers.rb +2 -0
  18. data/lib/grape-swagger/doc_methods/move_params.rb +7 -5
  19. data/lib/grape-swagger/doc_methods/operation_id.rb +5 -7
  20. data/lib/grape-swagger/doc_methods/optional_object.rb +2 -0
  21. data/lib/grape-swagger/doc_methods/parse_params.rb +3 -3
  22. data/lib/grape-swagger/doc_methods/path_string.rb +3 -1
  23. data/lib/grape-swagger/doc_methods/produces_consumes.rb +2 -0
  24. data/lib/grape-swagger/doc_methods/status_codes.rb +2 -2
  25. data/lib/grape-swagger/doc_methods/tag_name_description.rb +2 -0
  26. data/lib/grape-swagger/doc_methods/version.rb +1 -0
  27. data/lib/grape-swagger/endpoint.rb +36 -18
  28. data/lib/grape-swagger/errors.rb +2 -0
  29. data/lib/grape-swagger/model_parsers.rb +2 -0
  30. data/lib/grape-swagger/rake/oapi_tasks.rb +2 -0
  31. data/lib/grape-swagger/version.rb +3 -1
  32. data/spec/issues/403_versions_spec.rb +2 -0
  33. data/spec/issues/427_entity_as_string_spec.rb +2 -0
  34. data/spec/issues/430_entity_definitions_spec.rb +2 -0
  35. data/spec/issues/532_allow_custom_format_spec.rb +3 -1
  36. data/spec/issues/533_specify_status_code_spec.rb +2 -0
  37. data/spec/issues/537_enum_values_spec.rb +4 -2
  38. data/spec/issues/539_array_post_body_spec.rb +2 -0
  39. data/spec/issues/542_array_of_type_in_post_body_spec.rb +2 -0
  40. data/spec/issues/553_align_array_put_post_params_spec.rb +2 -0
  41. data/spec/issues/572_array_post_body_spec.rb +2 -0
  42. data/spec/issues/579_align_put_post_parameters_spec.rb +179 -0
  43. data/spec/issues/582_file_response_spec.rb +55 -0
  44. data/spec/issues/587_range_parameter_delimited_by_dash_spec.rb +26 -0
  45. data/spec/lib/data_type_spec.rb +2 -0
  46. data/spec/lib/endpoint_spec.rb +2 -0
  47. data/spec/lib/extensions_spec.rb +2 -0
  48. data/spec/lib/model_parsers_spec.rb +2 -0
  49. data/spec/lib/move_params_spec.rb +8 -5
  50. data/spec/lib/oapi_tasks_spec.rb +2 -0
  51. data/spec/lib/operation_id_spec.rb +2 -0
  52. data/spec/lib/optional_object_spec.rb +6 -1
  53. data/spec/lib/parse_params_spec.rb +2 -0
  54. data/spec/lib/path_string_spec.rb +10 -1
  55. data/spec/lib/produces_consumes_spec.rb +2 -0
  56. data/spec/lib/tag_name_description_spec.rb +10 -7
  57. data/spec/lib/version_spec.rb +5 -3
  58. data/spec/spec_helper.rb +3 -1
  59. data/spec/support/empty_model_parser.rb +2 -0
  60. data/spec/support/grape_version.rb +2 -0
  61. data/spec/support/mock_parser.rb +2 -0
  62. data/spec/support/model_parsers/entity_parser.rb +2 -0
  63. data/spec/support/model_parsers/mock_parser.rb +2 -0
  64. data/spec/support/model_parsers/representable_parser.rb +2 -0
  65. data/spec/support/namespace_tags.rb +2 -0
  66. data/spec/support/the_paths_definitions.rb +2 -0
  67. data/spec/swagger_v2/api_swagger_v2_body_definitions_spec.rb +2 -0
  68. data/spec/swagger_v2/api_swagger_v2_definitions-models_spec.rb +2 -0
  69. data/spec/swagger_v2/api_swagger_v2_detail_spec.rb +14 -12
  70. data/spec/swagger_v2/api_swagger_v2_extensions_spec.rb +2 -0
  71. data/spec/swagger_v2/api_swagger_v2_format-content_type_spec.rb +2 -0
  72. data/spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb +2 -0
  73. data/spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb +2 -0
  74. data/spec/swagger_v2/api_swagger_v2_headers_spec.rb +2 -0
  75. data/spec/swagger_v2/api_swagger_v2_hide_documentation_path_spec.rb +2 -0
  76. data/spec/swagger_v2/api_swagger_v2_hide_param_spec.rb +2 -0
  77. data/spec/swagger_v2/api_swagger_v2_ignore_defaults_spec.rb +2 -0
  78. data/spec/swagger_v2/api_swagger_v2_mounted_spec.rb +2 -0
  79. data/spec/swagger_v2/api_swagger_v2_param_type_body_nested_spec.rb +2 -0
  80. data/spec/swagger_v2/api_swagger_v2_param_type_body_spec.rb +2 -0
  81. data/spec/swagger_v2/api_swagger_v2_param_type_spec.rb +2 -0
  82. data/spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb +2 -0
  83. data/spec/swagger_v2/api_swagger_v2_response_spec.rb +2 -0
  84. data/spec/swagger_v2/api_swagger_v2_spec.rb +2 -0
  85. data/spec/swagger_v2/api_swagger_v2_type-format_spec.rb +2 -0
  86. data/spec/swagger_v2/boolean_params_spec.rb +2 -0
  87. data/spec/swagger_v2/default_api_spec.rb +43 -1
  88. data/spec/swagger_v2/description_not_initialized.rb +2 -0
  89. data/spec/swagger_v2/endpoint_versioned_path_spec.rb +2 -0
  90. data/spec/swagger_v2/errors_spec.rb +2 -0
  91. data/spec/swagger_v2/float_api_spec.rb +2 -0
  92. data/spec/swagger_v2/form_params_spec.rb +3 -1
  93. data/spec/swagger_v2/grape-swagger_spec.rb +2 -0
  94. data/spec/swagger_v2/hide_api_spec.rb +2 -0
  95. data/spec/swagger_v2/host.rb +2 -0
  96. data/spec/swagger_v2/mounted_target_class_spec.rb +2 -0
  97. data/spec/swagger_v2/namespace_tags_prefix_spec.rb +3 -1
  98. data/spec/swagger_v2/namespace_tags_spec.rb +2 -0
  99. data/spec/swagger_v2/namespaced_api_spec.rb +2 -0
  100. data/spec/swagger_v2/nicknamed_api_spec.rb +2 -0
  101. data/spec/swagger_v2/operation_id_api_spec.rb +2 -0
  102. data/spec/swagger_v2/param_multi_type_spec.rb +2 -0
  103. data/spec/swagger_v2/param_type_spec.rb +2 -0
  104. data/spec/swagger_v2/param_values_spec.rb +2 -0
  105. data/spec/swagger_v2/params_array_collection_fromat_spec.rb +2 -0
  106. data/spec/swagger_v2/params_array_spec.rb +2 -0
  107. data/spec/swagger_v2/params_hash_spec.rb +2 -0
  108. data/spec/swagger_v2/params_nested_spec.rb +2 -0
  109. data/spec/swagger_v2/parent_less_namespace.rb +2 -0
  110. data/spec/swagger_v2/reference_entity.rb +2 -0
  111. data/spec/swagger_v2/security_requirement_spec.rb +2 -0
  112. data/spec/swagger_v2/simple_mounted_api_spec.rb +2 -0
  113. data/spec/version_spec.rb +2 -0
  114. metadata +8 -2
@@ -1,24 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module DocMethods
3
5
  class OperationId
4
6
  class << self
5
7
  def build(route, path = nil)
6
8
  if route.options[:nickname]
7
- operation_id = route.options[:nickname]
9
+ route.options[:nickname]
8
10
  else
9
11
  verb = route.request_method.to_s.downcase
10
-
11
12
  operation = manipulate(path) unless path.nil?
12
-
13
- operation_id = "#{verb}#{operation}"
13
+ "#{verb}#{operation}"
14
14
  end
15
-
16
- operation_id
17
15
  end
18
16
 
19
17
  def manipulate(path)
20
18
  operation = path.split('/').map(&:capitalize).join
21
- operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation.include?('-')
19
+ operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation[/\-(\w)/]
22
20
  operation.gsub!(/\_(\w)/, &:upcase).delete!('_') if operation.include?('_')
23
21
  operation.gsub!(/\.(\w)/, &:upcase).delete!('.') if operation.include?('.')
24
22
  if path.include?('{')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module DocMethods
3
5
  class OptionalObject
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module DocMethods
3
5
  class ParseParams
4
6
  class << self
5
- def call(param, settings, route, definitions)
6
- path = route.path
7
+ def call(param, settings, path, route, definitions)
7
8
  method = route.request_method
8
-
9
9
  additional_documentation = settings.fetch(:documentation, {})
10
10
  settings.merge!(additional_documentation)
11
11
  data_type = DataType.call(settings)
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module DocMethods
3
5
  class PathString
4
6
  class << self
5
7
  def build(route, options = {})
6
- path = route.path
8
+ path = route.path.dup
7
9
  # always removing format
8
10
  path.sub!(/\(\.\w+?\)$/, '')
9
11
  path.sub!('(.:format)', '')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module DocMethods
3
5
  class ProducesConsumes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module DocMethods
3
5
  class StatusCodes
@@ -8,8 +10,6 @@ module GrapeSwagger
8
10
  post: { code: 201, message: 'created {item}' },
9
11
  put: { code: 200, message: 'updated {item}' },
10
12
  patch: { code: 200, message: 'patched {item}' },
11
- # 200 for delete would only be used, if a success entity is given,
12
- # else it would be set to 204
13
13
  delete: { code: 200, message: 'deleted {item}' },
14
14
  head: { code: 200, message: 'head {item}' },
15
15
  options: { code: 200, message: 'option {item}' }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module DocMethods
3
5
  class TagNameDescription
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module GrapeSwagger
3
4
  module DocMethods
4
5
  class Version
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support'
2
4
  require 'active_support/core_ext/string/inflections.rb'
3
5
 
@@ -35,14 +37,18 @@ module Grape
35
37
 
36
38
  # building info object
37
39
  def info_object(infos)
38
- {
40
+ result = {
39
41
  title: infos[:title] || 'API title',
40
42
  description: infos[:description],
41
43
  termsOfServiceUrl: infos[:terms_of_service_url],
42
44
  contact: contact_object(infos),
43
45
  license: license_object(infos),
44
46
  version: infos[:version]
45
- }.delete_if { |_, value| value.blank? }
47
+ }
48
+
49
+ GrapeSwagger::DocMethods::Extensions.add_extensions_to_info(infos, result)
50
+
51
+ result.delete_if { |_, value| value.blank? }
46
52
  end
47
53
 
48
54
  # sub-objects of info object
@@ -108,10 +114,10 @@ module Grape
108
114
  method[:description] = description_object(route)
109
115
  method[:produces] = produces_object(route, options[:produces] || options[:format])
110
116
  method[:consumes] = consumes_object(route, options[:format])
111
- method[:parameters] = params_object(route)
117
+ method[:parameters] = params_object(route, path)
112
118
  method[:security] = security_object(route)
113
119
  method[:responses] = response_object(route)
114
- method[:tags] = route.options.fetch(:tags, tag_object(route))
120
+ method[:tags] = route.options.fetch(:tags, tag_object(route, path))
115
121
  method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path)
116
122
  method.delete_if { |_, value| value.blank? }
117
123
 
@@ -138,9 +144,12 @@ module Grape
138
144
  end
139
145
 
140
146
  def produces_object(route, format)
147
+ return ['application/octet-stream'] if file_response?(route.attributes.success) &&
148
+ !route.attributes.produces.present?
149
+
141
150
  mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format)
142
151
 
143
- route_mime_types = [:formats, :content_types, :produces].map do |producer|
152
+ route_mime_types = %i(formats content_types produces).map do |producer|
144
153
  possible = route.options[producer]
145
154
  GrapeSwagger::DocMethods::ProducesConsumes.call(possible) if possible.present?
146
155
  end.flatten.compact.uniq
@@ -153,12 +162,12 @@ module Grape
153
162
  if route.settings[:description] && route.settings[:description][:consumes]
154
163
  format = route.settings[:description][:consumes]
155
164
  end
156
- mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format) if [:post, :put].include?(method)
165
+ mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format) if %i(post put).include?(method)
157
166
 
158
167
  mime_types
159
168
  end
160
169
 
161
- def params_object(route)
170
+ def params_object(route, path)
162
171
  parameters = partition_params(route).map do |param, value|
163
172
  value = { required: false }.merge(value) if value.is_a?(Hash)
164
173
  _, value = default_type([[param, value]]).first if value == ''
@@ -167,11 +176,11 @@ module Grape
167
176
  elsif value[:documentation]
168
177
  expose_params(value[:documentation][:type])
169
178
  end
170
- GrapeSwagger::DocMethods::ParseParams.call(param, value, route, @definitions)
179
+ GrapeSwagger::DocMethods::ParseParams.call(param, value, path, route, @definitions)
171
180
  end
172
181
 
173
182
  if GrapeSwagger::DocMethods::MoveParams.can_be_moved?(parameters, route.request_method)
174
- parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(parameters, route, @definitions)
183
+ parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(path, parameters, route, @definitions)
175
184
  end
176
185
 
177
186
  parameters
@@ -185,6 +194,7 @@ module Grape
185
194
 
186
195
  codes.each_with_object({}) do |value, memo|
187
196
  memo[value[:code]] = { description: value[:message] }
197
+ next build_file_response(memo[value[:code]]) if file_response?(value[:model])
188
198
 
189
199
  response_model = @item
190
200
  response_model = expose_params_from_model(value[:model]) if value[:model]
@@ -201,7 +211,7 @@ module Grape
201
211
  # TODO: proof that the definition exist, if model isn't specified
202
212
  reference = { '$ref' => "#/definitions/#{response_model}" }
203
213
  memo[value[:code]][:schema] = if route.options[:is_array] && value[:code] < 300
204
- { 'type' => 'array', 'items' => reference }
214
+ { type: 'array', items: reference }
205
215
  else
206
216
  reference
207
217
  end
@@ -223,11 +233,11 @@ module Grape
223
233
  [default_code]
224
234
  end
225
235
 
226
- def tag_object(route)
236
+ def tag_object(route, path)
227
237
  version = GrapeSwagger::DocMethods::Version.get(route)
228
238
  version = [version] unless version.is_a?(Array)
229
239
  Array(
230
- route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
240
+ path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
231
241
  i == route.prefix.to_s || version.map(&:to_s).include?(i)
232
242
  end.first
233
243
  )
@@ -235,23 +245,31 @@ module Grape
235
245
 
236
246
  private
237
247
 
248
+ def file_response?(value)
249
+ value.to_s.casecmp('file').zero? ? true : false
250
+ end
251
+
252
+ def build_file_response(memo)
253
+ memo['schema'] = { type: 'file' }
254
+ end
255
+
238
256
  def partition_params(route)
239
257
  declared_params = route.settings[:declared_params] if route.settings[:declared_params].present?
240
- required, exposed = route.params.partition { |x| x.first.is_a? String }
258
+ required = merge_params(route)
241
259
  required = GrapeSwagger::DocMethods::Headers.parse(route) + required unless route.headers.nil?
242
260
 
243
261
  default_type(required)
244
- default_type(exposed)
245
262
 
246
263
  request_params = unless declared_params.nil? && route.headers.nil?
247
264
  parse_request_params(required)
248
265
  end || {}
249
266
 
250
- if route.params.present? && !route.settings[:declared_params].present?
251
- request_params = route.params.merge(request_params)
252
- end
267
+ request_params.empty? ? required : request_params
268
+ end
253
269
 
254
- request_params
270
+ def merge_params(route)
271
+ param_keys = route.params.keys
272
+ route.params.delete_if { |key| key.is_a?(String) && param_keys.include?(key.to_sym) }.to_a
255
273
  end
256
274
 
257
275
  def default_type(params)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  module Errors
3
5
  class UnregisteredParser < StandardError; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
4
  class ModelParsers
3
5
  include Enumerable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'rake/tasklib'
3
5
  require 'rack/test'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GrapeSwagger
2
- VERSION = '0.26.1'.freeze
4
+ VERSION = '0.27.0'
3
5
  end
@@ -1,4 +1,6 @@
1
1
  # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'spec_helper'
3
5
 
4
6
  describe 'describing versions' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe '#427 nested entity given as string' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'definition names' do
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe '#542 array of type in post params' do
5
+ describe '#532 allow custom format' do
4
6
  let(:app) do
5
7
  Class.new(Grape::API) do
6
8
  namespace :issue_532 do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe '#533 specify status codes' do
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe '#537 enum values spec' do
4
6
  let(:app) do
5
7
  Class.new(Grape::API) do
6
- namespace :issue_539 do
8
+ namespace :issue_537 do
7
9
  class Spec < Grape::Entity
8
- expose :enum_property, documentation: { values: [:foo, :bar] }
10
+ expose :enum_property, documentation: { values: %i(foo bar) }
9
11
  expose :enum_property_default, documentation: { values: %w(a b c), default: 'c' }
10
12
  expose :own_format, documentation: { format: 'log' }
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe '#539 post params given as array' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe '#542 array of type in post params' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe '#553 array of type in post/put params' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe '#572 is_array is applied to all possible responses' do
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe '#579 put / post parameters spec' do
6
+ let(:app) do
7
+ Class.new(Grape::API) do
8
+ namespace :issue_579 do
9
+ class BodySpec < Grape::Entity
10
+ expose :guid, documentation: { type: String, format: 'guid', in: 'body' }
11
+ expose :name, documentation: { type: String, in: 'body' }
12
+ expose :content, documentation: { type: String, in: 'body' }
13
+ end
14
+
15
+ class Spec < Grape::Entity
16
+ expose :guid, documentation: { type: String, format: 'guid' }
17
+ expose :name, documentation: { type: String }
18
+ expose :content, documentation: { type: String }
19
+ end
20
+
21
+ namespace :implicit do
22
+ namespace :body_parameter do
23
+ desc 'update spec',
24
+ success: BodySpec,
25
+ params: BodySpec.documentation
26
+ put ':guid' do
27
+ # your code goes here
28
+ end
29
+ end
30
+
31
+ namespace :form_parameter do
32
+ desc 'update spec',
33
+ success: Spec,
34
+ params: Spec.documentation
35
+ put ':guid' do
36
+ # your code goes here
37
+ end
38
+ end
39
+ end
40
+
41
+ namespace :explicit do
42
+ namespace :body_parameter do
43
+ desc 'update spec',
44
+ success: BodySpec,
45
+ params: BodySpec.documentation
46
+ params do
47
+ requires :guid
48
+ end
49
+ put ':guid' do
50
+ # your code goes here
51
+ end
52
+ end
53
+
54
+ namespace :form_parameter do
55
+ desc 'update spec',
56
+ success: Spec,
57
+ params: Spec.documentation
58
+ params do
59
+ requires :guid
60
+ end
61
+ put ':guid' do
62
+ # your code goes here
63
+ end
64
+ end
65
+ end
66
+
67
+ namespace :namespace_param do
68
+ route_param :guid do
69
+ namespace :body_parameter do
70
+ desc 'update spec',
71
+ success: BodySpec,
72
+ params: BodySpec.documentation
73
+ put do
74
+ # your code goes here
75
+ end
76
+ end
77
+
78
+ namespace :form_parameter do
79
+ desc 'update spec',
80
+ success: Spec,
81
+ params: Spec.documentation
82
+ put do
83
+ # your code goes here
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ add_swagger_documentation format: :json
91
+ end
92
+ end
93
+
94
+ subject do
95
+ get '/swagger_doc'
96
+ JSON.parse(last_response.body)
97
+ end
98
+
99
+ describe 'implicit path param given' do
100
+ let(:body_parameters) { subject['paths']['/issue_579/implicit/body_parameter/{guid}']['put']['parameters'] }
101
+ specify do
102
+ expect(body_parameters).to eql(
103
+ [
104
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
105
+ {
106
+ 'name' => 'Issue579ImplicitBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
107
+ '$ref' => '#/definitions/putIssue579ImplicitBodyParameter'
108
+ }
109
+ }
110
+ ]
111
+ )
112
+ end
113
+
114
+ let(:form_parameters) { subject['paths']['/issue_579/implicit/form_parameter/{guid}']['put']['parameters'] }
115
+ specify do
116
+ expect(form_parameters).to eql(
117
+ [
118
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
119
+ { 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
120
+ { 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
121
+ ]
122
+ )
123
+ end
124
+ end
125
+
126
+ describe 'explicit path param given' do
127
+ let(:body_parameters) { subject['paths']['/issue_579/explicit/body_parameter/{guid}']['put']['parameters'] }
128
+ specify do
129
+ expect(body_parameters).to eql(
130
+ [
131
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
132
+ {
133
+ 'name' => 'Issue579ExplicitBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
134
+ '$ref' => '#/definitions/putIssue579ExplicitBodyParameter'
135
+ }
136
+ }
137
+ ]
138
+ )
139
+ end
140
+
141
+ let(:form_parameters) { subject['paths']['/issue_579/explicit/form_parameter/{guid}']['put']['parameters'] }
142
+ specify do
143
+ expect(form_parameters).to eql(
144
+ [
145
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
146
+ { 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
147
+ { 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
148
+ ]
149
+ )
150
+ end
151
+ end
152
+
153
+ describe 'explicit as route param given' do
154
+ let(:body_parameters) { subject['paths']['/issue_579/namespace_param/{guid}/body_parameter']['put']['parameters'] }
155
+ specify do
156
+ expect(body_parameters).to eql(
157
+ [
158
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
159
+ {
160
+ 'name' => 'Issue579NamespaceParamGuidBodyParameter', 'in' => 'body', 'required' => true, 'schema' => {
161
+ '$ref' => '#/definitions/putIssue579NamespaceParamGuidBodyParameter'
162
+ }
163
+ }
164
+ ]
165
+ )
166
+ end
167
+
168
+ let(:form_parameters) { subject['paths']['/issue_579/namespace_param/{guid}/form_parameter']['put']['parameters'] }
169
+ specify do
170
+ expect(form_parameters).to eql(
171
+ [
172
+ { 'in' => 'path', 'name' => 'guid', 'type' => 'string', 'format' => 'guid', 'required' => true },
173
+ { 'in' => 'formData', 'name' => 'name', 'type' => 'string', 'required' => false },
174
+ { 'in' => 'formData', 'name' => 'content', 'type' => 'string', 'required' => false }
175
+ ]
176
+ )
177
+ end
178
+ end
179
+ end