Skip to content

002_0007 - AvoidUsingValidationRules

Avoid using validation rules for domain model.

Remove datamodel validation rules.

Metadata

authors:
- Viktor Berlov <viktor@cinaq.com>
category: Maintainability
input: '*/DomainModels$DomainModel.yaml'
rulename: AvoidUsingValidationRules
rulenumber: '002_0007'
scope: package
severity: MEDIUM

Description

Validation rules on domain model level will give the users unexpected errors.

Remediation

Remove datamodel validation rules.

Test cases

package app.mendix.domain_model.avoid_using_validation_rules

import rego.v1


# Test data

positive := {
  "Entities": [
    {
      "ValidationRules": [],
      "Name": "Bike"
    }
  ]
}

negative := {
  "Entities": [
    {
      "ValidationRules": [
        {
          "$Type": "DomainModels$ValidationRule",
          "Attribute": "MyFirstModule.Bike.Name",
          "Message": {
            "$Type": "Texts$Text",
            "Items": [
              {
                "$Type": "Texts$Translation",
                "LanguageCode": "en_US",
                "Text": "Not a good name"
              }
            ]
          },
          "RuleInfo": {
            "$Type": "DomainModels$EqualsToRuleInfo",
            "EqualsToAttribute": "",
            "UseValue": true,
            "Value": "admin"
          }
        }
      ],
      "Name": "Bike"
    }
  ]
}

# Test cases

test_positive if {
    allow with input as positive
}

test_negative if {
    not allow with input as negative
}