Constrained blocks
Some blocks can be executed conditionally based on constraining the response or representation.
Currently it is possible to constrain Class
, Link
and
Property
blocks by setting conditions on HTTP Status code
or property values.
A generic syntax is
'When' ('Property' | 'Status') Not? Operator Value
Possible operators are:
- Strict equality
- Inequality
- Regular expression
- Custom code (to be parsed by test runner)
Possible values are string, numeric and boolean.
Multiple When
statements should be joined with a logical AND
operator
by the runner, ie. a block should be executed only when all conditions are
satisfied.
Examples
Only execute Class when property matches
With Class "Person" {
When Property "maritalStatus" Not Equals "Single"
Expect Link "spouse"
}
Constrain link block based on status code
With Class "Book" {
With Link "author" {
When Status => ```
status => status >= 400 && status != 404
```
Expect Header Content-Type "application/problem+json"
}
}