Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allOf inside anyOf causes form error #4281

Open
4 tasks done
nowifi4u opened this issue Aug 21, 2024 · 1 comment
Open
4 tasks done

allOf inside anyOf causes form error #4281

nowifi4u opened this issue Aug 21, 2024 · 1 comment

Comments

@nowifi4u
Copy link

nowifi4u commented Aug 21, 2024

Prerequisites

What theme are you using?

bootstrap-4

Version

5.19.3

Current Behavior

Error in playground: Invalid schema: [object Object], Raw Ajv Validation showed "No AJV errors encountered"

Frontend error:

Unsupported field schema for field root: Unknown field type undefined.

{
  "title": "Test"
}

Without the "title": "Test" the form just becomes empty while playground still gives the error

Expected Behavior

Should run normally

Steps To Reproduce

Playground link

The json schema was generated with zod-to-jsonschema

Environment

- OS: Windows 10
- Node: 22.4.1
- npm: 10.8.1

Anything else?

No response

@nowifi4u nowifi4u added bug needs triage Initial label given, to be assigned correct labels and assigned labels Aug 21, 2024
@abdalla-rko
Copy link
Contributor

The schema you used is not valid. Here are the issues in your schema:

  1. your schema is an array, which is why ajv didn't catch it. It should be an object with a defined type.
  2. each nested object needs to be inside the properties object. Your schema structure needs to be properties.result.properties.data.anyOf instead of result.data.anyOf.
  3. your $ref in the message field is wrong. If you want to reference schema, you need to define it in the definitions at the root of the schema.
    Here is the correct schema:
{
  "type": "object",
  "definitions": {
    "context": {
      "type": "object",
      "properties": {
        "context": {
          "type": "object",
          "properties": {
            "username": {
              "type": "string",
              "minLength": 1,
              "title": "Username"
            },
            "password": {
              "type": "string",
              "minLength": 1,
              "title": "Password"
            }
          },
          "required": [
            "username",
            "password"
          ],
          "additionalProperties": false,
          "title": "Account"
        }
      },
      "required": [
        "context"
      ],
      "title": "Test"
    }
  },
  "properties": {
    "result": {
      "type": "object",
      "properties": {
        "data": {
          "anyOf": [
            {
              "allOf": [
                {
                  "$ref": "#/definitions/context"
                },
                {
                  "type": "object",
                  "properties": {
                    "language": {
                      "type": "string",
                      "enum": [
                        "ru",
                        "en"
                      ],
                      "default": "ru"
                    },
                    "heat": {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 100,
                      "default": 80
                    },
                    "message": {
                      "$ref": "#/definitions/context"
                    }
                  },
                  "required": [
                    "message"
                  ]
                }
              ]
            }
          ],
          "$schema": "http://json-schema.org/draft-07/schema#"
        }
      }
    }
  }
}

@heath-freenome heath-freenome added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants