{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cloudinary/json-schema/cloudinary-metadata-rule-update-schema.json",
  "title": "metadata_rule_update",
  "x-generated": "2026-11-17",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/cloudinary-structured-metadata-openapi.yml#/components/schemas/metadata_rule_update",
  "allOf": [
    {
      "$ref": "#/$defs/metadata_rule_base"
    }
  ],
  "$defs": {
    "metadata_rule_activate_values": {
      "description": "Restricts which datasource option ids are active. Either the string \"all\" (activate every option) or an object listing the external ids to activate.\n",
      "oneOf": [
        {
          "type": "string",
          "enum": [
            "all"
          ]
        },
        {
          "type": "object",
          "required": [
            "external_ids"
          ],
          "properties": {
            "external_ids": {
              "type": [
                "array",
                "null"
              ],
              "items": {
                "type": "string"
              },
              "description": "The datasource external ids to activate."
            },
            "mode": {
              "type": "string",
              "enum": [
                "override",
                "append"
              ],
              "description": "Whether to override the current active set or append to it. Defaults to append."
            }
          }
        }
      ]
    },
    "metadata_rule_apply_value": {
      "type": "object",
      "description": "Applies a specific value to the metadata field when the rule condition is met.",
      "required": [
        "value"
      ],
      "properties": {
        "value": {
          "type": [
            "string",
            "null"
          ],
          "description": "The value to apply to the metadata field."
        },
        "mode": {
          "type": "string",
          "enum": [
            "default",
            "override",
            "append"
          ],
          "description": "How to apply the value. `default` sets it only when no value is already inferred; `override` always replaces any inferred value; `append` adds to an existing array value.\n"
        }
      }
    },
    "metadata_rule_base": {
      "type": "object",
      "properties": {
        "metadata_field_id": {
          "type": "string",
          "description": "The ID of the metadata field this rule applies to."
        },
        "name": {
          "type": "string",
          "description": "A descriptive name for the metadata rule."
        },
        "condition": {
          "type": "object",
          "description": "The condition that triggers this rule. Ensure it adheres to the metadata rule condition schema."
        },
        "result": {
          "$ref": "#/$defs/metadata_rule_result"
        },
        "state": {
          "$ref": "#/$defs/state_enum",
          "description": "The state of the rule."
        },
        "position": {
          "type": "integer",
          "description": "The position/order of this rule relative to other rules."
        }
      }
    },
    "metadata_rule_result": {
      "type": "object",
      "description": "The result to apply when the rule's condition is met. At least one property must be set.",
      "minProperties": 1,
      "properties": {
        "apply_value": {
          "$ref": "#/$defs/metadata_rule_apply_value"
        },
        "disable": {
          "type": "boolean",
          "description": "When true, disables the field in the UI (sets default_disabled). Preferred over the legacy enable action."
        },
        "enable": {
          "type": "boolean",
          "deprecated": true,
          "description": "When true, enables the field in the UI (clears default_disabled). Deprecated — prefer using disable with value false instead."
        },
        "hide": {
          "type": "boolean",
          "description": "When true, hides the field in the UI (sets hidden_ui)."
        },
        "activate_values": {
          "$ref": "#/$defs/metadata_rule_activate_values"
        },
        "set_mandatory": {
          "type": "boolean",
          "description": "When true, makes the field mandatory; when false, makes it optional."
        }
      }
    },
    "state_enum": {
      "type": "string",
      "enum": [
        "active",
        "inactive"
      ],
      "description": "The active or inactive state."
    }
  }
}