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

Improve type checking #7057

Open
nikpivkin opened this issue Sep 24, 2024 · 1 comment
Open

Improve type checking #7057

nikpivkin opened this issue Sep 24, 2024 · 1 comment

Comments

@nikpivkin
Copy link
Contributor

What is the underlying problem you're trying to solve?

Type checking can be improved with schemas, it's very cool. Right now Rego only does type checking when accessing an object and its child properties that are associated with a schema. But type checking stops working in other very common cases:

  • assigning an object property to a variable
  • passing an object to a Rego function
  • passing an object to a custom function

Describe the ideal solution

The type is stored in the value and are used for type checking anywhere

Additional Context

In the example below, only the first case works.

Example Rego file:

package test

import rego.v1

deny if {

    # case 1
    input.foo.baz

    # case 2
    # foo := input.foo
    # foo.baz

    # case 3
    # test(input.foo)

    # case 4
    # object.get(input.foo, "baz", input.foo)
}

test(foo) if foo.baz

schema.json

{
    "type": "object",
    "properties": {
        "foo": {
            "type": "object"
        }
    }
}

input.json

{
    "foo": {}
}

Run opa eval data -d test.rego -i input.json -s schema.json

Copy link

stale bot commented Oct 28, 2024

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

@stale stale bot added the inactive label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant