Class: Openapi3Parser::NodeFactory::Field::ValidNodeBuilder

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory) ⇒ ValidNodeBuilder

Returns a new instance of ValidNodeBuilder.



66
67
68
69
# File 'lib/openapi3_parser/node_factory/field.rb', line 66

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

Class Method Details

.data(factory) ⇒ Object



62
63
64
# File 'lib/openapi3_parser/node_factory/field.rb', line 62

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

.errors(factory) ⇒ Object



58
59
60
# File 'lib/openapi3_parser/node_factory/field.rb', line 58

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

Instance Method Details

#dataObject



81
82
83
84
85
86
87
88
# File 'lib/openapi3_parser/node_factory/field.rb', line 81

def data
  return default_value if factory.nil_input?

  TypeChecker.raise_on_invalid_type(factory.context,
                                    type: factory.input_type)
  validate(raise_on_invalid: true)
  factory.data
end

#errorsObject



71
72
73
74
75
76
77
78
79
# File 'lib/openapi3_parser/node_factory/field.rb', line 71

def errors
  return validatable.collection if factory.nil_input?

  TypeChecker.validate_type(validatable, type: factory.input_type)
  return validatable.collection if validatable.errors.any?

  validate(raise_on_invalid: false)
  validatable.collection
end