rjsf-team/react-jsonschema-form

Validation issue with oneOf

Open

#3567 opened on Apr 2, 2023

View on GitHub
 (1 comment) (0 reactions) (0 assignees)TypeScript (13,175 stars) (2,136 forks)batch import
bughelp wantedvalidation

Description

Prerequisites

What theme are you using?

core

Version

5.5.0

Current Behavior

Fields in the oneOf having the same key gives multiple errors while validating along with the additionalProperties key if it kept to false

Playground Link

JsonSchema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "ProgramingLanguages",
  "description": "ProgramingLanguages Config",
  "type": "object",
  "definitions": {
    "programingType": {
      "description": "ProgramingLanguages type",
      "type": "string",
      "enum": [
        "AI"
      ],
      "default": "AI"
    }
  },
  "properties": {
    "type": {
      "title": "ProgramingLanguages Type",
      "description": "ProgramingLanguages Type",
      "$ref": "#/definitions/programingType",
      "default": "Programing"
    },
    "hostPort": {
      "expose": true,
      "title": "Host and Port",
      "description": "URL for the ProgramingLanguages instance.",
      "type": "string",
      "format": "uri",
      "default": "http://localhost:8088"
    },
    "connection": {
      "title": "Programing Connection",
      "oneOf": [
        {
          "$schema": "http://json-schema.org/draft-07/schema#",
          "title": "API",
          "description": "API Config",
          "type": "object",
          "definitions": {
            "provider": {
              "title": "Provider",
              "type": "string",
              "enum": [
                "abc",
                "xyz"
              ],
              "default": "abc"
            }
          },
          "properties": {
            "provider": {
              "title": "Provider",
              "$ref": "#/properties/connection/oneOf/0/definitions/provider",
              "default": "abc"
            },
            "username": {
              "title": "Username",
              "type": "string"
            },
            "password": {
              "title": "Password",
              "type": "string",
              "format": "password"
            }
          },
          "additionalProperties": false,
          "required": [
            "provider",
            "password",
            "username"
          ]
        },
        {
          "$schema": "http://json-schema.org/draft-07/schema#",
          "title": "Javascript",
          "type": "object",
          "definitions": {
            "type": {
              "type": "string",
              "enum": [
                "Delta"
              ],
              "default": "Delta"
            },
            "scheme": {
              "type": "string",
              "enum": [
                "deltaplus"
              ],
              "default": "deltaplus"
            }
          },
          "properties": {
            "type": {
              "title": "Type",
              "$ref": "#/properties/connection/oneOf/1/definitions/type",
              "default": "Delta"
            },
            "scheme": {
              "title": "scheme",
              "$ref": "#/properties/connection/oneOf/1/definitions/scheme",
              "default": "deltaplus"
            },
            "username": {
              "title": "Username",
              "type": "string"
            },
            "password": {
              "title": "Password",
              "type": "string",
              "format": "password"
            },
            "hostPort": {
              "title": "Host and Port",
              "type": "string"
            },
            "database": {
              "title": "Database",
              "type": "string"
            },
            "mode": {
              "title": "Mode",
              "type": "string"
            },
            "ingestAll": {
              "title": "Ingest All",
              "type": "boolean",
              "default": false
            },
            "options": {
              "title": "Options",
              "type": "object",
              "additionalProperties": {
                "type": "string"
              }
            },
            "react": {
              "title": "React",
              "$ref": "#/properties/react"
            },
            "angular": {
              "type": "boolean",
              "default": true
            },
            "vue": {
              "type": "boolean",
              "default": true
            },
            "DotNet": {
              "type": "boolean",
              "default": true
            },
            "Rust": {
              "title": "Rust",
              "type": "boolean",
              "default": true
            },
            "comment": {
              "title": "Comment",
              "type": "boolean",
              "default": true
            }
          },
          "additionalProperties": false,
          "required": [
            "hostPort",
            "username",
            "database"
          ]
        },
        {
          "$schema": "http://json-schema.org/draft-07/schema#",
          "title": "pythin",
          "type": "object",
          "definitions": {
            "type": {
              "description": "type.",
              "type": "string",
              "enum": [
                "python"
              ],
              "default": "python"
            },
            "schema": {
              "description": "scheme options.",
              "type": "string",
              "enum": [
                "python"
              ],
              "default": "python"
            }
          },
          "properties": {
            "type": {
              "title": "Type",
              "description": "Service Type",
              "$ref": "#/properties/connection/oneOf/2/definitions/type",
              "default": "python"
            },
            "scheme": {
              "title": "Scheme",
              "$ref": "#/properties/connection/oneOf/2/definitions/schema",
              "default": "python"
            },
            "username": {
              "title": "Username",
              "type": "string"
            },
            "password": {
              "title": "Password",
              "type": "string",
              "format": "password"
            },
            "hostPort": {
              "title": "Host and Port",
              "type": "string"
            },
            "databaseName": {
              "title": "Database Name",
              "type": "string"
            },
            "ds": {
              "title": "ds",
              "type": "string"
            },
            "ssl": {
              "title": "SSL",
              "type": "string"
            },
            "certificate": {
              "title": "Certificate",
              "type": "string"
            },
            "key": {
              "title": "Key",
              "type": "string"
            },
            "react": {
              "title": "React",
              "$ref": "#/properties/react"
            },
            "angular": {
              "title": "Angular",
              "$ref": "#/properties/connection/oneOf/1/properties/angular"
            },
            "DotNet": {
              "$ref": "#/properties/connection/oneOf/1/properties/DotNet"
            },
            "Rust": {
              "title": "Rust",
              "$ref": "#/properties/connection/oneOf/1/properties/Rust"
            },
            "comment": {
              "title": "Comment",
              "$ref": "#/properties/connection/oneOf/1/properties/comment"
            }
          },
          "additionalProperties": false,
          "required": [
            "hostPort",
            "username"
          ]
        }
      ]
    },
    "react": {
      "title": "react",
      "type": "boolean",
      "default": true
    }
  },
  "additionalProperties": false,
  "required": [
    "hostPort",
    "connection"
  ]
}

UI Schema:

{
  "react": {
    "ui:widget": "hidden",
    "ui:hideError": true
  },
  "angular": {
    "ui:widget": "hidden",
    "ui:hideError": true
  },
  "DotNet": {
    "ui:widget": "hidden",
    "ui:hideError": true
  },
  "Rust": {
    "ui:widget": "hidden",
    "ui:hideError": true
  },
  "comment": {
    "ui:widget": "hidden",
    "ui:hideError": true
  },
  "vue": {
    "ui:widget": "hidden",
    "ui:hideError": true
  },
  "type": {
    "ui:widget": "hidden"
  },
  "connection": {
    "react": {
      "ui:widget": "hidden",
      "ui:hideError": true
    },
    "angular": {
      "ui:widget": "hidden",
      "ui:hideError": true
    },
    "DotNet": {
      "ui:widget": "hidden",
      "ui:hideError": true
    },
    "Rust": {
      "ui:widget": "hidden",
      "ui:hideError": true
    },
    "comment": {
      "ui:widget": "hidden",
      "ui:hideError": true
    },
    "vue": {
      "ui:widget": "hidden",
      "ui:hideError": true
    },
    "type": {
      "ui:widget": "hidden"
    }
  }
}

Expected Behavior

Should only validate the oneOf that is selected and should not throw an additionalProperties error.

Steps To Reproduce

No response

Environment

- OS:
- Node:
- npm:

Anything else?

No response

Contributor guide