Merge remote-tracking branch 'olegkyz/bugfix/examples-content' into jamie

This commit is contained in:
Jamie Macey
2020-10-17 13:14:47 -07:00
6 changed files with 47 additions and 33 deletions

View File

@@ -19,7 +19,11 @@ RSpec.describe '<%= controller_path %>', type: :request do
<% end -%>
after do |example|
example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) }
example.metadata[:response][:content] = {
'application/json' => {
example: JSON.parse(response.body, symbolize_names: true)
}
}
end
run_test!
end

View File

@@ -72,7 +72,10 @@ module Rswag
def examples(example = nil)
return super() if example.nil?
metadata[:response][:examples] = example
metadata[:response][:content] =
example.each_with_object({}) do |(mime, example_object), memo|
memo[mime] = { example: example_object }
end
end
def run_test!(&block)

View File

@@ -129,13 +129,13 @@ module Rswag
end
def upgrade_content!(mime_list, target_node)
target_node.merge!(content: {})
target_node[:content] ||= {}
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 }
(target_node[:content][mime_type] ||= {}).merge!(schema: schema)
end
end