class JsonMatchers::Validator

Attributes

document_store[R]
schema_path[R]

Public Class Methods

new(document_store:, schema_path:) click to toggle source
# File lib/json_matchers/validator.rb, line 5
def initialize(document_store:, schema_path:)
  @document_store = document_store
  @schema_path = schema_path
end

Public Instance Methods

validate(payload) click to toggle source
# File lib/json_matchers/validator.rb, line 10
def validate(payload)
  json_schema.validate!(payload.as_json, fail_fast: true)

  []
rescue JsonSchema::Error => error
  [error.message]
end

Private Instance Methods

build_json_schema_with_expanded_references() click to toggle source
# File lib/json_matchers/validator.rb, line 26
def build_json_schema_with_expanded_references
  json_schema = Parser.new(schema_path).parse

  json_schema.expand_references!(store: document_store)

  json_schema
end
json_schema() click to toggle source
# File lib/json_matchers/validator.rb, line 22
def json_schema
  @json_schema ||= build_json_schema_with_expanded_references
end