class OasParser::AbstractAttribute

Public Class Methods

new(name) click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 5
def initialize(name)
  @name = name
end

Public Instance Methods

allOf?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 23
def allOf?
  raw['allOf'] ? true : false
end
array?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 31
def array?
  type == 'array'
end
collection?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 39
def collection?
  array? || object?
end
empty?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 43
def empty?
  raise 'Called empty? on non collection type' unless collection?
  return true if object? && raw['properties'].blank?
  return true if array? && items.blank?
  false
end
enum() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 19
def enum
  raw['enum'] || (schema ? schema['enum'] : nil)
end
has_xml_name?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 75
def has_xml_name?
  return false unless has_xml_options?
  xml_name || false
end
has_xml_options?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 59
def has_xml_options?
  raw['xml'].present?
end
is_xml_attribute?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 63
def is_xml_attribute?
  return false unless has_xml_options?
  raw['xml']['attribute'] || false
end
is_xml_text?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 68
def is_xml_text?
  # See: https://github.com/OAI/OpenAPI-Specification/issues/630#issuecomment-350680346
  return false unless has_xml_options?
  return true if raw['xml']['text'] || false
  raw['xml']['x-text'] || false
end
name(format = nil) click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 9
def name(format = nil)
  default = @name || raw['name']
  return default unless format
  case format
  when 'text/xml'
    has_xml_name? ? xml_name : default
  else default
  end
end
object?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 35
def object?
  type == 'object'
end
oneOf?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 27
def oneOf?
  raw['oneOf'] ? true : false
end
properties() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 50
def properties
  return convert_property_schema_to_properties(raw) if (oneOf? || allOf?)
  return nil unless collection?
  return [] if empty?
  return convert_property_schema_to_properties(raw['properties']) if object?
  return convert_property_schema_to_properties(items) if array?
  nil
end
subproperties_are_one_of_many?() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 84
def subproperties_are_one_of_many?
  return false unless array?
  items['oneOf'].present?
end
xml_name() click to toggle source
# File lib/oas_parser/abstract_attribute.rb, line 80
def xml_name
  raw['xml']['name']
end