Class: Fictium::OpenApi::V3Exporter::ContentFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/fictium/exporters/open_api/v3_exporter/content_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format(http_object, default = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fictium/exporters/open_api/v3_exporter/content_formatter.rb', line 5

def format(http_object, default = nil)
  type = (http_object.presence && http_object[:content_type].presence) || default
  return if type.blank?

  {}.tap do |content|
    media_type = {
      example: http_object[:body]
    }
    media_type[:schema] = http_object[:schema] if http_object[:schema].present?
    content[type.to_sym] = media_type
  end
end