Packages

  • package root

    Documentation for the Axiell Schema Project

    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:

    • referential transparency. Each of the methods in the library is referentially transparent, that is if the method is called with the same arguments it will always return the same value and the method does not have any side effect (e.g. update globals, change the operating environment, etc).
    • minimal functionality. The library is designed to be small incorporating a small number of dependencies. The number of methods associated with a class/object is restricted to those that provide a base level of functionality.
    • support multiple JSON libraries. It should be possible to use the library with any number of different JSON library packages (e.g json4s, jackson, etc). The current library only supports json4s, but a facade approach should be added to hide individual library implementations.
    • generic "format" implementations. The JSON Schema specification mandates a standard set of "format" types that can be used to validate string values. Each "format" type is implemented as a class with the components of the type available.
    • full error handling. Error resulting from the validation process are returned as a list of validation failures. All possible errors should be returned for a single call, eliminating the need to fix a single error and then recall a method.

    Package structure

    The com.axiell.schema 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.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.

    The second component (com.axiell.schema.SchemaValidator) 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.

    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 a Schema 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 to JValue class).
    • various auxiliary classes for handling "format" types including:

    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 the Validated class used to return lists of validation errors.
    Definition Classes
    root
  • package com
    Definition Classes
    root
  • package axiell
    Definition Classes
    com
  • package schema

    Contains types used by the library.

    Contains types used by the library.

    In order to simplify method signatures a series of types are defined. The types are used throughout the library.

    Definition Classes
    axiell
  • package instances
    Definition Classes
    schema
  • package syntax
    Definition Classes
    schema
  • Assertions
  • Context
  • EmailAddress
  • Formats
  • Hostname
  • Implicits
  • Ipv4Address
  • Ipv6Address
  • JsonPointer
  • RelativeJsonPointer
  • Resolver
  • Schema
  • SchemaValidator
  • SchemaWalker
  • Validator
o

com.axiell.schema

Assertions

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
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Assertions
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. 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"

  5. 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"

  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. 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"

  9. 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"

  10. 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"

  11. 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"

  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  14. 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"

  15. 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"

  16. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  17. 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"

  18. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  20. 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"

  21. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  22. 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"

  23. 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"

  24. 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"

  25. 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"

  26. 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"

  27. 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"

  28. 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"

  29. 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"

  30. 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"

  31. 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"

  32. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  33. 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"

  34. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  35. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  36. 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"

  37. 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"

  38. 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"

  39. 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"

  40. 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"

  41. 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"

  42. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  43. def toString(): String
    Definition Classes
    AnyRef → Any
  44. 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"

  45. 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"

  46. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  47. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  48. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped