{
    "id": "http://schema.management.azure.com/schemas/2015-02-01-preview/logicapps#",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Logic App Template Schema",
    "description": "Schema for Logic App templates",
    "properties": {
        "$schema": {
            "type": "string",
            "description": "Specifies the location of the JSON schema file that describes the version of the template language."
        },
        "contentVersion": {
            "type": "string",
            "pattern": "(^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$)",
            "description": "A 4 number format for the version number of this template file. For example, 1.0.0.0"
        },
        "parameters": {
            "type": "object",
            "additionalProperties": {
                "$ref": "#/definitions/parameter"
            },
            "description": "Parameters that are used to input data into the template. A maximum of 50 parameters can be defined."
        },
        "variables": {
            "type": "object",
            "additionalProperties": {
                "$ref": "#/definitions/variable"
            },
            "description": "Variables that are used in the template. A maximum of 100 variables can be defined."
        },
        "outputs": {
            "type": "object",
            "additionalProperties": {
                "$ref": "#/definitions/output"
            },
            "description": "Output of the logic app. A maximum of 10 outputs can be defined."
        },
        "triggers": {
            "type": "object",
            "additionalProperties": {
                "$ref": "#/definitions/trigger"
            },
            "description": "Triggers that initiate the logic app. A maximum of 10 triggers can be defined."
        },
        "actions": {
            "type": "object",
            "additionalProperties": {
                "$ref": "#/definitions/action"
            },
            "description": "Actions that are taken as the logic app executes.  A maximum of 250 actions can be defined."
        }
    },
    "required": [ "$schema", "contentVersion" ],
    "definitions": {
        "trigger": {
            "allOf": [
                { "$ref": "#/definitions/triggerBase" },
                {
                    "oneOf": [
                        { "$ref": "#/definitions/httpInput" },
                        { "$ref": "#/definitions/apiAppInput" },
                        { "$ref": "#/definitions/storageQueueInput" },
                        { "$ref": "#/definitions/recurrenceInput" }
                    ]
                }
            ]
        },
        "actionBase": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "description": "Type of trigger"
                },
                "conditions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/condition"
                    },
                    "description": "Array of conditions that must all evaluate to true"
                },
                "inputs": {
                    "type": "object",
                    "description": "Values that will be passed to the operation."
                }
            },
            "required": [ "type" ]
        },
        "triggerBase": {
            "allOf": [
                { "$ref": "#/definitions/actionBase" },
                {
                    "type": "object",
                    "properties": {
                        "recurrence": {
                            "$ref": "#/definitions/recurrenceDef"
                        }
                    }
                }
            ],
            "required": [ "recurrence" ]
        },
        "triggerBaseFull": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "description": "Type of trigger"
                },
                "conditions": {
                    "type": "array",
                    "description": "Set of conditions that will be evaluated after the trigger is called to see if the logic app should be run or not. All conditions in the array must evaluate to true for the logic app to run."
                },
                "inputs": {
                    "type": "object",
                    "description": "Values that will be passed to the operation."
                },
                "recurrence": {
                    "$ref": "#/definitions/recurrenceDef"
                }
            },
            "required": [
                "type",
                "recurrence"
            ]
        },
        "action": {
            "allOf": [
                { "$ref": "#/definitions/actionBase" },
                {
                    "type": "object",
                    "properties": {
                        "repeat": {
                            "type": [ "array", "string" ],
                            "description": "Collection of items. Action will execute for each item in the array.  Must either be an array or an expression that evaluates to an array."
                        }
                    }
                },
                {
                    "oneOf": [
                        { "$ref": "#/definitions/httpInput" },
                        { "$ref": "#/definitions/apiAppInput" },
                        { "$ref": "#/definitions/storageQueueInput" },
                        { "$ref": "#/definitions/logicAppInput" }
                    ]
                }
            ]
        },
        "recurrenceDef": {
            "type": "object",
            "properties": {
                "frequency": {
                    "enum": [
                        "Second",
                        "Minute",
                        "Hour",
                        "Day",
                        "Week",
                        "Month",
                        "Year"
                    ],
                    "description": "Unit of frequency at which the trigger will run"
                },
                "interval": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "Interval for specified frequency at which the trigger will run"
                }
            },
            "description": "Defines the recurrence interval for running the trigger. Maximum recurrence interval is 500 days.",
            "required": [ "frequency", "interval" ]
        },
        "parameter": {
            "type": "object",
            "properties": {
                "type": {
                    "$ref": "#/definitions/parameterTypes",
                    "description": "Type of input parameter"
                },
                "defaultValue": {
                    "$ref": "#/definitions/parameterValueTypes",
                    "description": "Default value to be used if one is not provided"
                },
                "allowedValues": {
                    "type": "array",
                    "description": "Value can only be one of these values"
                },
                "metadata": {
                    "type": "object",
                    "description": "Metadata for the parameter"
                }
            },
            "required": [ "type" ],
            "description": "Input parameter definitions"
        },
        "output": {
            "type": "object",
            "properties": {
                "type": {
                    "$ref": "#/definitions/parameterTypes",
                    "description": "Type of output value"
                },
                "value": {
                    "$ref": "#/definitions/parameterValueTypes",
                    "description": "Value assigned for output"
                }
            },
            "required": [ "type", "value" ],
            "description": "Set of output parameters"
        },
        "parameterTypes": {
            "enum": [ "string", "securestring", "int", "bool", "object", "array", "secureObject" ]
        },
        "parameterValueTypes": {
            "type": [ "string", "boolean", "integer", "number", "object", "array", "null" ]
        },
        "variable": {
            "type": "object",
            "properties": {
                "value": {
                    "type": [ "array", "boolean", "integer", "number", "object", "string" ],
                    "description": "Value of the variable"
                },
                "conditions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/condition"
                    },
                    "description": "Array of conditions that must all evaluate to true"
                },
                "elseValue": {
                    "type": [ "array", "boolean", "integer", "number", "object", "string" ],
                    "description": "Value to set to variable if condition evaluates to false"
                }
            },
            "required": [ "value" ]
        },
        "condition": {
            "anyOf": [
                {
                    "type": "object",
                    "properties": {
                        "dependsOn": {
                            "type": "string",
                            "description": "References another action or trigger that must execute before this action"
                        }
                    }
                },
                { 
                    "type": "object",
                    "properties": {
                        "expression": {
                            "type": "string",
                            "description": "Expression to evaluate to true or false"
                        }
                    }
                }
            ]
        },
        "recurrenceInput": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "Recurrence" ]
                }
            },
            "required": [
                "type"
            ]
        },
        "httpInput": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "Http" ]
                },
                "inputs": {
                    "type": "object",
                    "properties": {
                        "uri": {
                            "type": "string",
                            "maxLength": 2048,
                            "description": "URI of the endpoint to call"
                        },
                        "method": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "enum": [
                                        "GET",
                                        "PUT",
                                        "POST",
                                        "PATCH",
                                        "DELETE",
                                        "HEAD",
                                        "TRACE",
                                        "CONNECT",
                                        "OPTIONS"
                                    ]
                                }
                            ],
                            "description": "HTTP method used to communicate with the endpoint"
                        },
                        "headers": {
                            "type": "object",
                            "description": "Dictionary HTTP request headers. Limited to 50 headers."
                        },
                        "body": {
                            "type": "string",
                            "maxLength": 8192,
                            "description": "HTTP request body"
                        },
                        "authentication": {
                            "oneOf": [
                                { "$ref": "#/definitions/authClientCert" },
                                { "$ref": "#/definitions/authOAuth" },
                                { "$ref": "#/definitions/authBasic" }
                            ]
                        }

                    },
                    "required": [
                        "uri",
                        "method"
                    ]
                }
            },
            "required": [
                "type",
                "inputs"
            ]
        },
        "authClientCert": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "ClientCertificate" ],
                    "description": "Authentication type"
                },
                "pfx": {
                    "type": "string",
                    "maxLength": 32768,
                    "description": "base64-encoded pfx. Required when providing a different certificate."
                },
                "password": {
                    "type": "string",
                    "maxLength": 256,
                    "description": "Certificate password. Required when providing a different certificate."
                },
                "certificateThumbprint": {
                    "type": "string",
                    "description": "Thumbprint of the certificate set on the job. Must match the currently configured certificate."
                },
                "certificateExpiration": {
                    "type": "string",
                    "description": "Date-time of the expiration of the certificate set on the job. Must match the currently configured certificate."
                },
                "certificateSubjectName": {
                    "type": "string",
                    "description": "Subject name of the certificate set on the job. Must match the currently configured certficate."
                }
            },
            "required": [
                "type",
                "pfx",
                "password"
            ]
        },
        "authBasic": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "Basic" ],
                    "description": "Authentication type"
                },
                "username": {
                    "type": "string",
                    "maxLength": 4096,
                    "description": "Username to use for Basic Authentication"
                },
                "password": {
                    "type": "string",
                    "maxLength": 4096,
                    "description": "Password to use for Basic Authentication. Only required when providing a different username."
                }
            },
            "required": [
                "type",
                "username"
            ]
        },
        "authOAuth": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "ActiveDirectoryOAuth" ],
                    "description": "Authentication type"
                },
                "secret": {
                    "type": "string",
                    "maxLength": 4096,
                    "description": "OAuth secret. Only required when providing different OAuth profile."
                },
                "tenant": {
                    "type": "string",
                    "maxLength": 4096,
                    "description": "OAuth tenant id."
                },
                "audience": {
                    "type": "string",
                    "maxLength": 2048,
                    "description": "OAuth audience"
                },
                "clientId": {
                    "type": "string",
                    "maxLength": 4096,
                    "description": "OAuth client id"
                }
            },
            "required": [
                "type",
                "tenant",
                "audience",
                "clientId"
            ]
        },
        "storageQueueInput": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "StorageQueue" ]
                },
                "inputs": {
                    "type": "object",
                    "properties": {
                        "storageAccount": {
                            "type": "string",
                            "description": "Storage account containing the queue to send scheduled messages to"
                        },
                        "queueName": {
                            "type": "string",
                            "minLength": 3,
                            "maxLength": 63,
                            "pattern": "^[a-z0-9]",
                            "description": "Queue to send scheduled messages to"
                        },
                        "sasToken": {
                            "type": "string",
                            "description": "SAS Token of storage account that has add messages to queue permissions to the storage account"
                        },
                        "message": {
                            "type": "string",
                            "maxLength": 8192,
                            "description": "Message to send to queue"
                        }
                    },
                    "required": [
                        "storageAccount",
                        "queueName",
                        "sasToken",
                        "message"
                    ]
                }
            },
            "required": [
                "type",
                "inputs"
            ]
        },
        "apiAppInput": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "ApiApp" ]
                },
                "inputs": {
                    "type": "object",
                    "properties": {
                        "host": {
                            "type": "object",
                            "properties": {
                                "gateway": {
                                    "type": "string",
                                    "description": "Hostname of the API App"
                                },
                                "id": {
                                    "type": "string",
                                    "description": "Resource id of the API App"
                                }
                            },
                            "required": [
                                "gateway",
                                "id"
                            ]
                        },
                        "operation": {
                            "type": "string",
                            "description": "Which operation as defined in the API definition of the API App should be called"
                        },
                        "apiVersion": {
                            "type": "string",
                            "description": "API version of the API App"
                        },
                        "parameters": {
                            "type": "object",
                            "description": "Object representing each of the parameters that will be sent to the operation"
                        },
                        "authentication": {
                            "type": "object",
                            "properties": {
                                "type": {
                                    "enum": [ "Raw" ]
                                },
                                "scheme": {
                                    "type": "string"
                                },
                                "parameter": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "type",
                                "scheme",
                                "parameter"
                            ]
                        }
                    },
                    "required": [
                        "host",
                        "operation",
                        "apiVersion"
                    ]
                }
            },
            "required": [
                "type",
                "inputs"
            ]
        },
        "logicAppInput": {
            "type": "object",
            "properties": {
                "type": {
                    "enum": [ "LogicApp" ]
                },
                "inputs": {
                    "type": "object",
                    "properties": {
                        "uri": {
                            "type": "string",
                            "description": "Endpoint of the logic app being called"
                        },
                        "apiVersion": {
                            "type": "string",
                            "description": "API version of the logic app"
                        },
                        "trigger": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string",
                                    "description": "Name of the trigger on target logic app being called"
                                },
                                "outputs": {
                                    "type": "object",
                                    "description": "Resource id of the API App"
                                }
                            },
                            "required": [ "name" ]
                        },
                        "authentication": {
                            "oneOf": [
                                { "$ref": "#/definitions/authOAuth" },
                                { "$ref": "#/definitions/authBasic" }
                            ]
                        }
                    },
                    "required": [
                        "uri",
                        "apiVersion",
                        "trigger",
                        "authentication"
                    ]
                }

            }
        }
    }
}