webgme / svelte-jsonschema-form

A Svelte component for generating forms from JSON Schema.
MIT License
26 stars 2 forks source link

Incorrect anyOf selected #34

Open romancow opened 1 month ago

romancow commented 1 month ago

In the example linked in webgme-taxonomy issue #226, the first anyOf value isn't selected properly.

romancow commented 1 month ago

Adding related example's schema and data here for reference.

Schema

{
  "type": "object",
  "properties": {
    "taxonomyTags": {
      "type": "array",
      "uniqueItems": true,
      "minItems": 1,
      "items": {
        "type": "object",
        "anyOf": [
          {
            "type": "object",
            "title": "OptionalTerm",
            "properties": {
              "Vocabulary": {
                "title": "Vocabulary",
                "type": "object",
                "properties": {
                  "OptionalTerm": {
                    "title": "OptionalTerm",
                    "type": "object",
                    "properties": {
                      "TextField": {
                        "title": "TextField",
                        "type": "string",
                        "default": "someDefault"
                      }
                    },
                    "required": [],
                    "additionalProperties": false
                  }
                },
                "required": [],
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          },
          {
            "type": "object",
            "title": "Mandatory",
            "properties": {
              "Vocabulary": {
                "title": "Vocabulary",
                "type": "object",
                "properties": {
                  "Mandatory": {
                    "title": "Mandatory",
                    "type": "object",
                    "properties": {
                      "OptWithDefault": {
                        "title": "OptWithDefault",
                        "type": "string",
                        "default": "SomeDefault"
                      },
                      "SetField": {
                        "title": "SetField",
                        "type": "array",
                        "uniqueItems": true,
                        "items": {
                          "anyOf": [
                            {
                              "title": "C",
                              "type": "object",
                              "properties": {
                                "C": {
                                  "title": "C",
                                  "type": "object",
                                  "properties": {},
                                  "required": [],
                                  "additionalProperties": false
                                }
                              },
                              "additionalProperties": false
                            },
                            {
                              "title": "A",
                              "type": "object",
                              "properties": {
                                "A": {
                                  "title": "A",
                                  "type": "object",
                                  "properties": {},
                                  "required": [],
                                  "additionalProperties": false
                                }
                              },
                              "additionalProperties": false
                            },
                            {
                              "title": "B",
                              "type": "object",
                              "properties": {
                                "B": {
                                  "title": "B",
                                  "type": "object",
                                  "properties": {},
                                  "required": [],
                                  "additionalProperties": false
                                }
                              },
                              "additionalProperties": false
                            }
                          ],
                          "default": {
                            "C": {}
                          }
                        }
                      },
                      "OptField": {
                        "title": "OptField",
                        "type": "string"
                      }
                    },
                    "required": [
                      "SetField"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [],
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          },
          {
            "type": "object",
            "title": "RecTerm",
            "properties": {
              "Vocabulary": {
                "title": "Vocabulary",
                "type": "object",
                "properties": {
                  "RecTerm": {
                    "title": "RecTerm",
                    "type": "object",
                    "properties": {
                      "IntegerField": {
                        "title": "IntegerField",
                        "type": "integer"
                      }
                    },
                    "required": [
                      "IntegerField"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [],
                "additionalProperties": false
              }
            },
            "additionalProperties": false
          }
        ]
      }
    }
  }
}

Data

{
  "taxonomyTags": [
    {
      "Vocabulary": {
        "Mandatory": {
          "OptWithDefault": "SomeDefault",
          "SetField": [],
          "OptField": null
        }
      }
    },
    {
      "Vocabulary": {
        "OptionalTerm": {
          "TextField": "someDefault"
        },
        "RecTerm": {
          "IntegerField": null
        }
      }
    }
  ]
}