{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "additionalProperties": false,
  "definitions": {
    "moduleType": {
      "enum": ["docker"]
    },
    "status": {
      "enum": ["running", "stopped"]
    },
    "restartPolicy": {
      "enum": ["never", "on-failure", "on-unhealthy", "always"]
    },
    "imagePullPolicy": {
      "enum": ["never", "on-create"]
    },
    "startupOrder": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295
    },
    "moduleSettings": {
      "type": "object",
      "required": ["image"],
      "properties": {
        "image": {
          "type": "string",
          "examples": ["mcr.microsoft.com/azureiotedge-agent:1.0"]
        }
      },
      "patternProperties": {
        "^(createoptions|createOptions)[0-9]*$": {
          "$ref": "#/definitions/createOptions"
        }
      },
      "additionalProperties": false
    },
    "env": {
      "type": "object",
      "patternProperties": {
        "^[^\\+#$\\s\\.]+$": {
          "type": "object",
          "required": ["value"],
          "properties": {
            "value": {
              "type": ["number", "string", "boolean"]
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "createOptions": {
      "type": "string",
      "contentMediaType": "application/json"
    }
  },
  "id": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.1.json",
  "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": {
              "type": "string",
              "pattern": "1.1"
            },
            "runtime": {
              "type": "object",
              "required": ["type", "settings"],
              "properties": {
                "type": {
                  "$ref": "#/definitions/moduleType"
                },
                "settings": {
                  "type": "object",
                  "properties": {
                    "minDockerVersion": {
                      "type": "string",
                      "examples": ["v1.25"]
                    },
                    "loggingOptions": {
                      "type": "string"
                    },
                    "registryCredentials": {
                      "type": "object",
                      "patternProperties": {
                        "^[^\\.\\$# ]+$": {
                          "type": "object",
                          "required": ["username", "password", "address"],
                          "properties": {
                            "username": {
                              "type": "string"
                            },
                            "password": {
                              "type": "string"
                            },
                            "address": {
                              "type": "string",
                              "pattern": "^[^\\s]+$"
                            }
                          },
                          "additionalProperties": false
                        }
                      },
                      "additionalProperties": false
                    }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            },
            "systemModules": {
              "type": "object",
              "required": ["edgeAgent", "edgeHub"],
              "properties": {
                "edgeAgent": {
                  "type": "object",
                  "required": ["type", "settings"],
                  "properties": {
                    "type": {
                      "$ref": "#/definitions/moduleType"
                    },
                    "settings": {
                      "$ref": "#/definitions/moduleSettings"
                    },
                    "env": {
                      "$ref": "#/definitions/env"
                    },
                    "imagePullPolicy": {
                      "$ref": "#/definitions/imagePullPolicy"
                    }
                  },
                  "additionalProperties": false
                },
                "edgeHub": {
                  "type": "object",
                  "title": "The Edgehub Schema",
                  "required": ["type", "settings", "status", "restartPolicy"],
                  "properties": {
                    "type": {
                      "$ref": "#/definitions/moduleType"
                    },
                    "settings": {
                      "$ref": "#/definitions/moduleSettings"
                    },
                    "env": {
                      "$ref": "#/definitions/env"
                    },
                    "status": {
                      "$ref": "#/definitions/status"
                    },
                    "restartPolicy": {
                      "$ref": "#/definitions/restartPolicy"
                    },
                    "imagePullPolicy": {
                      "$ref": "#/definitions/imagePullPolicy"
                    },
                    "startupOrder": {
                      "$ref": "#/definitions/startupOrder"
                    }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            },
            "modules": {
              "type": "object",
              "patternProperties": {
                "^[a-zA-Z0-9_-]+$": {
                  "type": "object",
                  "required": ["type", "status", "restartPolicy", "settings"],
                  "properties": {
                    "version": {
                      "type": "string",
                      "examples": ["1.0"]
                    },
                    "type": {
                      "$ref": "#/definitions/moduleType"
                    },
                    "status": {
                      "$ref": "#/definitions/status"
                    },
                    "restartPolicy": {
                      "$ref": "#/definitions/restartPolicy"
                    },
                    "env": {
                      "$ref": "#/definitions/env"
                    },
                    "settings": {
                      "$ref": "#/definitions/moduleSettings"
                    },
                    "imagePullPolicy": {
                      "$ref": "#/definitions/imagePullPolicy"
                    },
                    "startupOrder": {
                      "$ref": "#/definitions/startupOrder"
                    }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  },
  "required": ["$edgeAgent"],
  "title": "JSON schema for Azure IoT EdgeAgent Deployment version 1.1",
  "type": "object"
}