The National Registration entity schema, which I developed with one of several free schema validation tools available online , consists of three text fields, host Nation Name, ship Name, and owner Name, which are constrained only by a regular expression pattern that requires them to be at least four characters long and begin with a capital letter. There is also a registration Number which must be exactly ten numeric digits, as well as the registration Date and the Expiration Date, which must both be in YYYY-MM-DD format. All fields are required. The schema is shown below with some portions collapsed for brevity.
The first part of the script, shown below, ensures that the console is visible, prompts the user for the name of the schema file and reads it in. The technique I use here is patterned after a jArchi script by Steven Mileham .
The script next parses the JSON schema and adds information from it to the Archi model. It begins by capturing the schema attributes that occur only once, i.e., the title and description, and then initializing a counter:
The script then cycles through all the ArchiMate elements (as opposed to relationships) that are selected. It first sets the name, the documentation, and stereotype of each element that is selected, and then cycles through the properties in the schema object. For each property object, it creates a working copy called “props”, and fashions a string consisting of the description followed by a dictionary of all the remaining attributes (except $id which I omit). The script then sets the corresponding model element property to that descriptive string. It also accumulates a list of attribute names separated by newline characters, which it ultimately assigns to the element property “attributes”. After it has set all properties for all selected elements as shown in the excerpt below, it reports on the number of elements it has updated and terminates.
The Label Expression
The label consists of simple formatting and successive references to the stereotype property, the element name and documentation, and the attributes property.
The selected element, a data object in this case, is identified as an ERD component, and is labeled with the title and description from the schema object, as well as a list of the schema object properties.
In addition, the element has a set of properties that correspond to the properties in the JSON schema, each consisting of a description followed by a dictionary:
Opportunities for Future Work
This script could be further developed to reverse-engineer SQL DDL by leveraging an open-source package that converts JSON schema to DDL. It could be applied to situations where many objects require the same metadata, such as in the creation of business capability models. The script could be enhanced to work on a larger scale through simple performance optimization; right now, the schema object parsing is repeated for each selected object. Finally, along with the script described in the previous article, it could become part of a suite for modeling large schemas by creating and linking model concepts from an imported file instead of just manipulating their properties.
The generation of model element attributes from JSON Schema files provides additional evidence that Archi and its jArchi plugin can support data modeling through the implementation and management of data modeling profiles for the ArchiMate language. There are many opportunities for ArchiMate modelers and tool builders to contribute to this work.
- Archi – Open Source ArchiMate Modeling. https://www.archimatetool.com/
- jArchi – Scripting for Archi. https://www.archimatetool.com/plugins/#jArchi
- ArchiMate Standard – Adding Attributes to ArchiMate Elements and Relationships. https://pubs.opengroup.org/architecture/archimate3-doc/chap15.html#_Toc10045465
- Data Modeling with Archi. https://www.eaprincipals.com/content/data-modeling-archi
- JSON Schema. https://json-schema.org/
- LinkedIn Comment by J-B Sarrodie https://www.linkedin.com/feed/update/urn:li:activity:6738567508346974208?commentUrn=urn%3Ali%3Acomment%3A%28activity%3A6738567508346974208%2C6738772420854853632%29
- SQL DDL to JSON Schema NPM Package.
- ECMAScript 6 – New Features: Overview & Comparison. http://es6-features.org/
- Nashorn Engine. https://docs.oracle.com/javase/10/nashorn/introduction.htm
- JSON Schema Validator. https://www.jsonschemavalidator.net/
- jArchi Script: Import from CSV.ajs. https://gist.github.com/smileham/1e57a5946235e780dee5a824f664aa3d