{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/amazon-iot-device-defender/json-schema/amazon-iot-device-defender-metric-to-retain-schema.json",
  "title": "MetricToRetain",
  "description": "The metric you want to retain. Dimensions are optional.",
  "x-generated": "2026-11-11",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/amazon-iot-device-defender-security-profiles-api-openapi.yml#/components/schemas/MetricToRetain",
  "type": "object",
  "required": [
    "metric"
  ],
  "properties": {
    "metric": {
      "allOf": [
        {
          "$ref": "#/$defs/BehaviorMetric"
        },
        {
          "description": "What is measured by the behavior."
        }
      ]
    },
    "metricDimension": {
      "allOf": [
        {
          "$ref": "#/$defs/MetricDimension"
        },
        {
          "description": "The dimension of a metric. This can't be used with custom metrics."
        }
      ]
    }
  },
  "$defs": {
    "BehaviorMetric": {
      "type": "string"
    },
    "DimensionName": {
      "type": "string",
      "pattern": "[a-zA-Z0-9:_-]+",
      "minLength": 1,
      "maxLength": 128
    },
    "DimensionValueOperator": {
      "type": "string",
      "enum": [
        "IN",
        "NOT_IN"
      ]
    },
    "MetricDimension": {
      "type": "object",
      "required": [
        "dimensionName"
      ],
      "properties": {
        "dimensionName": {
          "allOf": [
            {
              "$ref": "#/$defs/DimensionName"
            },
            {
              "description": "A unique identifier for the dimension."
            }
          ]
        },
        "operator": {
          "allOf": [
            {
              "$ref": "#/$defs/DimensionValueOperator"
            },
            {
              "description": "Defines how the <code>dimensionValues</code> of a dimension are interpreted. For example, for dimension type TOPIC_FILTER, the <code>IN</code> operator, a message will be counted only if its topic matches one of the topic filters. With <code>NOT_IN</code> operator, a message will be counted only if it doesn't match any of the topic filters. The operator is optional: if it's not provided (is <code>null</code>), it will be interpreted as <code>IN</code>."
            }
          ]
        }
      },
      "description": "The dimension of a metric."
    }
  }
}