Module: JekyllOpenAPI::ContentType

Defined in:
lib/jekyll_openapi/content_type.rb

Overview

Classifies a media-type string so templates pick a schema representation without brittle == "application/xml" comparisons that miss text/xml, application/*+xml, or a trailing ; charset=… parameter.

Class Method Summary collapse

Class Method Details

.representation(content_type) ⇒ String

Returns one of "xml", "json", "text", "binary".

Returns:

  • (String)

    one of "xml", "json", "text", "binary"



8
9
10
11
12
13
14
# File 'lib/jekyll_openapi/content_type.rb', line 8

def self.representation(content_type)
  ct = normalize(content_type)
  return "xml" if ct == "application/xml" || ct == "text/xml" || ct.end_with?("+xml")
  return "json" if ct == "application/json" || ct.end_with?("+json")
  return "text" if ct.start_with?("text/")
  "binary"
end

.xml?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/jekyll_openapi/content_type.rb', line 16

def self.xml?(content_type)
  representation(content_type) == "xml"
end