Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce use of if and contains in rule declarations in OPA 1.0 #6288

Open
johanfylling opened this issue Oct 10, 2023 · 1 comment
Open

Enforce use of if and contains in rule declarations in OPA 1.0 #6288

johanfylling opened this issue Oct 10, 2023 · 1 comment

Comments

@johanfylling
Copy link
Contributor

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.

@johanfylling
Copy link
Contributor Author

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?

@johanfylling johanfylling changed the title Enforce use of if and contains in rule declarations Enforce use of if and contains in rule declarations in OPA 1.0 Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants