Class: Validator::Validator
- Inherits:
-
Object
- Object
- Validator::Validator
- Defined in:
- lib/opennebula/flow/validator.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Validator
constructor
A new instance of Validator.
-
#validate!(body, schema, key = "") ⇒ Hash, ...
Recursively validate and modify a JSON body based on a schema.
Constructor Details
#initialize(opts = {}) ⇒ Validator
Returns a new instance of Validator.
72 73 74 75 76 77 78 |
# File 'lib/opennebula/flow/validator.rb', line 72 def initialize(opts={}) @opts = { :default_values => true, :delete_extra_properties => false, :allow_extra_properties => false }.merge(opts) end |
Instance Method Details
#validate!(body, schema, key = "") ⇒ Hash, ...
Note:
The parameter body will be modified
Note:
Schema options supported :extends :type => [:object, :array, :string, :null]
Recursively validate and modify a JSON body based on a schema.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/opennebula/flow/validator.rb', line 115 def validate!(body, schema, key="") if schema[:extends] base_schema = schema.delete(:extends) schema = base_schema.deep_merge(schema) end case schema[:type] when :object then validate_object(body, schema, key) when :array then validate_array(body, schema, key) when :string then validate_string(body, schema, key) when :integer then validate_integer(body, schema, key) when :null then validate_null(body, schema, key) when :boolean then validate_boolean(body, schema, key) else raise SchemaException, "type #{schema[:type]} is not a valid type" end end |