Ensure valid "type" values for JSON data types

Created on 1 June 2019, almost 6 years ago
Updated 15 May 2025, 5 days ago

Consider:

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "http://vanilla-drupal.local/en/jsonapi/node/recipe/resource/schema.json?XDEBUG_SESSION_START=PHPSTORM",
    "allOf": [
        {
            "type": "object",
            "properties": {
                "attributes": {
                    "$ref": "#/definitions/attributes"
                },
                "relationships": {
                    "$ref": "#/definitions/relationships"
                }
            }
        },
        {
            "$ref": "https://jsonapi.org/schema#/definitions/resource"
        }
    ],
    "properties": {
        "attributes": {
            "$ref": "#/definitions/attributes"
        }
    },
    "definitions": {
        "attributes": {
            "description": "Entity attributes",
            "type": "object",
            "properties": {
                "drupal_internal__nid": {
                    "type": "integer",
                    "title": "ID"
                },
                "drupal_internal__vid": {
                    "type": "integer",
                    "title": "Revision ID"
                },
                "langcode": {
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "string",
                            "title": "Language code"
                        },
                        "language": {
                            "type": "language_reference",
                            "title": "Language object",
                            "description": "The referenced language"
                        }
                    },
                    "required": [
                        "value"
                    ],
                    "title": "Language"
                },
                "revision_timestamp": {
                    "type": "number",
                    "title": "Revision create time",
                    "format": "utc-millisec",
                    "description": "The time that the current revision was created."
                },
                "revision_log": {
                    "type": "string",
                    "title": "Revision log message",
                    "description": "Briefly describe the changes you have made.",
                    "default": ""
                },
                "status": {
                    "type": "boolean",
                    "title": "Published",
                    "default": true
                },
                "title": {
                    "type": "string",
                    "title": "Recipe Name",
                    "maxLength": 255
                },
                "created": {
                    "type": "number",
                    "title": "Authored on",
                    "format": "utc-millisec",
                    "description": "The time that the node was created."
                },
                "changed": {
                    "type": "number",
                    "title": "Changed",
                    "format": "utc-millisec",
                    "description": "The time that the node was last edited."
                },
                "promote": {
                    "type": "boolean",
                    "title": "Promoted to front page",
                    "default": true
                },
                "sticky": {
                    "type": "boolean",
                    "title": "Sticky at top of lists",
                    "default": false
                },
                "default_langcode": {
                    "type": "boolean",
                    "title": "Default translation",
                    "description": "A flag indicating whether this is the default translation.",
                    "default": true
                },
                "revision_default": {
                    "type": "boolean",
                    "title": "Default revision",
                    "description": "A flag indicating whether this was a default revision when it was saved."
                },
                "revision_translation_affected": {
                    "type": "boolean",
                    "title": "Revision translation affected",
                    "description": "Indicates if the last edit of a translation belongs to current revision."
                },
                "moderation_state": {
                    "type": "string",
                    "title": "Moderation state",
                    "maxLength": 255,
                    "description": "The moderation state of this piece of content."
                },
                "path": {
                    "type": "object",
                    "properties": {
                        "alias": {
                            "type": "string",
                            "title": "Path alias"
                        },
                        "pid": {
                            "type": "integer",
                            "title": "Path id"
                        },
                        "langcode": {
                            "type": "string",
                            "title": "Language Code"
                        }
                    },
                    "title": "URL alias"
                },
                "content_translation_source": {
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "string",
                            "title": "Language code"
                        },
                        "language": {
                            "type": "language_reference",
                            "title": "Language object",
                            "description": "The referenced language"
                        }
                    },
                    "required": [
                        "value"
                    ],
                    "title": "Translation source",
                    "description": "The source language from which this translation was created.",
                    "default": "und"
                },
                "content_translation_outdated": {
                    "type": "boolean",
                    "title": "Translation outdated",
                    "description": "A boolean indicating whether this translation needs to be updated.",
                    "default": false
                },
                "field_cooking_time": {
                    "type": "integer",
                    "title": "Cooking time"
                },
                "field_difficulty": {
                    "type": "string",
                    "title": "Difficulty",
                    "enum": [
                        "easy",
                        "medium",
                        "hard"
                    ],
                    "default": "medium"
                },
                "field_ingredients": {
                    "type": "string",
                    "title": "Ingredients",
                    "maxLength": 255,
                    "description": "List the ingredients required for this recipe, one per item."
                },
                "field_number_of_servings": {
                    "type": "integer",
                    "title": "Number of servings"
                },
                "field_preparation_time": {
                    "type": "integer",
                    "title": "Preparation time"
                },
                "field_recipe_instruction": {
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "string",
                            "title": "Text"
                        },
                        "format": {
                            "type": "string",
                            "title": "Text format"
                        }
                    },
                    "required": [
                        "value"
                    ],
                    "title": "Recipe instruction"
                },
                "field_summary": {
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "string",
                            "title": "Text"
                        },
                        "format": {
                            "type": "string",
                            "title": "Text format"
                        }
                    },
                    "required": [
                        "value"
                    ],
                    "title": "Summary",
                    "description": "Provide a short overview of this recipe."
                },
                "layout_builder__layout": {
                    "type": "layout_section",
                    "title": "Layout"
                }
            },
            "required": [
                "drupal_internal__nid",
                "drupal_internal__vid",
                "title",
                "revision_translation_affected",
                "path",
                "field_difficulty",
                "field_number_of_servings",
                "field_preparation_time",
                "field_recipe_instruction",
                "field_summary"
            ],
            "additionalProperties": false
        },
        "relationships": {
            "description": "Entity relationships",
            "properties": {
                "node_type": {
                    "type": "object",
                    "properties": {
                        "data": {
                            "type": "object",
                            "required": [
                                "type",
                                "id"
                            ],
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "title": "Referenced resource",
                                    "enum": [
                                        "node_type--node_type"
                                    ]
                                },
                                "id": {
                                    "type": "string",
                                    "title": "Resource ID",
                                    "format": "uuid",
                                    "maxLength": 128
                                }
                            }
                        }
                    },
                    "title": "Content type"
                },
                "revision_uid": {
                    "type": "object",
                    "properties": {
                        "data": {
                            "type": "object",
                            "required": [
                                "type",
                                "id"
                            ],
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "title": "Referenced resource",
                                    "enum": [
                                        "user--user"
                                    ]
                                },
                                "id": {
                                    "type": "string",
                                    "title": "Resource ID",
                                    "format": "uuid",
                                    "maxLength": 128
                                }
                            }
                        }
                    },
                    "title": "Revision user"
                },
                "uid": {
                    "type": "object",
                    "properties": {
                        "data": {
                            "type": "object",
                            "required": [
                                "type",
                                "id"
                            ],
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "title": "Referenced resource",
                                    "enum": [
                                        "user--user"
                                    ]
                                },
                                "id": {
                                    "type": "string",
                                    "title": "Resource ID",
                                    "format": "uuid",
                                    "maxLength": 128
                                }
                            }
                        }
                    },
                    "title": "Authored by"
                },
                "field_image": {
                    "type": "object",
                    "properties": {
                        "data": {
                            "type": "object",
                            "required": [
                                "type",
                                "id"
                            ],
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "title": "Referenced resource",
                                    "enum": [
                                        "file--file"
                                    ]
                                },
                                "id": {
                                    "type": "string",
                                    "title": "Resource ID",
                                    "format": "uuid",
                                    "maxLength": 128
                                }
                            }
                        }
                    },
                    "title": "Image"
                },
                "field_recipe_category": {
                    "type": "object",
                    "properties": {
                        "data": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "required": [
                                    "type",
                                    "id"
                                ],
                                "properties": {
                                    "type": {
                                        "type": "string",
                                        "title": "Referenced resource",
                                        "enum": [
                                            "taxonomy_term--recipe_category"
                                        ]
                                    },
                                    "id": {
                                        "type": "string",
                                        "title": "Resource ID",
                                        "format": "uuid",
                                        "maxLength": 128
                                    }
                                }
                            }
                        }
                    },
                    "title": "Recipe category"
                },
                "field_tags": {
                    "type": "object",
                    "properties": {
                        "data": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "required": [
                                    "type",
                                    "id"
                                ],
                                "properties": {
                                    "type": {
                                        "type": "string",
                                        "title": "Referenced resource",
                                        "enum": [
                                            "taxonomy_term--tags"
                                        ]
                                    },
                                    "id": {
                                        "type": "string",
                                        "title": "Resource ID",
                                        "format": "uuid",
                                        "maxLength": 128
                                    }
                                }
                            }
                        }
                    },
                    "title": "Tags"
                }
            },
            "type": "object",
            "additionalProperties": false
        }
    }
}

Notice how we have "type": "layout_section" and "type": "language_reference". These are not valid JSON data types. This is likely caused by the fallback TypeMapper plugin. We need to add better handling for these specific cases and default to undefined TypeMapper for unknown cases.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

e0ipso Can Picafort

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024