abstract class SchemaWalker[A] extends AnyRef
Provides a "visitor" pattern to walk a JSON Schema document.
The walk
method visits each node in a JSON Schema document. For each
JSON Object encountered it invokes the abstract process
method
for each property defined within the JSON object. Along with each property
name and value it passes in the JSON object containing the property and
the base URI for the object. The base URI is determined by processing
$$id
properties found in the JSON Schema.
Users should implement the abstract process
method if they want to
handle properties stored in a JSON Schema document. The method should
return either an error in Error or a value
defined by the A
type generic. Since process
accumulates results
the type A
must implement a Semigroup implicit value
to combine A
elements.
Example:
val walker = new SchemaWalker[Unit] { def process((path: JsonPointer, baseUri: URI, parent: JObject, name: String, value: JValue): Validated[Error, Unit] = (name, value) match { case ("$ref", JString(uri)) => println(s"Found reference ${baseUri.resolve(uri)}") case _ => } } walker.walk(new Uri(), parse("""{ <JSON Schema Document> }"""))
- A
type returned from
process
method
- Source
- SchemaWalker.scala
- Alphabetic
- By Inheritance
- SchemaWalker
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new SchemaWalker()
Abstract Value Members
- abstract def process(path: JsonPointer, baseUri: URI, parent: JObject, name: String, value: JValue): Validated[Error, A]
Invoked for each property in a JSON Schema document.
Invoked for each property in a JSON Schema document.
The method is called when each property is visited in each JSON object in a JSON Schema document. The calling order is top-down. The method should return a Error error if an error results while processing the node, otherwise a value of generic type
A
should be given.- path
JSON Pointer containing the path for the current property
- baseUri
for the current property
- parent
object containing the current property
- name
of the current property
- value
of the current property
- returns
an
A
otherwise an error
Concrete 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
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- 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()
- def walk(baseUri: URI, jsonSchema: JObject)(implicit semigroup: Semigroup[Option[A]]): Result[Option[A]]
Walks the supplied JSON Schema calling
process
for each property.Walks the supplied JSON Schema calling
process
for each property.The JSON Schema Document is traversed in a top-down fashion with
process
called for each property found in the document. The calculation of the base URI is handled by thewalk
method by scanning for$id
properties and applying them before processing any properties in the enclosing JSON object.- baseUri
to use as the root URI (can be e an empty URI)
- jsonSchema
JSON Schema document to walk
- semigroup
used to combine return values from
process
method- returns
optional
A
value. scala.None is returned if the schema consists of a boolean value only
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.