The goal is to express an ADT like the following in json schema:
data Sum
= Foo { hi :: Int }
| Bar { x :: Bool }
or in rust syntax:
enum Sum {
Foo { hi : i64 },
Bar { x : bool }
}
This can be done by encoding each of these alternatives in a “tagged” way in json:
{
"tag": "Foo",
"hi": 234
}
or
{
"tag": "Bar",
"x": true
}
Of course this means the field tag
cannot be used for any of the field names, but it’s a good encoding for most things.
Now, how to express this in json-schema? oneOf
to the rescue.