Open wtrocki opened 2 years ago
This becomes big issue as references are widely used for the rhoas schemas.
CC @jackdelahunt
Trying this out now 👀
💘
Progress so far:
Have this basic schema parsing
{
"$defs": {
"person": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
},
"type": "object",
"properties": {
"size": {"type": "string"},
"person1": {"$ref": "#/$defs/person"},
"person2": {"$ref": "#/$defs/person"}
}
}
The current problem is when you have nested objects in the $def like how all the rhoas schemas have. Most of them have $def->data_shape->consumes
this causes problems for me right now as the JsonSchemaType object does not have any data in it when it marshalls the data_shape object.
We need to traverse json nodes as tree. Currently we always stop at level 2 ( root leaves) which is only simple use case
We need to traverse json nodes as tree. Currently we always stop at level 2 ( root leaves) which is only simple use case
Think the issue is more when we are unmarshalling the file into JSONSchemaType. Because objects like data_shape
are not in the struct all that data is ignored.
As far as I know things like data_shape
used in the rhoas schemas aren't JsonSchema things it is just how they structured they're JSON. This means we miss them...
Thanks for making this clear. We would typically nest things by specifying json schema in existing json schema object. Maybe we can change datashape to meet those requirements somehow?
If there was a way to have an "Unspecified" field where any things added to the object are put there and parsed as SchemaObject. But maybe that is not possible.
@wtrocki After looking into it more you can use "-" for json key as a stand-in for any key-values in the json that are not specified in the go struct you want to un-marshal too https://go.dev/play/p/njkjh-qeJcM.
Even though it would add a lot more complexity to the library unmarshalling to a [string]interface{} might be more flexible.
$defs and $ref aren't well supported within library. Library would ignore references that are empty (and ignore refs)