JSON Schema: wrong detection anyOf

Created on 2 June 2025, 5 days ago

Problem/Motivation

When working on UI Suite Bootstrap: Define form elements from SDC Active , we defined an object for options handling optgroup like this:

    options:
      title: "Options"
      # @todo promote this structure as prop type.
      type: object
      additionalProperties: false
      patternProperties:
        ".+":
          anyOf:
            - type: string
            - type: object
              patternProperties:
                ".+": {type: string}

The problem is that it is detected as an Attribute prop type.

In https://git.drupalcode.org/project/ui_patterns/-/blob/2.0.x/src/SchemaMa..., there is a logic problem in :

  /**
   * When the schemas are using anyOf property, are they compatible?
   */
  protected function isAnyOfCompatible(array $checked_schema, array $reference_schema): bool {
    if (isset($reference_schema["anyOf"])) {
      foreach ($reference_schema["anyOf"] as $schema) {
        if ($this->isCompatible($checked_schema, $schema)) {
          return TRUE;
        }
      }
    }
    if (isset($checked_schema["anyOf"])) {
      foreach ($checked_schema["anyOf"] as $schema) {
        if ($this->isCompatible($schema, $reference_schema)) {
          return TRUE;
        }
      }
    }
    return FALSE;
  }

Some notes with @pdureau:

ATTRIBUTE PROP TYPE
anyOf:
 - type: string
 - type: array

KO:
anyOf:
 - type: object
 - type: string

OK:
anyOf:
 - type: string

OK:
type: string
🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France Grimreaper France 🇫🇷

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024