module SimpleJSONSchema
Constants
- CUSTOM_DRAFT7
Draft-7 whit custom settings.
- DEFAULT_SCHEMA
- DRAFT_BY_SCHEMA
- NET_HTTP_REF_RESOLVER
- VERSION
Public Class Methods
valid(data, schema, options = nil)
click to toggle source
# File lib/simple_json_schema.rb, line 50 def valid(data, schema, options = nil) if schema.is_a?(Hash) schema = schema.with_indifferent_access options ||= schema.delete(:options) end options = options.with_indifferent_access if options.is_a?(Hash) 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)
click to toggle source
# File lib/simple_json_schema.rb, line 45 def valid?(data, schema, options = nil) errors = valid(data, schema, options) errors.none? end
Private Class Methods
draft_class(schema)
click to toggle source
# File lib/simple_json_schema.rb, line 67 def draft_class(schema) meta_schema = schema.is_a?(Hash) && schema.key?('$schema') ? schema['$schema'] : DEFAULT_SCHEMA DRAFT_BY_SCHEMA[meta_schema] || raise(UnsupportedMetaSchema, meta_schema) end