Options
All
  • Public
  • Public/Protected
  • All
Menu

Schema.org Adapter

API documentation

This is the technical API documentation for the schema-org-adapter library.

Additional documentation is linked at the end of this page.

Setup

The readme explains the installation, loading and basic usage of this library. In any case, it is expected that the variable SOA references the library.

Node.js

const { SOA } = require('schema-org-adapter');
// or
import { SOA } from 'schema-org-adapter';

Browser

<script src="/dist/schema-org-adapter.min.js"></script>

Usage

The schema-org-adapter library itself (called SOA from now on) provides following static functions:

The most important function of SOA is .create(): it returns a new SDOAdapter instance. An SDOAdapter instance has its own settings and vocabularies, which are the base for the output given by its provided API. It is possible to pass these settings and vocabularies with a parameter object to the .create() function.

In the following common use-case the SDOAdapter instance mySdoAdapter is created with default settings and the latest version of schema.org.

const mySdoAdapter = await SOA.create({
schemaVersion: "latest"
});

After the initialization of mySdoAdapter, its API can be used to retrieve information about the schema.org vocabulary. Check the SDOAdapter reference page to discover its API. The most important methods are those that create instances for vocabulary terms:

In the following example a new Class instance is generated for the schema.org class https://schema.org/Hotel

const hotelClass = mySdoAdapter.getClass("schema:Hotel");

The term instances have their own API depending on their type. A Class instance, for example, provides a function to get all properties that the Class can use:

console.log(hotelClass.getProperties());
/* output:
* [
* 'schema:amenityFeature',
* 'schema:numberOfRooms',
* 'schema:starRating',
* 'schema:checkinTime',
* 'schema:petsAllowed',
* ...
* ]
*/

There are many more methods, options and functionalities to use! Explore them in the index page.

Additional Documentation

Data Model of SDO-Adapter

Expected Vocabulary Structure

Conversion Algorithm for Vocabularies