Class: Openapi3Parser::NodeFactory::Map::ValidNodeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/node_factory/map.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory) ⇒ ValidNodeBuilder

Returns a new instance of ValidNodeBuilder.



110
111
112
113
# File 'lib/openapi3_parser/node_factory/map.rb', line 110

def initialize(factory)
  @factory = factory
  @validatable = Validation::Validatable.new(factory)
end

Class Method Details

.data(factory, parent_context) ⇒ Object



106
107
108
# File 'lib/openapi3_parser/node_factory/map.rb', line 106

def self.data(factory, parent_context)
  new(factory).data(parent_context)
end

.errors(factory) ⇒ Object



102
103
104
# File 'lib/openapi3_parser/node_factory/map.rb', line 102

def self.errors(factory)
  new(factory).errors
end

Instance Method Details

#data(parent_context) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/openapi3_parser/node_factory/map.rb', line 123

def data(parent_context)
  return default_value if factory.nil_input?

  TypeChecker.raise_on_invalid_type(factory.context, type: ::Hash)
  check_keys(raise_on_invalid: true)
  check_values(raise_on_invalid: true)
  validate(raise_on_invalid: true)

  factory.data.each_with_object({}) do |(key, value), memo|
    memo[key] = if value.respond_to?(:node)
                  Node::Placeholder.new(value, key, parent_context)
                else
                  value
                end
  end
end

#errorsObject



115
116
117
118
119
120
121
# File 'lib/openapi3_parser/node_factory/map.rb', line 115

def errors
  return validatable.collection if factory.nil_input?
  TypeChecker.validate_type(validatable, type: ::Hash)
  return validatable.collection if validatable.errors.any?
  collate_errors
  validatable.collection
end