Module: SimpleJSONSchema
- Defined in:
- lib/simple_json_schema.rb,
lib/simple_json_schema/cache.rb,
lib/simple_json_schema/scope.rb,
lib/simple_json_schema/checker.rb,
lib/simple_json_schema/version.rb,
lib/simple_json_schema/validator.rb,
lib/simple_json_schema/ref_helper.rb,
lib/simple_json_schema/items_helper.rb,
lib/simple_json_schema/regex_helper.rb,
lib/simple_json_schema/uri_extender.rb,
lib/simple_json_schema/validators/base.rb,
lib/simple_json_schema/validators/null.rb,
lib/simple_json_schema/properties_helper.rb,
lib/simple_json_schema/validators/number.rb,
lib/simple_json_schema/validators/string.rb,
lib/simple_json_schema/validators/boolean.rb,
lib/simple_json_schema/validators/integer.rb,
lib/simple_json_schema/validators/numeric.rb,
lib/simple_json_schema/concerns/hash_acessor.rb,
lib/simple_json_schema/validators/concerns/format.rb
Defined Under Namespace
Modules: Checker, Concerns, ItemsHelper, PropertiesHelper, RefHelper, RegexHelper, URIExtender, Validators
Classes: Cache, Scope, UnsupportedMetaSchema, Validator
Constant Summary
collapse
- DRAFT_BY_SCHEMA =
{
'http://json-schema.org/draft-07/schema#' => :draft7
}.freeze
- NET_HTTP_REF_RESOLVER =
proc { |uri| JSON.parse(Net::HTTP.get(uri)) }
- DEFAULT_SCHEMA =
'http://json-schema.org/draft-07/schema#'
- VERSION =
'0.1.4'
Class Method Summary
collapse
Class Method Details
.valid(data, schema, options = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/simple_json_schema.rb', line 48
def valid(data, schema, options = nil)
if schema.is_a?(Hash)
schema = schema.with_indifferent_access
options ||= schema.delete(:options)
end
scope = Scope.new(data: data, schema: schema, draft: draft_class(schema), options: options)
Validator.validate(scope)
scope.errors
rescue StandardError => e
scope.error(:invalid, exception: e.message)
end
|
.valid?(data, schema, options = nil) ⇒ Boolean
43
44
45
46
|
# File 'lib/simple_json_schema.rb', line 43
def valid?(data, schema, options = nil)
errors = valid(data, schema, options)
errors.none?
end
|