opa
opa copied to clipboard
Enforce use of `if` and `contains` in rule declarations in OPA `1.0`
Currently it's, seemingly, arbitrary if a ref-head rule will produce a single-value or multi-value leaf:
package play
a[b] { b := 1 }
x.y[z] { z := 2 }
will produce
{
"a": [
1
],
"x": {
"y": {
"2": true
}
}
}
All rules declared with if contribute to an object unless contains is also used, though:
package play
import future.keywords
a[b] if { b := 1 }
x.y[z] if { z := 2 }
-->
{
"a": {
"1": true
},
"x": {
"y": {
"2": true
}
}
}
and:
package play
import future.keywords
a contains b if { b := 1 }
x.y contains z if { z := 2 }
-->
{
"a": [
1
],
"x": {
"y": [
2
]
}
}
In a 0.x release of OPA, the future.strict import will be intrudoced, and will impose the same constraints on the module, which will hopefully aid in transitioning to OPA 1.0.
This will however not solve the issue with no-body rules. E.g:
package play
a.b
x.y.x
which will produce:
{
"a": [
"b"
],
"x": {
"y": {
"x": true
}
}
}
Since the above rules don't have bodies, it's nonsensical to require the if keyword.
Is it possible to solve this without introducing a breaking change in OPA 1.0?