1.0.2 • Published 3 years ago

@nqminds/schema-utils v1.0.2

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
3 years ago

@nqminds/schema-utils

Contains utility functions for working with schemas.

The dereference command can be used to convert normal JSON Schemas into a format that the TDX can understand, when creating a schema: {mode: "JS"}.

Somethings that the TDX does not like are $ref tags, $id tags, and $schema tags, so dereference takes care of that.

Install

npm install @nqminds/schema-utils

Usage

CLI

Show help

npx nqm-schema-utils --help

Dereference schemas

# the folder `./dereferenced-schemas` must already exist
npx nqm-schema-utils dereference ./schemas/*.schema.json -o ./dereferenced-schemas

Javascript API

Dereference Schema

const fetch = require("node-fetch");
const { dereference } = require("@nqminds/schema-utils");

const schemaUrl =
  "https://nqminds.github.io/cropdoc/schema/weather-data-iot.schema.json";
const schema = await (await fetch(schemaUrl)).json();
const dereferencedSchema = await dereference(schema, schemaUrl);

Tests

Tests require the environment variables TDX_ID and TDX_SECRET to be set.

Please make an application definition for them in your .env file:

TDX_ID=YOUR_APPLICATION_ID
TDX_SECRET=YOUR_APPLICATION_SECRET