Hello. What's wrong with this schema? https://bpa.st/EBDQ

It doesn’t work using the jsonforms-react-seed app.

[original thread by Kal Sze]

[Kal Sze]

I basically want a drop-down for the user to select one of the predefined selling points or enter an ad hoc selling point.

Some of the predefined selling points are parameterized (as you can see with the “Supports multiple languages” selling point).

If the user selects to input an ad hoc selling point, they should enter both English (“en”) and Traditional Chinese (“zh-hant”) translations.

Hi @k-sze(k-sze), instead of posting a link please post the schema here.

On first glance the schema looks fine so I would expect JSON Forms to render it. As it seems that it doesn’t work we’ll have to take a closer look at some point in the future.

[Kal Sze]

I think something is wrong with the TypeScript definition of JsonSchema7

[Kal Sze]

I tried to follow this comment: Support "allOf" + "if" combination · Issue #1518 · eclipsesource/jsonforms · GitHub

And defined this schema:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "properties": {
    "selling_point": {
      "oneOf": [
        {
          "title": "Supports multiple languages",
          "properties": {
            "key": {
              "const": "supports_multiple_languages"
            },
            "languages": {
              "title": "The languages",
              "description": "The languages",
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "en",
                  "zh-hant",
                  "fr",
                  "de",
                  "it",
                  "kr",
                  "jp"
                ]
              }
            }
          },
          "required": [
            "key"
          ]
        },
        {
          "title": "(Ad hoc)",
          "properties": {
            "key": {
              "const": "ad_hoc"
            },
            "en": {
              "description": "English description",
              "type": "string",
              "minLength": 1,
              "default": "English description"
            },
            "zh-hant": {
              "description": "Traditional Chinese description",
              "type": "string",
              "minLength": 1,
              "default": "繁體中文描述"
            }
          },
          "required": [
            "key"
          ]
        }
      ]
    }
  },
  "required": [
    "selling_point"
  ]
}

And I get this TypeScript validation error:

[Kal Sze]

Argument of type '{ $schema: string; properties: { selling_point: { oneOf: ({ title: string; properties: { key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }; required: string[]; } | { ...; })[]; }; }; required: ...' is not assignable to parameter of type 'JsonSchema4 | JsonSchema7 | undefined'.
  Type '{ $schema: string; properties: { selling_point: { oneOf: ({ title: string; properties: { key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }; required: string[]; } | { ...; })[]; }; }; required: ...' is not assignable to type 'JsonSchema7'.
    Types of property 'properties' are incompatible.
      Type '{ selling_point: { oneOf: ({ title: string; properties: { key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }; required: string[]; } | { ...; })[]; }; }' is not assignable to type '{ [property: string]: JsonSchema7; }'.
        Property '"selling_point"' is incompatible with index signature.
          Type '{ oneOf: ({ title: string; properties: { key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }; required: string[]; } | { ...; })[]; }' is not assignable to type 'JsonSchema7'.
            Types of property 'oneOf' are incompatible.
              Type '({ title: string; properties: { key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }; required: string[]; } | { ...; })[]' is not assignable to type 'JsonSchema7[]'.
                Type '{ title: string; properties: { key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }; required: string[]; } | { ...; }' is not assignable to type 'JsonSchema7'.
                  Type '{ title: string; properties: { key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }; required: string[]; }' is not assignable to type 'JsonSchema7'.
                    Types of property 'properties' are incompatible.
                      Type '{ key: { const: string; }; languages: { title: string; description: string; type: string; items: { type: string; enum: string[]; }; }; en?: undefined; "zh-hant"?: undefined; }' is not assignable to type '{ [property: string]: JsonSchema7; }'.
                        Property '"en"' is incompatible with index signature.
                          Type 'undefined' is not assignable to type 'JsonSchema7'.ts(2345)

Your JSON Schema looks correct so I don’t know why there is this error. Also when starting the app via react-scripts this typing error is not reported. As this is just about the typing you could ignore it by simply casting your schema to any until we know why this error occurs.

Still sadly the app crashes which we have to investigate. You could try and model your schema after our oneOf example and see if it works then

The crash is now fixed. I did not yet investigate why the typing fails in the React seed but you can safely ignore it.