{
  "$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-edge-deployment-2.0.json",
  "properties": {
    "modulesContent": {
      "type": "object",
      "title": "The configuration for all the modules.",
      "required": ["$edgeAgent", "$edgeHub"],
      "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",
                  "examples": ["1.0", "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
        },
        "$edgeHub": {
          "type": "object",
          "title": "Configuration for the edgeHub module",
          "required": ["properties.desired"],
          "properties": {
            "properties.desired": {
              "type": "object",
              "required": ["schemaVersion", "routes"],
              "properties": {
                "schemaVersion": {
                  "type": "string",
                  "examples": ["1.0", "1.1"]
                },
                "routes": {
                  "type": "object",
                  "patternProperties": {
                    "^[^\\.\\$# ]+$": {
                      "anyOf": [
                        {
                          "type": "object",
                          "required": ["route"],
                          "properties": {
                            "route": {
                              "type": "string",
                              "examples": ["FROM /* INTO $upstream"],
                              "pattern": "^.+$"
                            },
                            "priority": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 9
                            },
                            "timeToLiveSecs": {
                              "type": "integer",
                              "minimum": 0,
                              "maximum": 4294967295
                            }
                          },
                          "additionalProperties": false
                        },
                        {
                          "type": "string",
                          "examples": ["FROM /* INTO $upstream"],
                          "pattern": "^.+$"
                        }
                      ]
                    }
                  },
                  "additionalProperties": false
                },
                "storeAndForwardConfiguration": {
                  "type": "object",
                  "required": ["timeToLiveSecs"],
                  "properties": {
                    "timeToLiveSecs": {
                      "type": "integer",
                      "examples": [7200]
                    }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        }
      },
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": ["properties.desired"],
          "properties": {
            "properties.desired": {
              "type": "object"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  },
  "required": ["modulesContent"],
  "title": "JSON schema for Azure IoT Edge Deployment version 2.0",
  "type": "object"
}