Class: JSON::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/json/schema.rb,
lib/json/schema/leaf.rb,
lib/json/schema/null.rb,
lib/json/schema/array.rb,
lib/json/schema/number.rb,
lib/json/schema/object.rb,
lib/json/schema/string.rb,
lib/json/schema/boolean.rb,
lib/json/schema/integer.rb,
lib/json/schema/version.rb

Overview

The JSON::Schema class represents a JSON schema, and provides methods that let you describe and produce a schema that can be used in various contexts that include the validation and generation of JSON data.

Examples:

schema = JSON::Schema.new
schema.object({
  name: schema.string.enum("John", "Jane").required,
  age: schema.integer.required,
  hobbies: schema.array(schema.string, schema.null).required,
  address: schema.object({street: schema.string}).required,
})

See Also:

Defined Under Namespace

Classes: Array, Booelean, Integer, Leaf, Null, Number, Object, String

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#numberJSON::Schema::Number

Returns a number

Returns:



60
61
62
# File 'lib/json/schema.rb', line 60

def number
  Number.new
end

#array(*items) ⇒ JSON::Schema::Array

Returns an array

Parameters:

  • items (Array)

    An array of items

Returns:



46
47
48
# File 'lib/json/schema.rb', line 46

def array(*items)
  Array.new(*items)
end

#stringJSON::Schema::String

Returns a string



53
54
55
# File 'lib/json/schema.rb', line 53

def string
  String.new
end

#object(properties) ⇒ JSON::Schema::Object

Returns an object

Parameters:

  • properties (Hash)

    A hash of properties

Returns:



38
39
40
# File 'lib/json/schema.rb', line 38

def object(properties)
  Object.new(properties)
end

#integerJSON::Schema::Integer

Returns an integer



67
68
69
# File 'lib/json/schema.rb', line 67

def integer
  Integer.new
end

#booleanJSON::Schema::Boolean

Returns a boolean

Returns:

  • (JSON::Schema::Boolean)


74
75
76
# File 'lib/json/schema.rb', line 74

def boolean
  Boolean.new
end

#nullJSON::Schema::Null

Returns null

Returns:



81
82
83
# File 'lib/json/schema.rb', line 81

def null
  Null.new
end