class Openapi3Parser::NodeFactory::Object

Attributes

context[R]
data[R]

Public Class Methods

new(context) click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 25
def initialize(context)
  @context = context
  @data = build_data(context.input)
end
object_type() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 21
def self.object_type
  to_s
end

Public Instance Methods

allowed_fields() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 62
def allowed_fields
  field_configs.keys
end
can_use_default?() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 54
def can_use_default?
  true
end
default() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 58
def default
  nil
end
errors() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 46
def errors
  @errors ||= ObjectFactory::NodeBuilder.errors(self)
end
inspect() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 72
def inspect
  %{#{self.class.name}(#{context.source_location.inspect})}
end
nil_input?() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 38
def nil_input?
  context.input.nil?
end
node(node_context) click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 50
def node(node_context)
  build_node(node_context)
end
raw_input() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 34
def raw_input
  context.input
end
required_fields() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 66
def required_fields
  field_configs.each_with_object([]) do |(key, config), memo|
    memo << key if config.required?
  end
end
resolved_input() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 30
def resolved_input
  @resolved_input ||= build_resolved_input
end
valid?() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 42
def valid?
  errors.empty?
end

Private Instance Methods

build_data(raw_input) click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 78
def build_data(raw_input)
  use_default = nil_input? || !raw_input.is_a?(::Hash)
  return if use_default && default.nil?

  process_data(use_default ? default : raw_input)
end
build_node(node_context) click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 109
def build_node(node_context)
  data = ObjectFactory::NodeBuilder.node_data(self, node_context)
  build_object(data, node_context) if data
end
build_resolved_input() click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 95
def build_resolved_input
  return unless data

  data.each_with_object({}) do |(key, value), memo|
    next if value.respond_to?(:nil_input?) && value.nil_input?

    memo[key] = if value.respond_to?(:resolved_input)
                  value.resolved_input
                else
                  value
                end
  end
end
process_data(raw_data) click to toggle source
# File lib/openapi3_parser/node_factory/object.rb, line 85
def process_data(raw_data)
  field_configs.each_with_object(raw_data.dup) do |(field, config), memo|
    memo[field] = nil unless memo[field]
    next unless config.factory?

    next_context = Context.next_field(context, field, memo[field])
    memo[field] = config.initialize_factory(next_context, self)
  end
end