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

- old
+ new

@@ -90,11 +90,24 @@ end def metadata_to_swagger(metadata) response_code = metadata[:response][:code] response = metadata[:response].reject { |k, _v| k == :code } + examples = response.delete(:examples) || [] + examples.each do |mime_type, titles| + titles.each do |title, example| + next unless response[:content][mime_type] + + response[:content][mime_type][:examples] ||= {} + + response[:content][mime_type][:examples][title] ||= {} + + response[:content][mime_type][:examples][title][:value] = example + end + end + verb = metadata[:operation][:verb] operation = metadata[:operation] .reject { |k, _v| k == :verb } .merge(responses: { response_code => response }) @@ -123,10 +136,14 @@ schema = target_node[:schema] return if mime_list.empty? || schema.nil? mime_list.each do |mime_type| # TODO upgrade to have content-type specific schema - target_node[:content][mime_type] = { schema: schema } + body = target_node + .fetch(:body, {}) + .fetch(mime_type, {}) + + target_node[:content][mime_type] = { schema: schema }.merge(body) end end def upgrade_request_type!(metadata) # No deprecation here as it seems valid to allow type as a shorthand