Problem/Motivation

Discovered while working on https://www.drupal.org/project/field_ui_modern.

For example:

{
  "$schema": "https://json-schema.org/draft/2019-09/hyper-schema",
  "$id": "http://core.test/jsonapi/field_storage_config/field_storage_config/resource/schema",
  "title": "Field storage",
  "allOf": [
    {
      "type": "object",
      "properties": {
        "type": {
          "$ref": "#/definitions/type"
        },
        "attributes": {
          "$ref": "#/definitions/attributes"
        }
      }
    },
    {
      "$ref": "https://jsonapi.org/schema#/definitions/resource"
    }
  ],
  "definitions": {
    "type": {
      "const": "field_storage_config--field_storage_config"
    },
    "attributes": {
      "properties": {
        "drupal_internal__id": {
          "type": "string",
          "title": "drupal_internal__id"
        },
        "langcode": {
          "type": "string",
          "title": "langcode"
        },
        "status": {
          "type": "boolean",
          "title": "status"
        },
        "dependencies": {
          "title": "dependencies"
        },
        "third_party_settings": {
          "type": "array",
          "items": {
            "properties": {
              "third_party_settings": {
                "title": "third_party_settings"
              }
            }
          }
        },
        "field_name": {
          "type": "string",
          "title": "field_name"
        },
        "entity_type": {
          "type": "string",
          "title": "entity_type"
        },
        "field_storage_config_type": {
          "type": "string",
          "title": "field_storage_config_type"
        },
        "settings": {
          "title": "settings"
        },
        "module": {
          "type": "string",
          "title": "module"
        },
        "locked": {
          "type": "boolean",
          "title": "locked"
        },
        "cardinality": {
          "type": "integer",
          "title": "cardinality"
        },
        "translatable": {
          "type": "boolean",
          "title": "translatable"
        },
        "indexes": {
          "type": "array",
          "items": {
            "properties": {
              "indexes": {
                "title": "indexes"
              }
            }
          }
        },
        "persist_with_no_fields": {
          "type": "boolean",
          "title": "persist_with_no_fields"
        },
        "custom_storage": {
          "type": "boolean",
          "title": "custom_storage"
        }
      },
      "description": "Entity attributes",
      "type": "object",
      "additionalProperties": false
    }
  }
}

→ note how

        "dependencies": {
          "title": "dependencies"
        },

does not specify any type — it should be a type: object, with the potential keys being module, theme, config and content.

Same for other "fields" (top-level properties) like settings — although that one is field-type-specific, which I'm not sure how we can express in JSON Schema.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new1.94 KB

Ignore: wrong patch.

wim leers’s picture

Before
…
    "dependencies": {
     "title": "dependencies"
    },
…
After
…
    "config": {
     "type": "array",
     "items": {
      "properties": {
       "config": {
        "type": "string",
        "title": "config"
       }
      }
     }
    },
    "content": {
     "type": "array",
     "items": {
      "properties": {
       "content": {
        "type": "string",
        "title": "content"
       }
      }
     }
    },
    "module": {
     "type": "string",
     "items": {
      "properties": {
       "module": {
        "type": "string",
        "title": "module"
       }
      }
     },
     "title": "module"
    },
    "theme": {
     "type": "array",
     "items": {
      "properties": {
       "theme": {
        "type": "string",
        "title": "theme"
       }
      }
     }
    },
…

→ better, but not quite there yet: now the top-level dependencies is gone 😬 Stay tuned…

wim leers’s picture

I've narrowed the problem down to ComplexDataDefinitionNormalizer's use of NestedArray::mergeDeep() + \Drupal\jsonapi_schema\Normalizer\DataDefinitionNormalizer::normalizeProperties()'s use of NestedArray::mergeDeep().

wim leers’s picture

m.stenta’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We have automated tests now (#3257911: Add basic test coverage) so it would be good to include a test to demonstrate this issue and prevent regressions.