Skip to content

Commit

Permalink
@assert.target with open ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
danjoa committed Nov 9, 2024
1 parent 3d19fbc commit dc5800c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions guides/providing-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,30 @@ entity Foo {
zoo : String @assert.range enum { high; medium; low; };
}
```
::: tip
Specified ranges are interpreted as closed intervals, that means, the performed checks are `min ≤ input ≤ max`.
#### ... with open intervals

By default, specified `[min,max]` ranges are interpreted as closed intervals, that means, the performed checks are `min ≤ input ≤ max`. You can also specify open intervals by wrapping the *min* and/or *max* values into parenthesis like that:

```cds
@assert.range: [(0),100] // 0 < input ≤ 100
@assert.range: [0,(100)] // 0 ≤ input < 100
@assert.range: [(0),(100)] // 0 < input < 100
```
In addition, you can use an underscore `_` to represent *Infinity* like that:
```cds
@assert.range: [(0),_] // positive numbers only, _ means +Infinity here
@assert.range: [_,(0)] // negative number only, _ means -Infinity here
```
> Basically values wrapped in parentheses _`(x)`_ can be read as _excluding `x`_ for *min* or *max*. Note that the underscore `_` doesn't have to be wrapped into parenthesis, as by definition no number can be equal to *Infinity* .

::: warning Support in latest runtimes

Support for open intervals and infinity has been added to CAP Node.js, i.e. `@sap/cds` version **8.5**. Support in CAP Java is **not yet available** but will follow soon.

:::



### `@assert.notNull` {#assert-notNull}

Annotate a property with `@assert.notNull: false` to have it ignored during the generic not null check, for example if your persistence fills it automatically.
Expand Down

0 comments on commit dc5800c

Please sign in to comment.