object Assertions
Implements all the assertions required for JSON Schema Draft #7
A JSON Schema document is made up of a number of assertions. The application of the assertions depends on the structure and content of the JSON data object being validated. Each assertion is implemented as a method in this object. The assertions are called from the Validator object.
Each assertion returns a
ValidatorResult which contains
either a Valid Unit
value indicating
the assertion was met, or an Invalid
value containing a NonEmptyList of
Error messages detailing why the assertion
failed.
- Source
- Assertions.scala
- Alphabetic
- By Inheritance
- Assertions
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def allOf(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "allOf" property.
Validate the JSON Schema "allOf" property.
The "allOf" property provides a mechanism to ensure a list of assertions all validate.
- value
array of subschemas to be validated
- json
data to validate against all the subschemas
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.7.1"
- def anyOf(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "anyOf" property.
Validate the JSON Schema "anyOf" property.
The "anyOf" property provides a mechanism to ensure that at least one assertion validates in a list of assertions.
- value
array of subschemas to be validated
- json
data to validate against all the subschemas
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.7.2"
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def const(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "const" property.
Validate the JSON Schema "const" property.
The "const" property checks that a JSON element's value matches a single value.
- value
of the constant
- json
value that must match the constant
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.1.3"
- def contains(value: JValue, json: JArray, context: Context): ValidatorResult
Validate the JSON Schema "contains" property.
Validate the JSON Schema "contains" property.
The "contains" property specifies a subschema that must validate against at least one entry in a JSON array. If no valid entries are found an error is generated.
- value
that must occur at least once in the JSON array
- json
array against which to check for match
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.4.6"
- def dependencies(value: JValue, json: JObject, context: Context): ValidatorResult
Validate the JSON Schema "dependencies" property.
Validate the JSON Schema "dependencies" property.
The "dependencies" property specifies a JSON object. If a property name matches an entry in the dependencies object then validation takes place for that entry. The validation is one of two types. The first is that if the value is an object and hence a subschema then the data object must validate against the subschema. This is similar to the "properties" keyword except the validation occurs on the parent object, rather than the value.
The second interpretation is that if the value is an array, it must contain string entries, where each entry is a property name. In this case each property name listed must occur in the current data object. This is similar to the "required" property except that it allows for conditional entries that only apply where the schema property name matches a data object name.
- value
subschema or array to validate data object against
- json
object to be validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.5.7"
- def enum(values: JValue, json: JValue, context: Context): ValidatorResult
Validates the JSON Schema "enum" property.
Validates the JSON Schema "enum" property.
The "enum" property checks that a JSON element's value is on in a list of values.
- values
that form the enumeration to be checked
- json
value to check against the enumeration
- context
containing validator state information
- returns
Unit
if validates, otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.1.2"
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exclusiveMaximum(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "exclusiveMaximum" property.
Validate the JSON Schema "exclusiveMaximum" property.
The "exclusiveMaximum" property defines an upper limit for a value in a numerical property. The maximum value is exclusive, that is the value must be below the maximum.
- value
maximum exclusive value
- json
value to be tested against the maximum
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.2.3"
- def exclusiveMinimum(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "exclusiveMinimum" property.
Validate the JSON Schema "exclusiveMinimum" property.
The "exclusiveMinimum" property defines a lower limit for a value in a numerical property. The minimum value is exclusive, that is the value must be above the minimum.
- value
minimum exclusive value
- json
value to be tested against the minimum
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.2.5"
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def format(value: JValue, json: JString, context: Context): ValidatorResult
Validate the JSON Schema "format" property.
Validate the JSON Schema "format" property.
The "format" property specifies the type of a value stored in a JSON string. Since JSON supports only a small number of types complex types, like dates, etc are stored as a string. The format property allows validation to be performed against that string for complex types.
- value
containing the format name to be checked
- json
string against which the format is to be validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 7.3"
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def ifThenElse(jsonSchema: JObject, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "if/then/else" property.
Validate the JSON Schema "if/then/else" property.
The "if/then/else" property provides a way for specifying conditional valuations.
- jsonSchema
object containing the if/then/else properties
- json
value to validate against if/then/else
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.6.1-6.6.3"
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def items(jsonSchema: JObject, json: JArray, context: Context): ValidatorResult
Validate the JSON Schema "items" and "additionalItems" properties.
Validate the JSON Schema "items" and "additionalItems" properties.
The "items" property is either a subschema or array of subschemas. If a subschema is specified then each entry in a JSON data array must validate against that subschema. Where an array of subschemas is specified then indexes in the JSON data array must validate against its corresponding index in the array of subschemas. If a corresponding index does not exist in the schema array then the subschema specified by the "additionaItems" property is used.
- jsonSchema
of object containing "items" and "additionalItems"
- json
array to validate against
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.4.1, 6.4.2"
- def maxItems(value: JValue, json: JArray, context: Context): ValidatorResult
Validate the JSON Schema "maxItems" property.
Validate the JSON Schema "maxItems" property.
The "maxItems" property specifies the maximum number of entries that can occur in a JSON array.
- value
specifying the maximum number of array elements
- json
array against which the maximum is to be validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.4.3"
- def maxLength(value: JValue, json: JString, context: Context): ValidatorResult
Validate the JSON Schema "maxLength" property.
Validate the JSON Schema "maxLength" property.
The "maxLength" property specifies the maximum length for a string value. The length must be greater than or equal to zero.
- value
specifying the maximum string length
- json
string against which to test the length
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.3.1"
- def maxProperties(value: JValue, json: JObject, context: Context): ValidatorResult
Validate the JSON Schema "maxProperties" property.
Validate the JSON Schema "maxProperties" property.
The "maxProperties" property specifies the maximum number of properties that can occur in a JSON object.
- value
specifying the maximum number of properties
- json
object against which the maximum is to be validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.5.1"
- def maximum(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "maximum" property.
Validate the JSON Schema "maximum" property.
The "maximum" property defines an upper limit for a value in a numerical property. The maximum value is inclusive.
- value
maximum inclusive value
- json
value to be tested against the maximum
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.2.2"
- def minItems(value: JValue, json: JArray, context: Context): ValidatorResult
Validate the JSON Schema "minItems" property.
Validate the JSON Schema "minItems" property.
The "minItems" property specifies the minimum number of entries that can occur in a JSON array.
- value
specifying the minimum number of array elements
- json
array against which the minimum is to be validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.4.4"
- def minLength(value: JValue, json: JString, context: Context): ValidatorResult
Validate the JSON Schema "minLength" property.
Validate the JSON Schema "minLength" property.
The "minLength" property specifies the minimum length for a string value. The length must be greater than or equal to zero.
- value
specifying the minimum string length
- json
string against which to test the length
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.3.2"
- def minProperties(value: JValue, json: JObject, context: Context): ValidatorResult
Validate the JSON Schema "minProperties" property.
Validate the JSON Schema "minProperties" property.
The "minProperties" property specifies the minimum number of properties that can occur in a JSON object.
- value
specifying the minimum number of properties
- json
object against which the minimum is to be validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.5.2"
- def minimum(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "minimum" property.
Validate the JSON Schema "minimum" property.
The "minimum" property defines a lower limit for a value in a numerical property. The minimum value is inclusive.
- value
minimum inclusive value
- json
value to be tested against the minimum
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.2.4"
- def multipleOf(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "multipleOf" property.
Validate the JSON Schema "multipleOf" property.
The "multipleOf" property tests whether a numeric value is divisible by a number wiht zero remainder. It is equivalent to the mathematical mod operator with a zero result.
- value
of the divisor
- json
value to be divided
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.2.1"
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def not(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "not" property.
Validate the JSON Schema "not" property.
The "not" property provides a mechanism to reverse the sense of an assertion.
- value
subschema to validate and reverse outcome
- json
data to validate against the subschema
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.7.4"
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def oneOf(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "oneOf" property.
Validate the JSON Schema "oneOf" property.
The "oneOf" property provides a mechanism to ensure that only one assertion validates in a list of assertions.
- value
array of subschemas to validate against
- json
data to validate against the subschemas
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.7.3"
- def pattern(value: JValue, json: JString, context: Context): ValidatorResult
Validate the JSON Schema "pattern" property.
Validate the JSON Schema "pattern" property.
The "pattern" property checks whether a value matches a regular expression. The regular expression conforms to the ECMA 262 dialect.
- value
containing the regular expression to test
- json
string against which to test the pattern
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.3.3"
- def properties(jsonSchema: JObject, json: JObject, context: Context): ValidatorResult
Validate the JSON Schema "properties", "patternProperties" and "additionalProperties" properties.
Validate the JSON Schema "properties", "patternProperties" and "additionalProperties" properties.
The "properties" property specifies a JSON object where each property name is validated against the same name ins a JSON object. Where the name matches the value is validated against the schema's value.
The "patternProperties" property is similar to the "properties" keyword except each name in the object is a pattern rather than a string. Each JSON object name is checked against each pattern and where a match occurs the data is validated against the schema value.
The "additionalProperties" property is matched only where no match exists against the "properties" or "patternProperties" names.
- jsonSchema
schema object containing the three keywords
- json
object against which the property names are validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.5.4, 6.5.5, 6.5.6"
- def propertyNames(value: JValue, json: JObject, context: Context): ValidatorResult
Validate the JSON Schema "propertyNames" property.
Validate the JSON Schema "propertyNames" property.
The "propertyNames" property specifies a subschema against which each property name must validate.
- value
subschema against which all data property names are checked
- json
object whose property names are to be validated
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.5.8"
- def readOnly(value: JValue, json: JValue, context: Context): ValidatorResult
Validate the JSON Schema "readOnly" property.
Validate the JSON Schema "readOnly" property.
The "readOnly" property indicates that a value cannot be assigned to a given property for the storage version of a record. The retrieval version does allow assignment to the property.
- value
JSON boolean whether read only applies
- json
value indicating whether a value has been set
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 10.3"
- def required(value: JValue, json: JObject, context: Context): ValidatorResult
Validate the JSON Schema "required" property.
Validate the JSON Schema "required" property.
The "required" property specifies an array of properties that must exist in a JSON object. In effect it allows mandatory properties to be listed.
- value
array of property names that must exist
- json
object against which the property names are checked
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.5.3"
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def types(values: JValue, json: String, context: Context): ValidatorResult
Validates the JSON Schema "type" property.
Validates the JSON Schema "type" property. The "type" property is used to assert that a JSON element must be of a given type.
- values
types to check against the
json
value- json
type of the JSON data node to check
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.1.1"
- def uniqueItems(value: JValue, json: JArray, context: Context): ValidatorResult
Validate the JSON Schema "uniqueItems" property.
Validate the JSON Schema "uniqueItems" property.
The "uniqueItems" property is a JSON boolean indicating whether the entries in a JSON array must be unique. Each entry is compared against all other entries to ensure they are unique.
- value
boolean indicating whether array element should be unique
- json
array against which to check for uniqueness
- context
containing validator state information
- returns
Unit
if validates otherwise a list of errors
- See also
"JSON Schema draft #7, section 6.4.5"
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Documentation for the Axiell Schema Project
Overview
The Axiell Schema Project provides a small library for validating JSON documents against a JSON Schema. The library conforms to the JSON Schema Draft #7 specification.
The library is based on a few simple principles, namely:
Package structure
The
packages consists of a number of utilities, where each utility provides a single piece of functionality. Since the library validates JSON structures two main components are provided. The first component (com.axiell.schema
) allows JSON documents conforming to the JSON Schema specification to be read. Once read a resolution process may be required to resolve any external references defined in the document.com.axiell.schema.Schema
The second component (
) takes a resolved schema and allows JSON documents to be validated against that schema. When creating a validator it is also possible to incorporate your own "format" types for validation.com.axiell.schema.SchemaValidator
A set of auxiliary components implement parsers for many of the "format" types and can be used independently of the validator itself.
Notable utilities are:
Schema
wrapper around a JSON document containing the document itself, its$id
value and resolution mappings for all$id
and$ref
directives.SchemaValidator
takes aSchema
and an optional handler for "format" types and provides a validation method for arbitrary JSON documents.Implicits
implements implicit methods and classes used to convert one class to another or pimp methods onto existing classes (e.g.same()
method toJValue
class).EmailAddress
Hostname
Ipv4Address
Ipv6Address
JsonPointer
RelativeJsonPointer
Dependencies
The list of dependencies are:
Axiell Util Library
provides error handling classes and methods that allow multilingual error messages to be generated.JSON for Scala Library
provides mthods for dealing with JSON structures. The routines work around an AST (Abstract Syntax Tree) used to represent a JSON document.Cats Functional Programming Library
provides various traits, classes and methods that simplify functional programming in Scala. Also provides theValidated
class used to return lists of validation errors.