class JDDF::Validator
Validates JSON instances against JDDF
schemas.
Attributes
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.
@return [Integer] the maximum depth of references to follow when validating
The maximum number of errors to return when running {validate}.
If this value is set to a number, then it's guaranteed that {validate} will return an array of size no greater than the value of this attribute.
By default, no maximum errors is enforced. All validation errors are returned.
@return [Integer] the maximum errors to return when validating
Public Instance Methods
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.
@param schema [Schema] the schema to validate against
@param instance [Object] the input (“instance”) to validate
@raise [MaxDepthExceededError} if {max_depth} is exceeded.
@return [Array] an array of {ValidationError}
# 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