accordproject / concerto

Business schema language and runtime
https://concerto.accordproject.org
Apache License 2.0
121 stars 106 forks source link

feat(decorators): validate decorators against model #916

Closed dselman closed 1 month ago

dselman commented 1 month ago

Closes #391

Adds a new option to the model manager to validate the names and structure of decorators and their arguments:

Changes

Documentation updates: https://github.com/accordproject/concerto-docs/pull/61

Using this Model Manager configuration:

validatedModelManager = new ModelManager({
            strict: true, decoratorValidation: {
                missingDecorator: 'error',
                invalidDecorator: 'error'
            }
        });

This file will error, because it uses the undeclared decorator @Hide:

namespace test@1.0.0
concept Person {
   o String name
   @Hide
   o String ssn
   @Hide(false)
   o Integer age
}

While this file will not:

namespace test@1.0.0
import concerto.decorator@1.0.0.Decorator

concept Hide extends Decorator {
    o Boolean hidden optional
}

concept Person {
   o String name
   @Hide
   o String ssn
   @Hide(false)
   o Integer age
}

Flags

The Decorator Command Set model has been updated to support an optional namespace property for DecoratorCommand.decorator (in addition to the existing decorator name). This is required so that the DecoratorManager can create imports for the decorators that are being added to a model file. If the namespace property is missing on a decorator command then the defaultNamespace option passed to DecoratorManager is used. If both are null and a decorator is applied, and decoratorValidation is ON then the model file will be flagged by the model manager as invalid.

Screenshots or Video

Related Issues

Author Checklist