opa
opa copied to clipboard
bug: Panic when using a JSON schema with recursive elements
Short description
I'm using the Go API to apply some policies to a variety of different inputs. I'm using a JSON schema for each input type to validate rules and have come across a panic when using a schema with recursive elements. Minimal example below.
- OPA version: v0.44.0
The example below is simplified for readability but we need this feature to parse tree structures etc.
Steps To Reproduce
- Use the following schema (
schema.json):
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/open-policy-agent/opa/issues/5166",
"type": "object",
"properties": {
"Something": {
"$ref": "#/$defs/X"
}
},
"$defs": {
"X": {
"type": "object",
"properties": {
"Y": {
"$ref": "#/$defs/Y"
}
}
},
"Y": {
"type": "object",
"properties": {
"X": {
"$ref": "#/$defs/X"
}
}
}
}
}
- Run
opa check -s schema.json input.json(whereinput.regois pretty much anything) - KABOOM
Expected behavior
The input.rego should be validated against the input schema.
Happy to have a go at fixing this if I can manage it :crossed_fingers: