Module: JSONSchemer

Defined in:
lib/json_schemer.rb,
lib/json_schemer/format.rb,
lib/json_schemer/version.rb,
lib/json_schemer/schema/base.rb,
lib/json_schemer/schema/draft4.rb,
lib/json_schemer/schema/draft6.rb,
lib/json_schemer/schema/draft7.rb

Defined Under Namespace

Modules: Format, Schema Classes: UnknownRef, UnsupportedMetaSchema

Constant Summary collapse

DRAFT_CLASS_BY_META_SCHEMA =
{
  'http://json-schema.org/draft-04/schema#' => Schema::Draft4,
  'http://json-schema.org/draft-06/schema#' => Schema::Draft6,
  'http://json-schema.org/draft-07/schema#' => Schema::Draft7
}.freeze
DEFAULT_META_SCHEMA =
'http://json-schema.org/draft-07/schema#'
VERSION =
'0.1.4'

Class Method Summary collapse

Class Method Details

.schema(schema, **options) ⇒ Object



22
23
24
25
26
# File 'lib/json_schemer.rb', line 22

def self.schema(schema, **options)
  meta_schema = schema.is_a?(Hash) && schema.key?('$schema') ? schema['$schema'] : DEFAULT_META_SCHEMA
  draft_class = DRAFT_CLASS_BY_META_SCHEMA[meta_schema] || raise(UnsupportedMetaSchema, meta_schema)
  draft_class.new(schema, **options)
end