Flattening objects in the schema
Required Functionality Creating a schema where result has many fields A1..AN but has two other fields, say B and C and only one can be present requires us to create a schema with a one_of at the root.
{
"type":"one_of",
"variants": [
{
"type":"object",
"A1": {...},
...
"AN": {...},
"B": {...}
},
{
"type":"object",
"A1": {...},
...
"AN": {...},
"C": {...}
},
]
}
This means a lot of repetition. All the A1..AN fields have to be spelt out again.
Proposed Solution
If we could add an attribute to an object which puts all its entries into the parent (like serde's struct flattening at https://serde.rs/attr-flatten.html) we would be able to write this as something like
{
"type":"object",
"A1": {...},
...
"AN": {...},
"B_OR_C": {
"type":"variant",
"attributes":["flatten"],
"variants":[
{ "type":"object", "B":{...} }
{ "type":"object", "C":{...} }
]
}
}
with that "B_OR_C" never appearing in the output.
The example schema you shown should be something like this, right?
{
"type":"one_of",
"variants": [
{
"type":"object",
"A1": {...},
...
"AN": {...},
"B": {...}
},
{
"type":"object",
"A1": {...},
...
"AN": {...},
"B": {...} // <==== C ?
},
]
}
The example schema you shown should be something like this, right?
Absolutely.
The example schema you shown should be something like this, right?
I've fixed it in the description now. There were a few issues in the proposed syntax too, which I've just corrected too. Again copy-paste errors due to me submitting this in a rush - sorry.