Data models used to drive the OpenActive validator and developer documentation.
This library provides all the JSON representations of the models in the versions/<version>/models
directory. It is capable of storing multiple versions of the spec.
The library provides various exports:
Returns a list of examples relating to the specification version supplied.
Each object in the list should contain the following keys:
const { getExamples } = require('@openactive/data-models');
const examples = getExamples('2.0');
// [
// {
// "file": "event_example_1.json",
// "name": "Example Event"
// },
// // ...
// ]
Returns a list of examples relating to the specification version supplied, that includes the JSON content of these examples.
Each object in the list should contain the following keys:
const { getExamplesWithContent } = require('@openactive/data-models');
(async () => {
const examples = await getExamplesWithContent('2.0');
// [
// {
// "file": "event_example_1.json",
// "name": "Example Event",
// "data": { ... }
// },
// // ...
// ]
})();
Returns a resolved version of a property, indicating its namespace, prefix and alias. It will by default insert the OpenActive context for the provided specification version at the top of the context tree.
const { getFullyQualifiedProperty } = require('@openactive/data-models');
let info = getFullyQualifiedProperty('type');
// {
// "prefix": null,
// "namespace": null,
// "label": "@type",
// "alias": "type",
// }
let info = getFullyQualifiedProperty('meetingPoint', '2.0');
// {
// "prefix": "oa",
// "namespace": "https://openactive.io/",
// "label": "meetingPoint",
// "alias": "meetingPoint",
// }
let info = getFullyQualifiedProperty('schema:name', '2.0');
// {
// "prefix": "schema",
// "namespace": "https://schema.org/",
// "label": "name",
// "alias": null,
// }
let info = getFullyQualifiedProperty('beta:field', '2.0');
// {
// "prefix": null,
// "namespace": null,
// "label": "beta:field",
// "alias": null,
// }
Returns the meta data relating to the specification version supplied.
The meta data should contain the following keys:
@vocab
field of the OpenActive JSON-LD definition.@graph
property of the OpenActive JSON-LD definition.
const { getMetaData } = require('@openactive/data-models');
const metaData = getMetaData('2.0');
// {
// "defaultPrefix": "schema",
// "openActivePrefix": "oa",
// "contextUrl": "https://openactive.io/",
// "specUrl": "https://openactive.io/modelling-opportunity-data/EditorsDraft/",
// "defaultActivityLists": [
// "https://openactive.io/activity-list"
// ],
// "baseGraph": {},
// "keywords": {
// "type": "@type",
// "id": "@id"
// },
// "namespaces": {
// "oa": "https://openactive.io/",
// "dc": "http://purl.org/dc/terms/",
// "owl": "http://www.w3.org/2002/07/owl#",
// "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
// "rdfa": "http://www.w3.org/ns/rdfa#",
// "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
// "schema": "https://schema.org/",
// "skos": "http://www.w3.org/2004/02/skos/core#",
// "xsd": "http://www.w3.org/2001/XMLSchema#",
// "pending": "https://pending.schema.org/"
// }
// }
Returns the model definition, augmented based on model inheritance, for a particular version of the spec.
const { loadModel } = require('@openactive/data-models');
// Returns the latest version of this model
const eventModel = loadModel('Event');
// Returns the 2.0 version of this model
const eventModel2 = loadModel('Event', '2.0');
Returns a map of raw model definitions for a particular version of the spec.
const { getModels } = require('@openactive/data-models');
// Returns the latest version of the models map
const models = getModels();
// Returns the 2.0 version of the models map
const models2 = getModels('2.0');
Returns a Set containing the fully qualified property names within the version
const { getProperties } = require('@openactive/data-models');
// Returns the latest version of the properties Set
const models = getProperties();
// Returns the 2.0 version of the properties Set
const models2 = getProperties('2.0');
Returns the bundled JSON-LD version of the schema.org vocabulary.
A hash of available versions. This includes some named aliases. You can pass the keys of this hash to any of the above methods in the version
parameter.
const { versions } = require('@openactive/data-models');
// {
// "latest": "2.x",
// "2.0": "2.x"
// }
$ git clone [email protected]:openactive/data-models.git
$ cd data-models
$ npm install
This project uses Jasmine for its tests. All spec files are located alongside the files that they target.
To run tests locally, run:
$ npm test
The test run will also include a run of eslint. To run the tests without these, use:
$ npm run test-no-lint
Add new models to the versions/models
directory.
Find more on the models, see the model reference
To release after pushing changes to git run the following:
npm test
- check tests passnpm version patch
- to bump the patch version (see semver)npm publish
- to publish to npmgit push
- to push the repo, as npm will have created git tags with the last command that need to be pusheddata-model-validator-site
in Heroku, and it will auto update (for patch and minor version bumps only, major versions are breaking changes by definition so require code changes to the other projects).