Class: JDDF::Validator
- Inherits:
-
Object
- Object
- JDDF::Validator
- Defined in:
- lib/jddf/validator.rb
Overview
Validates JSON instances against JDDF schemas.
Instance Attribute Summary collapse
-
#max_depth ⇒ Integer
The maximum stack depth of references to follow when running #validate.
-
#max_errors ⇒ Integer
The maximum number of errors to return when running #validate.
Instance Method Summary collapse
-
#validate(schema, instance) ⇒ Array
Validate a JDDF schema against a JSON instance.
Instance Attribute Details
#max_depth ⇒ Integer
The maximum stack depth of references to follow when running #validate.
If this maximum depth is exceeded, such as if a schema passed to #validate is defined cyclically, then #validate throws a MaxDepthExceededError.
By default, no maximum depth is enforced. The validator may overflow the stack if a schema is defined cyclically.
273 274 275 |
# File 'lib/jddf/validator.rb', line 273 def max_depth @max_depth end |
#max_errors ⇒ Integer
284 285 286 |
# File 'lib/jddf/validator.rb', line 284 def max_errors @max_errors end |
Instance Method Details
#validate(schema, instance) ⇒ Array
Validate a JDDF schema against a JSON instance.
The precise rules of validation for this method are defined formally by the JDDF specification, and this method follows those rules exactly, assuming that instance
is the result of calling JSON#parse using the standard library’s JSON
module.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/jddf/validator.rb', line 300 def validate(schema, instance) vm = VM.new vm.max_depth = max_depth vm.max_errors = max_errors vm.root_schema = schema vm.instance_tokens = [] vm.schema_tokens = [[]] vm.errors = [] begin vm.validate(schema, instance) rescue MaxErrorsError # rubocop:disable Lint/HandleExceptions # There is nothing to do here. MaxErrorsError is just a circuit-breaker. end vm.errors end |