The @assert.range annotation allows the specification of value ranges for elements of model entities with ordinal types - i.e. numeric or date/time types. The value range is defined as an interval with the following syntax:
1
@assert.range: [min, max]
The defined range is regarded as a closed interval, i.e. it is checked whether a specified value is greater than or equal to min and less than or equal to max.
For enum elements, true can be specified to restrict possible values to the defined enum values.
In the example shown, the genre element of the Books entity has the data type Genre, which is a custom type with enumeration values. Annotating the genre element with @assert.range: true ensures that only values from the enumeration can be specified for this element, i.e. 1 or 2.
If, for example, the value 3 is provided for the genre element when creating a book, the requested CREATE operation is not executed. Instead, the HTTP response has the status code 400 (Bad Request) and the response body contains an error message similar to the following:
123456
"error": {
"code": "400",
"message": "Value 3 is invalid according to enum declaration {1, 2}",
"target": "genre",
"@Common.numericSeverity": 4
}