{
  "$schema": "https://json-schema.org/draft-04/schema#",
  "id": "https://api.dataplatform.ibm.com/schemas/common-pipeline/operators/operator-v2-schema.json",
  "title": "Watson Data Platform Operator Schema",
  "description": "Operator schema for the Watson Data Platform",
  "type": "object",
  "properties": {
    "id": {
      "description": "Operator identifier",
      "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/operators/operator-v2-schema.json"
      ]
    },
    "operator_type": {
      "description": "operator type",
      "enum": [
        "model",
        "transformer",
        "estimator",
        "dataReader",
        "dataWriter"
      ]
    },
    "input_ports": {
      "description": "List of input ports. If no ports are defined this is a source operator that accepts no data inputs. If the input_ports array is missing a single input port with id 'input_port' is assumed which accepts only a single connection.",
      "type": "array",
      "minItems": 0,
      "items": {
        "$ref": "#/definitions/port_definition"
      }
    },
    "output_ports": {
      "description": "List of output ports. If no ports are defined this is a terminal operator that provides no data outputs. If the output_ports array is missing a single output port named 'output_port' is assumed which accepts multiple connections.",
      "type": "array",
      "minItems": 0,
      "items": {
        "$ref": "#/definitions/port_definition"
      }
    },
    "complex_types": {
      "description": "List of complex types",
      "type": "array",
      "items": {
        "$ref": "#/definitions/complex_type_definition"
      }
    },
    "parameters": {
      "description": "List of parameters",
      "type": "array",
      "items": {
        "$ref": "#/definitions/parameter_definition"
      }
    },
    "app_data": {
      "$ref": "#/definitions/app_data_def"
    }
  },
  "required": [
    "id",
    "operator_type",
    "parameters"
  ],
  "definitions": {
    "parameter_definition": {
      "description": "Operator parameters definition",
      "type": "object",
      "properties": {
        "id": {
          "description": "A unique name for the parameter.",
          "type": "string"
        },
        "required": {
          "description": "Indication whether parameter is required or optional",
          "type": "boolean",
          "default": false
        },
        "role": {
          "description": "Role of parameter",
          "enum": [
            "column",
            "new_column",
            "expression"
          ]
        },
        "type": {
          "description": "Field type. Can be a primitive type (string, integer, double, date, time, timestamp, or custom), an array, or map containing those types(note arrays and maps can contain complex_types)",
          "type": "string"
        },
        "enum": {
          "description": "List of valid values. Can be used instead of specifying type.",
          "type": "array"
        },
        "default": {
          "description": "default value based on type of parameter",
          "anyOf": [
            {
              "$ref": "#/definitions/parameter_ref_definition"
            },
            {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                },
                {
                  "type": "boolean"
                },
                {
                  "type": "array"
                },
                {
                  "type": "object"
                },
                {
                  "type": "null"
                }
              ]
            }
          ]
        }
      },
      "oneOf": [
        {
          "required": [
            "id",
            "type"
          ]
        },
        {
          "required": [
            "id",
            "enum"
          ]
        }
      ]
    },
    "parameter_ref_definition": {
      "description": "Structure for parameter refs",
      "type": "object",
      "properties": {
        "parameter_ref": {
          "description": "Reference to another parameter.",
          "type": "string"
        }
      },
      "required": [
        "parameter_ref"
      ]
    },
    "complex_type_definition": {
      "description": "Structure for complex parameters",
      "type": "object",
      "properties": {
        "id": {
          "description": "Identifier of complex type, can be referenced in other places.",
          "type": "string"
        },
        "key_definition": {
          "$ref": "#/definitions/parameter_definition"
        },
        "parameters": {
          "description": "List of parameters",
          "type": "array",
          "items": {
            "anyOf": [
              {
                "$ref": "#/definitions/parameter_definition"
              },
              {
                "$ref": "#/definitions/complex_type_definition"
              }
            ]
          }
        }
      },
      "required": [
        "id",
        "parameters"
      ]
    },
    "port_definition": {
      "description": "Operator ports support multiple differentiated connections for either inputs or outputs.",
      "type": "object",
      "properties": {
        "id": {
          "description": "Unique identifier within the node",
          "type": "string"
        },
        "cardinality": {
          "description": "Property to capture how many connections are allowed for this port, e.g., min: 1, max:1 implies you must supply 1 and only 1; min:0, max:1 implies it is optional and a max of one, min:0, max:-1 means it is optional and you can may have any number of connections. The default value is 1:1 for inputs and 1:-1 for outputs.",
          "type": "object",
          "properties": {
            "min": {
              "description": "Minimum data sets that are required for this port",
              "type": "integer",
              "default": 1
            },
            "max": {
              "description": "Maximum data sets that are allowed on this port. A negative value indicates unlimited. The default value is 1 for inputs and -1 for outputs.",
              "type": "integer"
            }
          },
          "additionalProperties": false
        }
      }
    },
    "app_data_def": {
      "description": "Object containing application-specific data",
      "type": "object",
      "properties": {},
      "additionalProperties": true
    }
  }
}
