Skip to content

Latest commit

 

History

History
93 lines (64 loc) · 3.08 KB

resource.md

File metadata and controls

93 lines (64 loc) · 3.08 KB

Resource Object

Every File in a JsonSchema object contains an array of Resource objects. Each Resource object represents a JSON Schema Resource in the file. Every file has at least one resource.

TIP: Read Understanding Schema Structure to learn how all the different objects in our object model are related.

Source Code

You can view the source code for the JsonSchema object here.

Properties

This is the JsonSchema object that contains this resource.

if (resource.schema.rootResource === resource) {
  console.log("This is the root resource of the schema");
}

This is the File object that contains this resource.

console.log(`This resource is in ${resource.file.path}`);

The absolute, canonical URI (Uniform Resource Identifier) of the resource. Note that this does not necessarily correspond to a physical file on disk, or a URL (Uniform Resource Locator) that can be downloaded.

console.log(resource.uri.href);

locationInFile (Pointer object)

A JSON Pointer that indicates the resource's location in the file.

console.log(`This resource is at ${resource.locationInFile.path} in ${resource.file}`);

data (anything)

The resource data. This can be any JavaScript value, but will usually be one of the following:

  • object
    If the resource is a JSON Schema document that has already been parsed.

  • string
    If the resource is in text-based data that has not yet been parsed. This includes JSON, YAML, HTML, SVG, CSV, plain-text, etc.

  • ArrayBuffer
    If the resource contains binary data, such as an image.

resource.data = {
  $id: "person",
  title: "Person",
  properties: {
    name: { type: "string" },
    age: { type: "integer" },
  }
};

anchors (array of Anchor objects)

An array of all the JSON Schema anchors (i.e. $anchor) in the resource.

for (let anchor of resource.anchors) {
  console.log(anchor.uri.href);
}

references (iterable of Reference objects)

An array of all the JSON Schema references (i.e. $ref) in the resource.

for (let ref of resource.references) {
  console.log(`${ref.locationInFile.path} points to ${ref.targetURI.href}`);
}