
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@openstapps/core-validator
Advanced tools
StAppsCore Validator - validator of instances (objects, e.g. SCThings) against JSON schema files
The StAppsCore (SC) is a generalized model of data.
SC is based on the idea of schema.org. The SC structures data by describing objects as so called SC-types like: Event, Place, Date, Person, ...
Data sources of the same type of data are assigned to the same SC-type.
The StAppsCore Validator is a tool for run-time validation of objects (determining wether a JavaScript/JSON object is a valid object of the corresponding SC-type. It consumes JSON schema files from StAppsCore as the definitions of SC-types against which are validated concrete (actual) objects (as an example SCDish object in the example below).
You can use the validator programatically:
import {SCValidator} from '@openstapps/core-validator';
import {SCDish} from '@openstapps/core';
import {ValidatorResult} from 'jsonschema';
import {join} from 'path';
const objectToValidate: SCDish = {
type: 'Dish',
// more properties
};
// instantiate a new validator
const validator = new SCValidator(join('path', 'to', 'schema', 'files'));
// make the validator read the schema files
validator.feedValidator();
// validate an object
const result: ValidatorResult = validator.validate(objectToValidate);
The JSON files passed to the validateFiles method have an added layer. That layer encapsulates the actual JSON data of the object to be verified and adds a property to enable true negative testing.
Your basic JSON object:
{
"property1": "value1",
"property2": "value2",
...
}
JSON for validateFiles:
{
"validationErrorNames": [],
"scData":{
"property1": "value1",
"property2": "value2",
...
}
}
Where validationErrorNames holds the string values of the name property of the expected ValidationErrors from JSON Schema.
Empty array means no errors are expected.
Installation of the npm package (using npm install) makes the tool available as an executable with the name openstapps-validate.
The command openstapps-validate can then be called using two required arguments and one optional:
node_modules/.bin/openstapps-validate <schemadir> <resdir> [reportDir]
where:
<schemadir> is a directory (relative path to the current directory) where JSON schema files are, e.g. lib/schema,<resdir> is a directory (relative path to the current directory) where test files are, e.g. src/test/resources,[reportDir] is a directory where HTML report of the validation will be saved to, e.g. report (optional argument - if it's not provided report will be used).Command with the example arguments is then for example:
node_modules/.bin/openstapps-validate lib/schema src/test/resources
Inside of a script in package.json or if the npm package is installed globally, the tool openstapps-validate can be called without its local path (node_modules/.bin):
openstapps-validate <schemadir> <resdir> [reportDir]
FAQs
StAppsCore Validator - validator of instances (objects, e.g. SCThings) against JSON schema files
We found that @openstapps/core-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.