vazco / uniforms

A React library for building forms from any schema.
https://uniforms.tools
MIT License
1.92k stars 239 forks source link

Support for lazy recursive JSON schemas #1278

Open lordrip opened 11 months ago

lordrip commented 11 months ago

Hi team, I saw another similar issue closed about supporting lazy recursive schemas #596, but I'm not sure if managed to get a consensus about how to implement such capability.

Considering the following schema (this is a simplified version of a more complex one)

{
  "$schema": "https://json-schema.org/draft-04/schema#",
  "type": "array",
  "items": {
    "maxProperties": 1,
    "definitions": {
      "org.apache.camel.model.OnExceptionDefinition": {
        "type": "object",
        "properties": {
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/items/definitions/org.apache.camel.model.ProcessorDefinition"
            }
          }
        }
      },
      "org.apache.camel.model.ProcessorDefinition": {
        "type": "object",
        "maxProperties": 1,
        "properties": {
          "aggregate": {
            "$ref": "#/items/definitions/org.apache.camel.model.AggregateDefinition"
          }
        }
      },
      "org.apache.camel.model.AggregateDefinition": {
        "type": "object",
        "properties": {
          "aggregation-strategy": {
            "type": "string"
          },
          "steps": {
            "type": "array",
            "items": {
              "$ref": "#/items/definitions/org.apache.camel.model.ProcessorDefinition"
            }
          }
        },
        "required": [
          "aggregation-strategy"
        ]
      }
    },
    "properties": {
      "on-exception-recursive": {
        "$ref": "#/items/definitions/org.apache.camel.model.OnExceptionDefinition"
      }
    }
  }
}

you can see that there's a recursive property from:

aggregate -> steps -> aggregate -> steps

The idea would be to either limit the nested level up to point or to offer a lazy mechanism to render level by level depending on the user interaction.

I was checking the JSONSchemaBridge#getInitialValue but is not clear to me where to place a limit or even if this is the best place to do such thing.

Thanks in advance for the help :+1:

Monteth commented 11 months ago

Hello @lordrip, thank you for this question. I think it is possible for Uniforms to support some kinds of recursive schemas. You can take a look at my draft https://github.com/vazco/uniforms/pull/1282 and see if it could help you.

lordrip commented 11 months ago

Hi @Monteth, this is great 👍.

In a couple weeks I need to work on custom fields to kinda have a workaround. In the meantime, please let me know if I can help somehow, I have a recursive schema to try out as well (although the recursive schema from your PR seems more than good to test it out)

Thanks for the response