Class: Openapi3Parser::NodeFactory::TypeChecker
- Inherits:
-
Object
- Object
- Openapi3Parser::NodeFactory::TypeChecker
- Defined in:
- lib/openapi3_parser/node_factory/type_checker.rb
Class Method Summary collapse
- .raise_on_invalid_keys(context, type:) ⇒ Object
- .raise_on_invalid_type(context, type:) ⇒ Object
- .validate_keys(validatable, type:, context: nil) ⇒ Object
- .validate_type(validatable, type:, context: nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(type) ⇒ TypeChecker
constructor
A new instance of TypeChecker.
- #raise_on_invalid_keys(context) ⇒ Object
- #raise_on_invalid_type(context) ⇒ Object
- #validate_keys(validatable, context) ⇒ Object
- #validate_type(validatable, context) ⇒ Object
Constructor Details
#initialize(type) ⇒ TypeChecker
Returns a new instance of TypeChecker.
24 25 26 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 24 def initialize(type) @type = type end |
Class Method Details
.raise_on_invalid_keys(context, type:) ⇒ Object
18 19 20 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 18 def self.raise_on_invalid_keys(context, type:) new(type).raise_on_invalid_keys(context) end |
.raise_on_invalid_type(context, type:) ⇒ Object
10 11 12 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 10 def self.raise_on_invalid_type(context, type:) new(type).raise_on_invalid_type(context) end |
.validate_keys(validatable, type:, context: nil) ⇒ Object
14 15 16 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 14 def self.validate_keys(validatable, type:, context: nil) new(type).validate_keys(validatable, context) end |
.validate_type(validatable, type:, context: nil) ⇒ Object
6 7 8 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 6 def self.validate_type(validatable, type:, context: nil) new(type).validate_type(validatable, context) end |
Instance Method Details
#raise_on_invalid_keys(context) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 60 def raise_on_invalid_keys(context) return true if !type || valid_keys?(context.input) raise Error::InvalidType, "Invalid keys for #{context.location_summary}: " \ "#{}" end |
#raise_on_invalid_type(context) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 52 def raise_on_invalid_type(context) return true if !type || valid_type?(context.input) raise Error::InvalidType, "Invalid type for #{context.location_summary}: " \ "#{}" end |
#validate_keys(validatable, context) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 40 def validate_keys(validatable, context) return true unless type context ||= validatable.context valid_keys?(context.input).tap do |valid| next if valid validatable.add_error("Invalid keys. #{}", context) end end |
#validate_type(validatable, context) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openapi3_parser/node_factory/type_checker.rb', line 28 def validate_type(validatable, context) return true unless type context ||= validatable.context valid_type?(context.input).tap do |valid| next if valid validatable.add_error("Invalid type. #{}", context) end end |