Skip to content

EntityValidations

The entityValidations section allows you to create the business rules validations using an entity, ensuring, for example, data consistency before persistence.

This validation type doesn't depend on a context and execution order and can be used in one or more service, if needed.

Fields

An entityValidation contains the following fields to be defined:

Name

The name of entityValidation to be created.

Requirements Rules:

  • Is Required;
  • Must not be a Reserved Keyword;
  • Must start with a letter;
  • Must contains only letters, numbers and the underline char ('_');
  • Max length of 50 chars

Example:

1
2
EntityValidations:
- Name: My_First_EntityValidation


Type

The type of validation to be created.

Possible types are:

  • PropertyValidation: Allows you to validate the entity properties values, ensuring data consistency;
  • ExistsReferenceById: Allows you to validate whether the value entered for a foreign key property in your entity exists in the database through the Id

Requirements Rules:

  • Is Required;
  • Must be an Allowed valid type, according to the types informed above

Example:

1
2
3
EntityValidations:
- Name: My_First_EntityValidation
  Type: PropertyValidation


EntityName

The name of business entity to which validation will be applied.

Requirements Rules:

  • Is Required;
  • The name must exist in Entities list in the current model;
    • See Entity section for more details.

Example:

1
2
3
4
EntityValidations:
- Name: My_First_EntityValidation
  Type: PropertyValidation
  EntityName: My_First_Entity


PropertyValidationParams

The list of validation rules for the entity properties linked to the current entityValidation. Required to configure PropertyValidation type validation.

Requirements Rules:

  • Must be filled out only for the PropertyValidation type;
  • Each item on list must follows rules as specified in PropertyValidationParam

Example:

1
2
3
4
5
6
7
8
9
EntityValidations:
- Name: My_First_EntityValidation
  Type: PropertyValidation
  EntityName: My_First_Entity
  PropertyValidationParams:
  - PropertyName: Property01
    ...
  - PropertyName: Property02
    ...


ExistsReferenceByIdParams

Information regarding foreign key property and repository for record validation. Required to configure ExistsReferenceById type validation.

Requirements Rules:

Example:

1
2
3
4
5
6
7
EntityValidations:
- Name: My_First_EntityValidation
  Type: ExistsReferenceById
  EntityName: My_First_Entity
  ExistsReferenceByIdParams:
    PropertyName: ReferenceId
    ...


Complete Example

See below for a complete example, containing all the properties for the EntityValidations section.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
EntityValidations:
- Name: My_First_EntityPropertiesValidation
  Type: PropertyValidation
  EntityName: My_First_Entity
  PropertyValidationParams:
  - PropertyName: Property01
    StopOnFirstRuleFailure: true
    ForEachRule: false
    Rules:
    - Type: IsGreaterThan
      Expressions:
      - Value(@ConstInt::10)
      ErrorCode: InvalidMinValue
      Message: Informed value must be higher than the minimum allowed

- Name: ReferenceIdMustExistsInRepositoryValidation
  Type: ExistsReferenceById
  EntityName: My_First_Entity
  ExistsReferenceByIdParams:
    PropertyName: ReferenceId
    RepositoryName: ReferenceRepository
    ErrorCode: NotExistsReference
    Message: The reference must exist in the database.

Back to top