koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
538 stars 154 forks source link

`oneOf` issues #416

Open ai-nikolai opened 1 year ago

ai-nikolai commented 1 year ago

First of all, thank you for this great package. It works really well and is much easier to get started compared to some others and has great re-activity.

The current issue that we are reporting is that oneOf only works with a very specific format of the const keyword.

However, the following json-schemas do not work:

1. Nesting the Const keyword into an array

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "option": {
            "oneOf": [
                {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "const": "a"
                    }
                },
                {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "const": "b"
                    }
                }
            ]
        },
        "sharedProperty": {
            "type": "string"
        }
    },
    "required": ["option", "sharedProperty"]
}

2. Using other keywords than const

e.g.: using the above schema and adding this option for oneOf:

                {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": ["b", "c"]
                    }
                }

In particular, what we are aiming to generate is a json that has either: option : [a], option: [b], or option: [b,c] and depending on that a different sub-schema.

Please advice us on how to get this going, i.e. the full json should like like:

{
 option : [a],
 sharedProperty : "abc"
}
albanm commented 1 year ago

In the next major version I intend to use a closer integration with ajv and I think the current subschema of a oneOf will be calculated by attempting validation of each subschema, this way any way of discriminating between subschemas will be supported. But this will not be available soon and I don't want to make such important changes to the current version. So for the time being, sorry but a const property is the only supported way to discriminate subschemas in a oneOf.

ai-nikolai commented 1 year ago

Ok got it. Thanks for the quick response.