class Strum::Json::Schema::Validate

Public Instance Methods

audit() click to toggle source
# File lib/strum/json/schema/validate.rb, line 18
def audit
  add_error(:schema, :not_found) unless args[:schema].is_a?(Hash)
end
call() click to toggle source
# File lib/strum/json/schema/validate.rb, line 12
def call
  array_errors = JSON::Validator.fully_validate(args[:schema], input, errors_as_objects: true)
  array_errors.each { |error| add_error(*parse_json_schema_error(error)) }
  output(input)
end

Protected Instance Methods

parse_json_schema_error(error) click to toggle source
# File lib/strum/json/schema/validate.rb, line 24
def parse_json_schema_error(error)
  id = error[:fragment].sub(/#/, "input")
  keys = id.split("/")
  last_key = keys.map { |key| key =~ /[0-9]+/ ? "[#{key}]" : ".#{key}" }.join[1..]
  value = error[:message][0, error[:message].index(/ in schema/)].sub(error[:fragment], last_key)
  [last_key.to_sym, value]
end