JSON Schema Keywords AllOf and AnyOf in OPA Type Checker
Enhancement of the Open Policy Agent Rego type checker did not support some keywords in the JSON Schema 2019-09 release. Now it does.
Sep 29th, 2021 8:20am by
Featured image via Pixabay.
IBM Cloud sponsored this post.
Jing Chen
Jing is a junior majoring in computer science and located in New York. She is excited to learn more about research in the hybrid cloud space and is passionate to always learn more in the tech domain.
allOf vs. anyOf — What’s the Difference?
To understand the meaning of anyOf and allOf, consider entering your mailing address to purchase something online. After entering your address line, you can either specify it with state, city and ZIP code or with country and postcode. For those who are familiar with JSON Schema language, it might look something like this:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"title": "My schema",
"properties": {
"Address": { "type": "string" },
},
"required": [ "Address" ],
"anyOf": [
{
"allOf":[
{
"type": "object",
"properties": {
"State": { "type": "string" },
"City": { "type": "string" },
"ZipCode": { "type": "string" }
},
},
{
"required": [ “State”, “City”, "ZipCode" ]
}
]
},
{
"allOf":[
{
"type": "object",
"properties": {
"County": { "type": "string" },
"PostCode": { "type": "string" }
},
},
{
"required": [ “County”, "PostCode" ]
}
]
}
]
}
Julia Friedman
Julia is a third-year student at the University of Virginia majoring in computer science and minoring in engineering business. Over the summer, she interned at IBM in the field of cloud computing.
package shopper.mailingAddress
deny {
input.States == “California”
}
input.States
^
have: "States"
want (one of): ["City" "County" "PostCode" "State" "ZipCode"]
What’s Next?
Future work relating to this project will involve implementing support for the many other keywords not currently supported by OPA’s JSON schema Rego type checker (enum, if/then/else, among others). Further, we hope to conduct user surveys with the OPA community to evaluate the effectiveness of the type checker. Let us know what you think!
Hear more from our sponsor
Links
Note: Other authors of this article were Mandana Vaziri, principal research staff member at IBM, and Ansu Varghese, research software engineer at IBM.
YOUTUBE.COM/THENEWSTACK
Tech moves fast, don't miss an episode. Subscribe to our YouTube
channel to stream all our podcasts, interviews, demos, and more.