lib/swagalicious/example_helpers.rb in swagalicious-0.3.1 vs lib/swagalicious/example_helpers.rb in swagalicious-0.4.0

- old
+ new

@@ -47,15 +47,25 @@ body = response.body body = "{}" if body.empty? @body = Oj.load(body, symbol_keys: true) + metadata[:paths] ||= [] + metadata[:paths] << request[:path] + if request[:payload] metadata[:response][:request] = Oj.load(request[:payload]) end - metadata[:response][:examples] ||= {} - metadata[:response][:examples]["application/json"] = @body + metadata[:response][:examples] ||= {} + + mime_types = metadata[:response][:produces] || ["application/json"] + full_title = "#{metadata[:operation][:summary]}: #{metadata[:description]}" + + mime_types.each do |mime_type| + metadata[:response][:examples][mime_type] ||= {} + metadata[:response][:examples][mime_type][full_title] = @body + end # Validates response matches the proper schema Swagalicious::ResponseValidator.new.validate!(metadata, response) response