lib/ghost_writer/document.rb in ghost_writer-0.4.2 vs lib/ghost_writer/document.rb in ghost_writer-0.5.0
- old
+ new
@@ -4,11 +4,11 @@
attr_reader :basename, :relative_path, :title, :description, :location, :request_method, :path_info, :response_format, :param_example, :status_code
attr_accessor :header
def initialize(basename, attrs)
@basename = basename
- @relative_path = Pathname.new(basename).relative_path_from(GhostWriter.output_path)
+ @relative_path = basename
@title = attrs[:title]
@description = attrs[:description]
@location = attrs[:location]
@request_method = attrs[:request_method]
@path_info = attrs[:path_info]
@@ -24,11 +24,14 @@
writer = GhostWriter::Writer.new(self, options)
writer.write_file
end
def serialized_params
- MultiJson.dump(param_example)
+ Oj.dump(param_example)
+ rescue NoMemoryError, StandardError
+ puts "Param serialize error: #{param_example.inspect} of #{description} at #{location}"
+ param_example.inspect
end
def response_body
arrange_json(@response_body)
end
@@ -52,15 +55,15 @@
private
def arrange_json(body)
return body unless response_format == "json"
- data = ActiveSupport::JSON.decode(body)
+ data = Oj.load(body)
if data.is_a?(Array) || data.is_a?(Hash)
JSON.pretty_generate(data)
else
data
end
- rescue MultiJson::DecodeError
+ rescue Oj::Error
body
end
end