From 04a0ebb1e6114f0b1a2bf42a52b04eddc46bf395 Mon Sep 17 00:00:00 2001 From: Chris Hossenlopp Date: Wed, 10 Feb 2016 17:09:55 -0500 Subject: [PATCH] Fixed to_json encoding error that occurs with uploaded file parameters. - Turns uploaded file parameters into strings to represent a file was uploaded. --- lib/apipie/extractor/writer.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/apipie/extractor/writer.rb b/lib/apipie/extractor/writer.rb index 2d0fb6d4..234c700d 100644 --- a/lib/apipie/extractor/writer.rb +++ b/lib/apipie/extractor/writer.rb @@ -79,6 +79,12 @@ def ordered_call(call) next unless call.has_key?(k) ordered_call[k] = case call[k] when ActiveSupport::HashWithIndifferentAccess + # UploadedFiles break the to_json call, turn them into a string so they don't break + call[k].each do |pkey, pval| + if (pval.is_a?(Rack::Test::UploadedFile) || pval.is_a?(ActionDispatch::Http::UploadedFile)) + call[k][pkey] = "" + end + end JSON.parse(call[k].to_json) # to_hash doesn't work recursively and I'm too lazy to write the recursion:) else call[k]