class Fictium::OpenApi::V3Exporter::ExampleFormatter

Public Instance Methods

content_formatter() click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb, line 36
def content_formatter
  @content_formatter ||= ContentFormatter.new
end
default_response_content_type() click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb, line 24
def default_response_content_type
  Fictium.configuration.default_response_content_type
end
extract_headers(example) click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb, line 28
def extract_headers(example)
  {}.tap do |headers|
    example.headers.each do |name, value|
      headers[name] = header_formatter.format(name, :header, value)
    end
  end
end
format(example) click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb, line 15
def format(example)
  { description: example.summary }.tap do |format|
    content = content_formatter.format(example.response, default_response_content_type)
    format[:content] = content if content.present?
    headers = extract_headers(example)
    format[:headers] = headers if headers.present?
  end
end
format_default(operation, responses, default_example) click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb, line 5
def format_default(operation, responses, default_example)
  responses[:default] = format(default_example)
  return if default_example.request[:content_type].blank?

  operation[:requestBody] = {
    content: content_formatter.format(default_example.request)
  }
  operation[:requestBody][:required] = true if default_example.request[:required]
end
header_formatter() click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb, line 40
def header_formatter
  @header_formatter ||= ParamFormatter.new(ignore_name: true, ignore_in: true)
end