{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "moduleSettings": {
      "type": "object",
      "required": ["image"],
      "properties": {
        "image": {
          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/moduleSettings/properties/image"
        }
      },
      "patternProperties": {
        "^(createoptions|createOptions)[0-9]*$": {
          "$ref": "#/definitions/createOptions"
        }
      }
    },
    "createOptions": {
      "type": ["object", "string"],
      "contentMediaType": "application/json"
    }
  },
  "id": "https://json.schemastore.org/azure-iot-edge-deployment-template-4.0.json",
  "properties": {
    "modulesContent": {
      "type": "object",
      "title": "The configuration for all the modules.",
      "required": ["$edgeAgent"],
      "properties": {
        "$edgeAgent": {
          "type": "object",
          "title": "Configuration for the edgeAgent module",
          "required": ["properties.desired"],
          "properties": {
            "properties.desired": {
              "type": "object",
              "required": [
                "schemaVersion",
                "runtime",
                "systemModules",
                "modules"
              ],
              "properties": {
                "schemaVersion": {
                  "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/properties/$edgeAgent/properties/properties.desired/properties/schemaVersion"
                },
                "runtime": {
                  "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/properties/$edgeAgent/properties/properties.desired/properties/runtime"
                },
                "systemModules": {
                  "type": "object",
                  "required": ["edgeAgent", "edgeHub"],
                  "properties": {
                    "edgeAgent": {
                      "type": "object",
                      "required": ["type", "settings"],
                      "properties": {
                        "type": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/moduleType"
                        },
                        "settings": {
                          "$ref": "#/definitions/moduleSettings"
                        },
                        "env": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/env"
                        },
                        "imagePullPolicy": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/imagePullPolicy"
                        }
                      }
                    },
                    "edgeHub": {
                      "type": "object",
                      "title": "The Edgehub Schema",
                      "required": [
                        "type",
                        "settings",
                        "status",
                        "restartPolicy"
                      ],
                      "properties": {
                        "type": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/moduleType"
                        },
                        "settings": {
                          "$ref": "#/definitions/moduleSettings"
                        },
                        "env": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/env"
                        },
                        "status": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/status"
                        },
                        "restartPolicy": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/restartPolicy"
                        },
                        "imagePullPolicy": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/imagePullPolicy"
                        },
                        "startupOrder": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/startupOrder"
                        }
                      }
                    }
                  }
                },
                "modules": {
                  "type": "object",
                  "patternProperties": {
                    "^[a-zA-Z0-9_-]+$": {
                      "type": "object",
                      "required": [
                        "type",
                        "status",
                        "restartPolicy",
                        "settings"
                      ],
                      "properties": {
                        "version": {
                          "type": "string",
                          "examples": ["1.0"]
                        },
                        "type": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/moduleType"
                        },
                        "status": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/status"
                        },
                        "restartPolicy": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/restartPolicy"
                        },
                        "env": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/env"
                        },
                        "settings": {
                          "$ref": "#/definitions/moduleSettings"
                        },
                        "imagePullPolicy": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/imagePullPolicy"
                        },
                        "startupOrder": {
                          "$ref": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json#/definitions/startupOrder"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "$edgeHub": {
          "$ref": "https://json.schemastore.org/azure-iot-edgehub-deployment-1.2.json#/properties/$edgeHub"
        }
      }
    }
  },
  "required": ["modulesContent"],
  "title": "JSON schema for Azure IoT Edge Deployment Template version 4.0 (Edge Agent schema v1.1 + Edge Hub schema v1.2 )",
  "type": "object"
}
