-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: Add support for recursive json schema elements to prevent fatal error #5167
fix: Add support for recursive json schema elements to prevent fatal error #5167
Conversation
Looks like it's got a race condition, converting to draft until it's fixed. |
d6316ed
to
66fa711
Compare
...fixed now 🥳 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, just a tiny nitpick re: the error case. Let's do some error unwrapping, maybe?
// | ||
// We'd get this result: | ||
// | ||
// GetRulesDynamicWithOpts("data[x]", RulesOptions{IncludeHiddenModules: true}) => [rule1, rule2, rule3] | ||
// GetRulesDynamicWithOpts("data[x]", RulesOptions{IncludeHiddenModules: true}) => [rule1, rule2, rule3] | ||
// | ||
// Without the options, it would be excluded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☝️ These are automatically done through go 1.19's formatter -- it's not related to this PR, but someone's got to commit it eventually. So I'm ok if that someone is you 😀
expectedErrors: []string{ | ||
"undefined function foo", | ||
}, | ||
},*/ | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈 this is weird, but presumably also the code formatter. Let's roll with it.
@@ -7332,3 +7333,121 @@ func TestKeepModules(t *testing.T) { | |||
} | |||
}) | |||
} | |||
|
|||
// see https://github.com/open-policy-agent/opa/issues/5166 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think keeping the issue link in the commit message is good enough. But it doesn't hurt much to have it twice, either.
66fa711
to
43c8f01
Compare
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
…error Resolves open-policy-agent#5166 Signed-off-by: Liam Galvin <liam.galvin@aquasec.com>
43c8f01
to
03993a1
Compare
This adds support for recursive json schemas, such as:
The
parseSchema
method now hangs from aschemaParser
struct. This allows the use of a cache that can be populated with definitions as they are seen, to prevent them being reparsed later. They are added to cache before they are completely parsed, otherwise the recursive crash would still occur. Thus they are added to the cache with all properties without values, then the values are added in by reference after the subsequent child tree parse.I've added a couple of tests that cover my use case, as well as a schema parsing test (this already passed before my changes - the compile time analysis of the schema is the problem) for good measure.
Happy to change whatever or discuss an alternative approach, just shout (I'm on the OPA slack)
Resolves #5166
Signed-off-by: Liam Galvin liam.galvin@aquasec.com