1.0.2 • Published 4 years ago
@nqminds/schema-utils v1.0.2
@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-utilsUsage
CLI
Show help
npx nqm-schema-utils --helpDereference schemas
# the folder `./dereferenced-schemas` must already exist
npx nqm-schema-utils dereference ./schemas/*.schema.json -o ./dereferenced-schemasJavascript 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