OntoUML / ontouml-schema

JSON Schema definition of a OntoUML Model Exchange file.
Apache License 2.0
9 stars 4 forks source link

Features/improvements #1

Closed claudenirmf closed 4 years ago

claudenirmf commented 4 years ago

This PR updates the ontouml-schema to have a schema exclusive for OntoUML 2. In the future, related schemas and schemas for other language versions shall be added.

Please remember to run npm install before testing/running the project.

How to use

The code excerpt bellow, examplifies how to use the ontouml-schema project to validate objects representing OntoUML 2 models:

const schemas = require('ontouml-schema');
const Ajv = require('ajv');

let validator = new Ajv().compile(schemas.getSchema(schemas.ONTOUML_2));
let model = {
    "@type": "Model",
    "id": "m1",
    "name": "My Model",
    "authors": null,
    "elements": null
};
let isValid = validator(model);

if(isValid) {
    console.log(`Model ${model.name} is valid!`);
}
else {
    console.log(`Model ${model.name} is NOT valid!`);
    console.log(validator.errors);
}

How to test

From within the project folder, run npm run test or jest, in case the later is globally installed.