From 6a4cc8de8de150c71c6a172eef56d72def39df0d Mon Sep 17 00:00:00 2001 From: Jay Danielian Date: Sat, 7 Sep 2019 08:21:56 -0400 Subject: [PATCH] Adds fix for multiple files to be marked in request_body_multipart --- .../rswag/specs/example_group_helpers.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb b/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb index b0efcbe..ae71e4a 100644 --- a/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb +++ b/rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb @@ -106,12 +106,11 @@ module OpenApi request_body(description: description, content: content_hash) schema.extend(Hashie::Extensions::DeepLocate) - file_properties = schema.deep_locate -> (_k, v, _obj) { v == :binary } - + file_properties = schema.deep_locate ->(_k, v, _obj) { v == :binary } hash_locator = [] file_properties.each do |match| - hash_match = schema.deep_locate -> (_k, v, _obj) { v == match } + hash_match = schema.deep_locate ->(_k, v, _obj) { v == match } hash_locator.concat(hash_match) unless hash_match.empty? end @@ -119,9 +118,17 @@ module OpenApi locator.select { |_k,v| file_properties.include?(v) } end + existing_keys = [] property_hashes.each do |property_hash| - file_name = property_hash.keys.first - parameter name: file_name, in: :formData, type: :file, required: true + property_hash.keys.each do |k| + if existing_keys.include?(k) + next + else + file_name = k + existing_keys << k + parameter name: file_name, in: :formData, type: :file, required: true + end + end end end