JsDoc Reference - JSONSchema

Class Index | File Index

## Classes

- Environment
- InitializationError
- JSONInstance
- JSONSchema
- JSV
- Report
- ValidationError

# Class JSONSchema

Extends JSONInstance.
Defined in: jsv.js.

Class Summary
Constructor Attributes | Constructor Name and Description
--- | ---
| JSONSchema(env, json, uri, schema) This class binds a JSONInstance with a JSONSchema to provided context aware methods.

Method Summary
Method Attributes | Method Name and Description
--- | ---
| getAttribute(key, arg) Returns the value of the provided attribute name.
| getAttributes() Returns all the attributes of the schema.
| getLink(rel, instance) Convenience method for retrieving a link or link object from a schema.
| getReference(name) Returns the value of the provided reference name.
| getSchema() Returns the schema of the schema.
| setReference(name, uri) Set the provided reference to the given value.
| validate(instance, report, parent, parentSchema, name) Validates the provided instance against the target schema and returns a Report.

Methods borrowed from class JSONInstance:
  equals, getEnvironment, getProperties, getProperty, getPropertyNames, getType, getURI, getValue, getValueOfProperty, resolveURI

Class Detail
JSONSchema(env, json, uri, schema)
This class binds a JSONInstance with a JSONSchema to provided context aware methods.

Parameters:
{Environment} env
  The environment this schema belongs to
{JSONInstance|Any} json
  The value of the schema
{String} uri Optional
  The URI of the schema. If undefined, the URI will be a randomly generated UUID.
{JSONSchema|Boolean} schema Optional
  The schema to bind to the instance. If `undefined`, the environment's default schema will be used. If `true`, the instance's schema will be itself.

Method Detail
{JSONSchema|Any} getAttribute(key, arg)
Returns the value of the provided attribute name.

This method is different from JSONInstance#getProperty as the named property is converted using a parser defined by the schema's schema before being returned. This makes the return value of this method attribute dependent.

Parameters:
{String} key
  The name of the attribute
{Any} arg Optional
  Some attribute parsers accept special arguments for returning resolved values. This is attribute dependent.

Returns:
  {JSONSchema|Any} The value of the attribute

{Object} getAttributes()
Returns all the attributes of the schema.

Returns:
  {Object} A map of all parsed attribute values

{String|Object|undefined} getLink(rel, instance)
Convenience method for retrieving a link or link object from a schema. This method is the same as calling `schema.getAttribute("links", [rel, instance])[0];`.

Parameters:
{String} rel
  The link relationship
{JSONInstance} instance Optional
  The instance to resolve any URIs from

Returns:
  {String|Object|undefined} If `instance` is provided, a string containing the resolve URI of the link is returned. If `instance` is not provided, a link object is returned with details of the link. If no link with the provided relationship exists, `undefined` is returned.

See:
  JSONSchema#getAttribute

{String} getReference(name)
Returns the value of the provided reference name.

Parameters:
{String} name
  The name of the reference

Returns:
  {String} The value of the provided reference name

{JSONSchema} getSchema()
Returns the schema of the schema.

Returns:
  {JSONSchema} The schema of the schema

setReference(name, uri)
Set the provided reference to the given value.
References are used for establishing soft-links to other JSONSchemas. Currently, the following references are natively supported:

`full`
  The value is the URI to the full instance of this instance.
`describedby`
  The value is the URI to the schema of this instance.

Parameters:
{String} name
  The name of the reference
{String} uri
  The URI of the schema to refer to

{Report} validate(instance, report, parent, parentSchema, name)
Validates the provided instance against the target schema and returns a Report.

Parameters:
{JSONInstance|Any} instance
  The instance to validate; may be a JSONInstance or any JavaScript value
{Report} report Optional
  A Report to concatenate the result of the validation to. If `undefined`, a new Report is created.
{JSONInstance} parent Optional
  The parent/containing instance of the provided instance
{JSONSchema} parentSchema Optional
  The schema of the parent/containing instance
{String} name Optional
  The name of the parent object's property that references the instance

Returns:
  {Report} The result of the validation

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Sep 14 2011 18:53:24 GMT-0600 (MDT)