Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add validation of model files against metamodel #684

Merged
merged 7 commits into from
Aug 16, 2023

Conversation

mttrbrts
Copy link
Sponsor Member

@mttrbrts mttrbrts commented Aug 11, 2023

Closes #678

Adds an extra validation step in the ModelManager to validate ModelFile object against the Metamodel definition.

When opting into this feature:

  • In strict mode, invalid models will now throw an error.
  • In the default non-strict mode, a console warning is printed.

Turn on the feature with a parameter to the ModelManager constructor, e.g.

new ModelManager({ metamodelValidation: true });

Changes

  • Adds a new MetamodelException class to report errors found while validating the ModelFile
  • Adds a new private function on the BaseModelManager that is used when adding a model file.

Flags

  • Ideally, I would have liked to build a separate ModelManager instance purely for this purpose. However, this introduced issues with circular dependencies (a ModelManager would then contain a ModelManager!). This approach mutates the client's ModelManager temporarily; this should be safe if we clean up properly after ourselves.
  • We also have to disable validation when adding the RootModel to a ModelManager because it is now a pre-requisite for metamodel validation

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

Signed-off-by: Matt Roberts <code@rbrts.uk>
@mttrbrts mttrbrts requested a review from a team August 11, 2023 13:12
Signed-off-by: Matt Roberts <code@rbrts.uk>
Signed-off-by: Matt Roberts <code@rbrts.uk>
Signed-off-by: Matt Roberts <code@rbrts.uk>
@mttrbrts mttrbrts enabled auto-merge (squash) August 16, 2023 12:53
Signed-off-by: Matt Roberts <code@rbrts.uk>
@mttrbrts mttrbrts merged commit b2469e4 into accordproject:main Aug 16, 2023
12 checks passed
This was referenced Sep 4, 2023
@mttrbrts mttrbrts modified the milestone: v4.0 Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsed models are not validated against the metamodel
3 participants