{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$comment": "v1.0",
    "definitions": {
        "onRequestError": {
            "type": "string",
            "enum": ["nextRequest" ,"nextStep", "stopTest"],
            "description": "Method for handling request errors",
            "default":"stopTest"
        },
        "library": {
            "type": "object",
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["data", "vars", "certificate", "ats"]
                },
                "name": {
                    "type": "string"
                },
                "scope": {
                    "type": "string",
                    "enum": ["project", "fileSystem", "url"]
                },
                "src": {
                    "type": "string"
                },
                "options": {
                    "type": "object"
                }
            },
            "additionalProperties": false,
            "required": ["type", "name", "scope", "src"]
        },
        "httpsAgent": {
            "type": "object",
            "properties": {
                "rejectUnauthorized": {
                    "type": "boolean"
                },
                "ca": {
                    "type": "string"
                },
                "cert": {
                    "type": "string"
                },
                "key": {
                    "type": "string"
                },
                "pfx": {
                    "type": "string"
                }
            }
        },
        "script": {
            "type": "object",
            "properties": {
                "scope": {
                    "type": "string",
                    "enum": ["before", "after", "afterEach", "beforeEach"]
                },
                "script": {
                    "type": ["array", "string"]
                },
                "name": {
                    "type": "string"
                },
                "async": {
                    "type": "boolean"
                },
                "options": {
                    "type": "object",
                    "properties": {
                        "builtin": {
                            "type": "array",
                            "contains": {
                                "type": "string",
                                "pattern": "^(?!(fs)|(\\*)).*$"
                            }
                        }
                    }
                }
            },
            "additionalProperties": false,
            "required": ["scope", "script", "name"]
        },
        "authMethod": {
            "type": "object",
            "properties": {
                "method": {
                    "type": "string",
                    "enum": ["aws4sign", "bearerToken"],
                    "default": "aws4sign"
                },
                "variableName": {
                    "type": "string"
                },
                "aws4sign": {
                    "type": "object",
                    "properties": {
                        "region": {
                            "type": "string"
                        },
                        "service": {
                            "type": "string"
                        },
                        "accessKeyId": {
                            "type": "string"
                        },
                        "secretAccessKey": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "region",
                        "service",
                        "accessKeyId",
                        "secretAccessKey"
                    ]
                }
            },
            "required": ["method"]
        },
        "config": {
            "type": "object",
            "properties": {
                "url": {
                    "type": "string"
                },
                "method": {
                    "type": "string",
                    "default": "get"
                },
                "headers": {
                    "type": "object",
                    "allOf": [
                        {
                            "type": "object",
                            "patternProperties": {
                                "^.*$": {
                                    "type": "string"
                                }
                            }
                        }
                    ]
                },
                "params": {
                    "type": "object",
                    "description": "Query parameters",
                    "allOf": [
                        {
                            "type": "object",
                            "patternProperties": {
                                "^.*$": {
                                    "type": [
                                        "string",
                                        "object",
                                        "boolean",
                                        "number"
                                    ]
                                }
                            }
                        }
                    ]
                },
                "data": {
                    "type": ["object", "string", "array"]
                },
                "timeout": {
                    "type": "number",
                    "default": 0,
                    "description": "Request timeout (ms). Default 0=no timeout"
                },
                "maxContentLength": {
                    "type": "number",
                    "description": "Max content length stored in response"
                },
                "withCredentials": {
                    "type": "boolean",
                    "default": false,
                    "description": "Indicates whether or not cross-site Access-Control requests should be made using credentials"
                },
                "auth": {
                    "type": "object",
                    "properties": {
                        "username": {
                            "type": "string"
                        },
                        "password": {
                            "type": "string"
                        }
                    },
                    "required": ["username", "password"],
                    "additionalProperties": false
                }
            },
            "additionalProperties": true
        },
        "variable": {
            "type": "object",
            "properties": {
                "key": {
                    "type": "string",
                    "pattern": "^[A-Za-z_]\\w+$"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "number",
                        "string",
                        "url",
                        "array",
                        "object",
                        "boolean",
                        "header"
                    ]
                },
                "encrypt": {
                    "type": "string",
                    "enum": ["encryptionKey", "encryptedValue"]
                },
                "usage": {
                    "type": "string",
                    "enum": [
                        "returnValue",
                        "info",
                        "inResponse",
                        "input",
                        "urlLink",
                        "metric",
                        ""
                    ]
                },
                "value": {},
                "hideValue": {
                    "type": "boolean"
                },
                "description": {
                    "type": "string"
                },
                "unit": {
                    "type": "string",
                    "default": "ms"
                },
                "validation": {
                    "type": "string"
                }
            },
            "required": ["key", "type", "usage"]
        },
        "variables": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/variable"
            }
        }
    },
    "type": "object",
    "properties": {
        "$schema": {
            "type": "string"
        },
        "name": {
            "type": "string"
        },
        "description": {
            "type": "string"
        },
        "message": {
            "type": "string"
        },
        "flowControl": {
            "description": "Flow control for the test. Can be 'Chained Flow' or 'Individual Tests'",
            "default": "Chained Flow",
            "enum": ["Chained Flow", "Individual Tests"]
        },
        "requestTimeCalculation": {
            "description": "Custom calculation of request response time. Default total response time in ms.",
            "type": "string",
            "enum": [
                "TotalTime",
                "Request",
                "DNS",
                "TimeToFirstByte",
                "DownloadTime",
                "ContentLength"
            ],
            "default": "TotalTime"
        },
        "reportCustomMetrics": {
            "description": "Return custom metrics in the report. Replace or extend to timing metrics.",
            "type": "string",
            "enum":["extend","replace","none"]

        },
        "envPrefix": {
            "description": "Prefix for environment variables used to replace input variable values. Max length 6",
            "type": "string",
            "examples": ["KK"],
            "pattern": "^[a-zA-Z]+$",
            "maxLength": 6

        },
        "hideSteps": {
            "description": "Hide step data in report",
            "type":"boolean",
            "default": false
        },
        "variables": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/variable"
            }
        },
        "baseURL": {
            "type": "string",
            "pattern": "^https?://"
        },
        "config": {
            "$ref": "#/definitions/config"
        },
        "includes": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/library"
            }
        },

        "httpsAgent": {
            "$ref": "#/definitions/httpsAgent"
        },

        "scripts": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/script"
            }
        },
        "steps": {
            "type": "array",
            "minItems": 1,
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string"
                    },
                    "idleBetweenRequests": {
                        "type": ["number", "string"]
                    },
                    "disabled": {
                        "type": "boolean"
                    },
                    "ignoreDuration": {
                        "type": "boolean"
                    },
                    "scripts": {
                        "type": "array",
                        "items": {
                            "$ref": "#/definitions/script"
                        }
                    },
                    "authMethod": {
                        "$ref": "#/definitions/authMethod"
                    },
                    "onRequestError": {
                        "$ref": "#/definitions/onRequestError"
                    },
                    "httpsAgent": {
                        "$ref": "#/definitions/httpsAgent"
                    },
                    "iterator": {
                        "type": "object",
                        "properties": {
                            "varName": {
                                "type": "string"
                            },
                            "value": {
                                "type": ["string", "array", "integer"]
                            },
                            "waitForValidResponse": {
                                "type": "boolean"
                            },
                            "maxLaps": {
                                "type": ["integer", "string"],
                                "description": "Max laps in array based iterator"
                            }
                        },
                        "required": ["value"]
                    },
                    "requests": {
                        "type": "array",
                        "minItems": 1,
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "message": {
                                    "type": "string",
                                    "description": "An informative message in the result. Can contain placeholders"
                                },
                                "disabled": {
                                    "type": "boolean"
                                },
                                "alwaysSaveResponse": {
                                    "type": "boolean",
                                    "description": "Always save the response to this request",
                                    "default": false
                                },
                                "onRequestError": {
                                    "$ref": "#/definitions/onRequestError"
                                },
                                "authMethod": {
                                    "$ref": "#/definitions/authMethod"
                                },
                                "httpsAgent": {
                                    "$ref": "#/definitions/httpsAgent"
                                },
                                "condition": {
                                    "type": "object",
                                    "properties": {
                                        "value": {
                                            "type": "string"
                                        },
                                        "expression": {
                                            "type": "string",
                                            "pattern": "^(?!.*(while|for)).*$"
                                        }
                                    },
                                    "required": ["value", "expression"]
                                },
                                "config": {
                                    "$ref": "#/definitions/config"
                                },
                                "scripts": {
                                    "type": "array",
                                    "items": {
                                        "$ref": "#/definitions/script"
                                    }
                                },
                                "notSaveData": {
                                    "type": "boolean"
                                },
                                "expectedStatus": {
                                    "minItems": 1,
                                    "type": ["array", "number", "string"],
                                    "items": {
                                        "type": "number"
                                    }
                                },
                                "extractors": {
                                    "type": "array",
                                    "items": {
                                        "type": "object",
                                        "properties": {
                                            "type": {
                                                "type": "string",
                                                "enum": [
                                                    "jsonpath",
                                                    "regexp",
                                                    "xpath",
                                                    "header",
                                                    "cookie"
                                                ]
                                            },
                                            "expression": {
                                                "type": "string"
                                            },
                                            "variable": {
                                                "type": "string",
                                                "pattern": "^[A-Za-z_]\\w+$"
                                            },
                                            "index": {
                                                "type": "boolean"
                                            },
                                            "counter": {
                                                "type": "boolean"
                                            },
                                            "notFoundError": {
                                                "type": "boolean"
                                            },
                                            "array": {
                                                "type": "boolean"
                                            }
                                        },
                                        "required": [
                                            "type",
                                            "expression",
                                            "variable"
                                        ]
                                    }
                                },
                                "assertions": {
                                    "type": "array",
                                    "items": {
                                        "type": "object",
                                        "properties": {
                                            "type": {
                                                "type": "string",
                                                "enum": [
                                                    "javaScript",
                                                    "regexp",
                                                    "value"
                                                ]
                                            },
                                            "value": {
                                                "type": "string"
                                            },
                                            "description": {
                                                "type": "string"
                                            },
                                            "expression": {
                                                "type": "string"
                                            },
                                            "failStep": {
                                                "type": "boolean"
                                            },
                                            "reportFailOnly": {
                                                "type": "boolean"
                                            }
                                        },
                                        "required": [
                                            "type",
                                            "description",
                                            "expression"
                                        ]
                                    }
                                },
                                "transformers": {
                                    "type": "array",
                                    "items": {
                                        "type": "object",
                                        "properties": {
                                            "type": {
                                                "type": "string",
                                                "enum": ["extract", "replace"]
                                            },
                                            "source": {
                                                "type": "string"
                                            },
                                            "target": {
                                                "type": "string"
                                            },
                                            "from": {
                                                "type": "string"
                                            },
                                            "to": {
                                                "type": "string"
                                            }
                                        },
                                        "required": ["source", "target"]
                                    },
                                    "defaultHeaders": {
                                        "type": "object",
                                        "allOf": [
                                            {
                                                "type": "object",
                                                "patternProperties": {
                                                    "^.*$": {
                                                        "type": "string"
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                }
                            },
                            "additionalProperties": false,
                            "required": ["config"]
                        }
                    }
                },
                "additionalProperties": false,
                "required": ["name", "requests"]
            }
        }
    },
    "required": ["name", "baseURL", "steps"],
    "additionalProperties": false
}
