Class: JTD::ValidationOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/jtd/validate.rb

Overview

Options you can pass to JTD::validate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_depth: 0, max_errors: 0) ⇒ ValidationOptions

Construct a new set of ValidationOptions with the given max_depth and max_errors.

See the documentation for max_depth and max_errors for what their default values of 0 mean.



77
78
79
80
# File 'lib/jtd/validate.rb', line 77

def initialize(max_depth: 0, max_errors: 0)
  @max_depth = max_depth
  @max_errors = max_errors
end

Instance Attribute Details

#max_depthObject

The maximum number of references to follow before aborting validation. You can use this to prevent a stack overflow when validating schemas that potentially have infinite loops, such as this one:

{
  "definitions": {
    "loop": { "ref": "loop" }
  },
  "ref": "loop"
}

The default value for max_depth is 0, which indicates that no max depth should be imposed at all.



57
58
59
# File 'lib/jtd/validate.rb', line 57

def max_depth
  @max_depth
end

#max_errorsObject

The maximum number of errors to return. You can use this to have JTD::validate have better performance if you don’t have any use for errors beyond a certain count.

For instance, if all you care about is whether or not there are any validation errors at all, you can set max_errors to 1. If you’re presenting validation errors in an interface that can’t show more than 5 errors, set max_errors to 5.

The default value for max_errors is 0, which indicates that all errors will be returned.



70
71
72
# File 'lib/jtd/validate.rb', line 70

def max_errors
  @max_errors
end