jackdelahunt / survey-json-schema

golang survey tooling to fullfill JSON schema requirements
Apache License 2.0
2 stars 1 forks source link

Add support for references #5

Open wtrocki opened 2 years ago

wtrocki commented 2 years ago

$defs and $ref aren't well supported within library. Library would ignore references that are empty (and ignore refs)

wtrocki commented 2 years ago

This becomes big issue as references are widely used for the rhoas schemas.

CC @jackdelahunt

jackdelahunt commented 2 years ago

Trying this out now 👀

wtrocki commented 2 years ago

💘

jackdelahunt commented 2 years ago

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"}
  }
}

image

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.

wtrocki commented 2 years ago

We need to traverse json nodes as tree. Currently we always stop at level 2 ( root leaves) which is only simple use case

jackdelahunt commented 2 years ago

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...

wtrocki commented 2 years ago

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?

jackdelahunt commented 2 years ago

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.

jackdelahunt commented 2 years ago

@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.