Glossary
Background
The terminology JSI uses comes from a number of sources:
- JSON Schema and its specifications
- JSON and its specification
- Tree data structure (Wikipedia)
- Object-oriented programming (Wikipedia)
- The Ruby programming language
- JSON Pointer
The terminology from these can be contradictory, e.g. 'object' in JSON meaning what is a Hash in Ruby, but 'object' in Ruby meaning any object as in object-oriented programming. This glossary aims to clarify any ambiguity and introduce any terms which may not be familiar to the reader.
Terms
- ### JSI
JSI is the name of this library. As a countable, "a JSI" refers to the library's instantiation of an instance of a set of schemas. This is a Ruby instance of a subclass of JSI::Base.
The subclass of JSI::Base which a JSI is instantiated as includes the schema module of each schema that describes the instance (its JSI::Base#jsi_schemas), as well as type-specific modules for array and hash/object instances.
- ### node
A node is an element in a document at a location identified by a pointer.
In JSI a node generally means a JSI - a JSI::Base instance is often referred to just as "a JSI", but is referred to as a node in the context of its relationship to other nodes in its document.
- ### node content
The content of a node is the parsed JSON instance. It is generally a Ruby Hash, Array, String, Integer, Float or BigDecimal, true, false, or nil.
This content is referred to as the 'instance' in relation to schemas that describe it.
See JSI::Base#jsi_node_content (also aliased as JSI::Base#jsi_instance.
- ### document
The document is the content of the root.
- ### root
A node representing the whole of a document.
Its pointer is empty (has zero tokens).
- ### complex
A node that can have children is complex. Its content is an array or a hash/object.
Hash and Array nodes can mostly be used like Ruby Hashes and Arrays. JSI defines or delegates the methods of Hash and Array with nearly perfect compatibility, and supports implicit conversion with #to_hash
and #to_ary
.
These nodes also support implicit conversion for the instance's content, treating any object responding to #to_hash
or #to_ary
like Hash or Array - though it is most common that actual Hash and Array instances will be the content. (This support may be incomplete for node content that is implicitly convertible but does not respond to certain methods, especially #[]
.)
- ### child
A node immediately below another node, its parent. Identified by one token relative to the parent.
See JSI::Base#[].
- ### parent
A node immediately above some number of other nodes, its children. A node that can be a parent node must be complex.
See JSI::Base#jsi_parent_node.
- ### descendent
A node anywhere below another node, its ancestor. Identified by a relative pointer. A node is considered to be a descendent of itself (at an empty relative pointer).
See JSI::Base#jsi_descendent_node, JSI::Base#jsi_each_descendent_node.
- ### ancestor
A node anywhere above another node, its descendent. A node is considered to be an ancestor of itself, and the root node is an ancestor of every node in the document.
See JSI::Base#jsi_ancestor_nodes.
- ### token
An array or hash/object that identifies a child node of its parent. Generally a String or non-negative Integer. JSON Pointer calls this a "reference token".
A sequence of tokens comprises a pointer.
- ### pointer
A sequence of tokens which identifies a descendent of a node, instantiated as a JSI::Ptr.
JSON Pointers are parsed to JSI pointers.
A pointer may be referred to as 'absolute' when identifying a descendent of the root node (see JSI::Base#jsi_ptr), or 'relative' identifying a descendent of any node (such as the pointer passed to JSI::Base#jsi_descendent_node).
- ### hash/object
The content of a complex JSI Hash node, representing a JSON object, is typically a Ruby Hash, or implicitly convertible with #to_hash
.
- ### array
The content of a complex JSI Array node is typically a Ruby Array, or implicitly convertible with #to_ary
.
- ### property name/key
A token identifying a child of a hash/object. In Ruby, a Hash key; in JSON Schema, an object property name. Property names are expected to be strings, though Ruby Hash keys do not have this limitation. Note that Symbols are not Strings, and Symbols should not be used in JSI [node content].
Property names can be described by schemas (using the propertyNames
keyword), and can be JSI instances of those schemas. See JSI::Base::HashNode#jsi_each_propertyName.
- ### index
A token identifying a child of an array. A non-negative integer.
- ### instance
A heavily-overloaded term. Context should make it clear in what sense it is being used. 'Instance' can refer to an object or a relationship, in Ruby or JSON Schema or JSI instantiation:
- JSON Schema: the _instance_ (JSON data) is an _instance_ (relationship) of [JSON Schemas][schema] that describe it
- Ruby: the _instance_ (an Object) is an _instance_ (relationship) of a Class and included Modules
- JSI: the _instance_ ([a JSI]) is an _instance_ (relationship) of JSI Schemas
These all operate in parallel in JSI: a JSI instance represents a JSON instance, it is described by JSI Schemas which represent JSON Schemas, and it is a Ruby instance of JSI Schema Modules of each schema that describes it.
- ### schema
A JSI Schema is a JSI that represents a JSON Schema. It is a Ruby instance of the module JSI::Schema.
A schema describes a set of instances. Any JSI instance that is described by a given schema is a Ruby instance of that schema's schema module.
A schema is described by a meta-schema and is a Ruby instance of that meta-schema's schema module.
- ### schema module
A JSI Schema Module is a Ruby module associated with a particular schema. Any JSI instance that is described by the schema is a Ruby instance of the schema's schema module. This is a JSI::SchemaModule.
See JSI::Schema#jsi_schema_module.
A JSI Schema Module is not to be confused with the module JSI::Schema - a schema is a Ruby instance of the module JSI::Schema, and it has a JSI Schema Module. The module JSI::Schema is included on the JSI Schema module of a meta-schema.
- ### meta-schema
A meta-schema is a schema that describes schemas, i.e. instances of the meta-schema are schemas.
As with any other instance, a JSI schema includes the schema module of the meta-schema that describes it. The meta-schema's schema module defines the functionality for its instances to behave as schemas, including the module JSI::Schema as well as other modules implementing functionality particular to that meta-schema.
A meta-schema is described by a meta-schema, which may be itself or another meta-schema. Examples of self-describing meta-schemas are the JSON Schema meta-schemas. An example of the latter is the schema describing the OpenAPI v3.0 Schema object, which describes schemas in OpenAPI documents, but is itself described by JSON Schema draft 04.
A self-describing meta-schema is a Ruby instance of its own schema module.
See JSI::Schema::DescribesSchema and JSI::SchemaModule::DescribesSchemaModule, JSI::Schema#describes_schema? and JSI::Schema#describes_schema!
- ### resource
A resource, or schema resource, is either:
- A schema that is identified by an absolute URI (declared with an id keyword)
- The root of a document containing schemas, whether or not the root is itself a schema. (Technically the root of any document can be considered a resource, but it is only useful when the document contains schemas.)
The nearest ancestor that is a resource is a node's "resource root" - this is distinct from the root node of the whole document.
Relative URIs and pointers used by a schema (e.g. in $ref
or $id
) are resolved relative to its resource root and that resource's id.
See JSI::Schema#schema_resource_root
- ### schema application
The computation of schemas that apply describing a node at a given location. This involves several steps:
- root indicated schemas: Application begins with the schemas (usually just one schema) indicated as describing the root.
#new_jsi
is invoked on a JSI::SchemaSet of the indicated schemas, or more commonly on one schema or schema module. These are the root's JSI::Base#jsi_indicated_schemas. - root applied schemas: in-place application is performed on each of the root indicated schemas to compute its applied schemas, i.e. its JSI::Base#jsi_schemas.
- Descending from the root to the given node, for each token of the node's pointer:
- child indicated schemas: child application is performed on each applied schema of the parent on the current token. This results in the child's indicated schemas.
- child applied schemas: in-place application is performed on each child indicated schema to compute its applied schemas.
The schemas that apply describing the node are the result of the final in-place application.
- ### child application
The computation of subschemas of a given schema that apply to a child of a complex instance on a given token. These come from subschemas defined on child applicator keywords such as properties
and items
. The result may be an empty schema set if no such keywords are present or none apply.
- ### in-place application
The resolution or expansion of a schema to a set of applied schemas for a given instance. "In-place" means all the schemas apply to the same location in the instance, in contrast to child application. This is a recursive process.
If the schema contains a
$ref
keyword:- The reference is resolved and in-place application is performed on the resolved schema.
- The schema containing the reference is not applied.
- No other applicator keywords should be present; if present they are ignored.
The resulting applied schemas are those of the reference's resolved schema.
Otherwise:
- The schema applies itself (it is added to the set of applied schemas).
- Any in-place applicator keywords (
anyOf
,dependencies
, etc.) are evaluated for subschemas that apply to the instance. For each such subschema, in-place application is performed and the resulting schemas are added to the applied schemas.
The resulting applied schemas are the given schema plus the results of in-place application of each applicable subschema.
- ### validation
The process of determining whether a given instance is valid against the schemas that describe it, or collecting validation errors indicating why the instance is not valid. See JSI::Base#jsi_valid?, JSI::Base#jsi_validate, JSI::Schema#instance_valid?, JSI::Schema#instance_validate