{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "additionalProperties": false,
  "definitions": {
    "policy": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "operations": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^mqtt:connect$|^mqtt:subscribe$|^mqtt:publish$"
            }
          },
          "resources": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^.+$",
              "examples": ["$iothub/clients/+/twin/res/#", "events/alerts"]
            }
          }
        },
        "additionalProperties": false
      }
    }
  },
  "id": "https://json.schemastore.org/azure-iot-edgehub-deployment-1.2.json",
  "properties": {
    "$edgeHub": {
      "type": "object",
      "title": "Configuration for the edgeHub module",
      "required": ["properties.desired"],
      "properties": {
        "properties.desired": {
          "type": "object",
          "required": ["schemaVersion", "routes"],
          "properties": {
            "schemaVersion": {
              "type": "string",
              "pattern": "1.2"
            },
            "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
            },
            "mqttBroker": {
              "type": "object",
              "properties": {
                "bridges": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "endpoint": {
                        "type": "string",
                        "pattern": "\\$upstream"
                      },
                      "settings": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "direction": {
                              "type": "string",
                              "pattern": "^in$|^out$"
                            },
                            "topic": {
                              "type": "string",
                              "pattern": "^.*$"
                            },
                            "inPrefix": {
                              "type": "string",
                              "pattern": "^.*$"
                            },
                            "outPrefix": {
                              "type": "string",
                              "pattern": "^.*$"
                            }
                          },
                          "additionalProperties": false
                        }
                      }
                    },
                    "additionalProperties": false
                  }
                },
                "authorizations": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "identities": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "pattern": "^.+$",
                          "examples": [
                            "{{iot:identity}}",
                            "contoso.azure-devices.net/MyLeafDevice1",
                            "contoso.azure-devices.net/MyEdgeDevice/MyModule"
                          ]
                        }
                      },
                      "allow": {
                        "$ref": "#/definitions/policy"
                      },
                      "deny": {
                        "$ref": "#/definitions/policy"
                      }
                    },
                    "additionalProperties": false
                  }
                }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  },
  "required": ["$edgeHub"],
  "title": "JSON schema for Azure IoT EdgeHub Deployment version 1.2",
  "type": "object"
}
