{
  "$schema": "https://json-schema.org/draft-04/schema#",
  "id": "https://api.dataplatform.ibm.com/schemas/common-pipeline/datarecord-metadata/datarecord-metadata-v3-schema.json",
  "title": "Datarecord Metadata Schema",
  "description": "Metadata schema for datarecords",
  "type": "object",
  "definitions": {
    "record_schema": {
      "description": "Description of a datarecord including column types and metadata",
      "type": "object",
      "properties": {
        "id": {
          "description": "Unique identifier",
          "type": "string"
        },
        "name": {
          "description": "Name of datarecord",
          "type": "string"
        },
        "json_schema": {
          "description": "Refers to the JSON schema used to validate documents of this type",
          "enum": [
            "https://api.dataplatform.ibm.com/schemas/common-pipeline/datarecord-metadata/datarecord-metadata-v3-schema.json"
          ],
          "type": "string"
        },
        "type": {
          "description": "Always 'struct' for datarecord schema",
          "type": "string"
        },
        "fields": {
          "description": "Array of field definitions",
          "type": "array",
          "minItems": 0,
          "items": {
            "$ref": "#/definitions/field"
          },
          "uniqueItems": true
        },
        "struct_types": {
          "description": "The list of custom struct types to be used as field types",
          "type": "object",
          "patternProperties": {
            ".": {
              "type": "object",
              "properties": {
                "fields": {
                  "description": "Array of field definitions",
                  "type": "array",
                  "minItems": 0,
                  "items": {
                    "$ref": "#/definitions/field"
                  },
                  "uniqueItems": true
                }
              }
            }
          }
        }
      },
      "required": [
        "id",
        "fields"
      ]
    },
    "field": {
      "description": "Definition of a datarecord field",
      "type": "object",
      "properties": {
        "name": {
          "description": "Field name. Must be unique within the datarecord",
          "type": "string"
        },
        "type": {
          "description": "Field type. Can be a primitive type (string, integer, double, date, time, timestamp, binary, boolean, array[type], map[type, type]. The type can also be a reference to a struct_type declaration.)",
          "type": "string"
        },
        "nullable": {
          "description": "Whether or not one can place null values into the field",
          "type": "boolean",
          "default": false
        },
        "metadata": {
          "$ref": "#/definitions/metadata"
        },
        "app_data": {
          "$ref": "#/definitions/app_data_def"
        }
      },
      "required": [
        "name",
        "type"
      ]
    },
    "metadata": {
      "description": "Additional field metadata",
      "type": "object",
      "properties": {
        "description": {
          "description": "Field description",
          "type": "string"
        },
        "measure": {
          "description": "Field measurement level",
          "enum": [
            "range",
            "discrete",
            "flag",
            "set",
            "ordered-set",
            "typeless",
            "collection",
            "geospatial",
            "default"
          ]
        },
        "modeling_role": {
          "description": "Field role for modeling",
          "enum": [
            "input",
            "target",
            "both",
            "none",
            "partition",
            "split",
            "frequency",
            "record-id"
          ]
        },
        "max_length": {
          "description": "Maximum length for fields. Length is unlimited when not present",
          "type": "number"
        },
        "min_length": {
          "description": "Minimum length for fields",
          "type": "number"
        },
        "decimal_precision": {
          "description": "Precision for decimal, time, and timestamp types",
          "type": "number"
        },
        "decimal_scale": {
          "description": "Scale for decimal, time, and timestamp types",
          "type": "number"
        },
        "values": {
          "description": "Array of unique categorical values for the column",
          "type": "array",
          "minItems": 0,
          "items": {
            "description": "A value discovered in the data",
            "type": [
              "string",
              "number",
              "boolean"
            ]
          },
          "uniqueItems": true
        },
        "range": {
          "description": "Minimum and maximum discovered values for scalar data",
          "type": "object",
          "properties": {
            "min": {
              "description": "Lowest value discovered in the data",
              "type": [
                "string",
                "number"
              ]
            },
            "max": {
              "description": "Highest value discovered in the data",
              "type": [
                "string",
                "number"
              ]
            }
          },
          "required": [
            "min",
            "max"
          ]
        },
        "runtime_type": {
          "description": "Type of runtime",
          "type": "string"
        },
        "is_key": {
          "description": "A field is key",
          "type": "boolean"
        },
        "is_signed": {
          "description": "Signed or Unsigned for number",
          "type": "boolean"
        },
        "item_index": {
          "description": "Item record level",
          "type": "number"
        },
        "source_field_id": {
          "description": "Source field for a target field",
          "type": "string"
        }
      }
    },
    "app_data_def": {
      "description": "Object containing app-specific data",
      "type": "object",
      "properties": {
      },
      "additionalProperties": true
    }
  }
}
