mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
Add support for multiple content types in examples (#8)
This commit is contained in:
parent
b9ac008a9f
commit
79304a1bc1
@ -72,18 +72,18 @@ module OpenApi
|
||||
def metadata_to_swagger(metadata)
|
||||
response_code = metadata[:response][:code]
|
||||
response = metadata[:response].reject { |k, _v| k == :code }
|
||||
content_type = metadata[:response][:content].present? ? metadata[:response][:content].keys.first : 'application/json'
|
||||
|
||||
# need to merge in to response
|
||||
if response[:examples]&.dig('application/json')
|
||||
example = response[:examples].dig('application/json').dup
|
||||
schema = response.dig(:content, 'application/json', :schema)
|
||||
if response[:examples]&.dig(content_type)
|
||||
example = response[:examples].dig(content_type).dup
|
||||
schema = response.dig(:content, content_type, :schema)
|
||||
new_hash = {example: example}
|
||||
new_hash[:schema] = schema if schema
|
||||
response.merge!(content: { 'application/json' => new_hash })
|
||||
response.merge!(content: { content_type => new_hash })
|
||||
response.delete(:examples)
|
||||
end
|
||||
|
||||
|
||||
verb = metadata[:operation][:verb]
|
||||
operation = metadata[:operation]
|
||||
.reject { |k, _v| k == :verb }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user