README
Smartmate Schemas
Schemas for validating a smartmate workspace and its components.
Installation
yarn add smartmate-schemas
# or npm i smartmate-schemas
Usage
This module will return an instance of Ajv, loaded will all the smartmate schemas.
const schemas = require('smartmate-schemas');
const isValid = schemas.validate('workspaces/smartmate-file.schema', myWorkspaceJson);
if (!isValid) console.log(schemas.errors);
# [] or [{"app":{"yourApp":{"errors":[{"keyword":"enum","dataPath":".spec.menu[0].type","schemaPath":"#/definitions/menuItem/properties/type/enum","params":{"allowedValues":["table"]},"message":"should be equal to one of the allowed values"}]}}}]
Development
Local check
const schemas = require('./src');
const isFormValid = schemas.validate('forms/form.schema', {
'name': 'MyForm',
'rows': [
'field1',
{
'isActive': {
'label': 'IS ACTIVE',
},
},
'_parent(table.field)',
'_parent(table.field).name',
],
});
if (!isFormValid) {
console.error(schemas.errors);
}
Adding a new field type
Under schemas/field/types
directory create a new directory with the name of your new type and add the following files inside:
<your-new-type>.valid.yaml
- A valid example of the new type.<your-new-type>.schema.json
- Actual JSON schema for validation.<your-new-type>.methods-to-invalidate.js
- Methods for unit testing the schema.
Finally add a new entry for your new type in schemaFiles.js
Adding a new row type for forms
Under schemas/form/rows/types
directory create the following files:
<your-new-type>.valid.yaml
- A valid example of the new type.<your-new-type>.schema.json
- Actual JSON schema for validation.<your-new-type>.methods-to-invalidate.js
- Methods for unit testing the schema (tests that will fail).
Add your new type in src/schemaFile.js
file:
...
'forms/rows/types/<your-new-type>.schema.json',
...
Finally, add a new entry under anyOf
in schemas/forms/rows/row.schema.json
:
...
"anyOf": {
...
{ "$ref": "https://schemas.apps.smartmate.io/forms/rows/types/<your-new-type>.schema.json"}
}