Skip to content

Commit bf378dc

Browse files
oleksandr-morozoviNecas
authored andcommitted
Added recursion for documentation, fixed bug in examples with paperclip
1 parent 853f2bf commit bf378dc

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

lib/apipie/extractor/writer.rb

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,26 @@ def ordered_call(call)
7878
%w[title verb path versions query request_data response_data code show_in_doc recorded].each do |k|
7979
next unless call.has_key?(k)
8080
ordered_call[k] = case call[k]
81-
when ActiveSupport::HashWithIndifferentAccess
82-
# UploadedFiles break the to_json call, turn them into a string so they don't break
83-
call[k].each do |pkey, pval|
84-
if (pval.is_a?(Rack::Test::UploadedFile) || pval.is_a?(ActionDispatch::Http::UploadedFile))
85-
call[k][pkey] = "<FILE CONTENT '#{pval.original_filename}'>"
86-
end
87-
end
88-
JSON.parse(call[k].to_json) # to_hash doesn't work recursively and I'm too lazy to write the recursion:)
89-
else
90-
call[k]
91-
end
92-
end
81+
when ActiveSupport::HashWithIndifferentAccess
82+
convert_file_value(call[k]).to_hash
83+
else
84+
call[k]
85+
end
86+
end
9387
return ordered_call
9488
end
9589

90+
def convert_file_value hash
91+
hash.each do |k, v|
92+
if (v.is_a?(Rack::Test::UploadedFile) || v.is_a?(ActionDispatch::Http::UploadedFile))
93+
hash[k] = "<FILE CONTENT '#{v.original_filename}'>"
94+
elsif v.is_a?(Hash)
95+
hash[k] = convert_file_value(v)
96+
end
97+
end
98+
hash
99+
end
100+
96101
def load_recorded_examples
97102
self.class.load_recorded_examples
98103
end
@@ -131,7 +136,7 @@ def deep_merge_examples(new_examples, old_examples)
131136
new_example[:title] ||= old_example["title"] if old_example["title"].present?
132137
end
133138
new_example
134-
end
139+
end
135140
end
136141

137142
def load_new_examples

0 commit comments

Comments
 (0)