{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "async_ref": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "address": {
          "type": "string"
        },
        "ssl": {
          "type": "boolean"
        },
        "type": {
          "type": "string",
          "enum": [
            "kafka",
            "amqp",
            "rabbitmq",
            "activemq",
            "redis",
            "gpubsub",
            "amazonsqs",
            "mqtt"
          ]
        },
        "actors": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/actor_ref"
          }
        }
      },
      "required": [
        "type",
        "address",
        "actors"
      ],
      "additionalProperties": false
    },
    "actor_ref": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "dataset": {
          "$ref": "#/definitions/dataset_ref"
        },
        "produce": {
          "oneOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/definitions/produce_ref"
              },
              "minItems": 1
            },
            {
              "$ref": "#/definitions/produce_ref"
            }
          ]
        },
        "consume": {
          "$ref": "#/definitions/consume_ref"
        },
        "delay": {
          "type": "number"
        },
        "limit": {
          "type": "integer"
        },
        "multiPayloadsLooped": {
          "type": "boolean"
        },
        "datasetLooped": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    },
    "produce_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "queue",
        "value"
      ],
      "properties": {
        "create": {
          "type": "boolean"
        },
        "queue": {
          "type": "string"
        },
        "tag": {
          "type": "string"
        },
        "key": {
          "type": [
            "string",
            "null"
          ]
        },
        "value": {
          "type": "string"
        },
        "headers": {
          "$ref": "#/definitions/headers_ref"
        },
        "amqpProperties": {
          "$ref": "#/definitions/amqp_properties_ref"
        }
      }
    },
    "consume_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "queue"
      ],
      "properties": {
        "group": {
          "type": "string"
        },
        "queue": {
          "type": "string"
        },
        "key": {
          "type": [
            "string",
            "null"
          ]
        },
        "schema": {
          "oneOf": [
            {
              "$ref": "http://json-schema.org/draft-07/schema#"
            },
            {
              "type": "string"
            }
          ]
        },
        "value": {
          "type": "string"
        },
        "headers": {
          "$ref": "#/definitions/headers_ref"
        },
        "amqpProperties": {
          "$ref": "#/definitions/amqp_properties_ref"
        },
        "capture": {
          "type": "integer"
        }
      }
    },
    "service_ref": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "hostname": {
          "type": "string"
        },
        "port": {
          "type": "integer"
        },
        "ssl": {
          "type": "boolean"
        },
        "sslCertFile": {
          "type": "string"
        },
        "sslKeyFile": {
          "type": "string"
        },
        "managementRoot": {
          "type": "string"
        },
        "oas": {
          "type": "string"
        },
        "endpoints": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/endpoint_ref"
          }
        },
        "performanceProfile": {
          "type": "string"
        },
        "fallbackTo": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "required": [
        "port"
      ]
    },
    "endpoint_ref": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "comment": {
          "type": "string"
        },
        "method": {
          "type": "string"
        },
        "path": {
          "type": "string"
        },
        "queryString": {
          "type": "object",
          "patternProperties": {
            ".+": {
              "type": "string"
            }
          }
        },
        "headers": {
          "type": "object",
          "patternProperties": {
            ".+": {
              "type": "string"
            }
          }
        },
        "body": {
          "type": "object",
          "properties": {
            "schema": {
              "oneOf": [
                {
                  "$ref": "http://json-schema.org/draft-07/schema#"
                },
                {
                  "type": "string"
                }
              ]
            },
            "text": {
              "type": "string"
            },
            "graphql-query": {
              "type": "string"
            },
            "graphql-variables": {
              "type": "object",
              ".+": {
                "type": "string"
              }
            },
            "urlencoded": {
              "type": "object",
              ".+": {
                "type": "string"
              }
            },
            "multipart": {
              "type": "object",
              ".+": {
                "type": "string"
              }
            }
          },
          "additionalProperties": false
        },
        "dataset": {
          "$ref": "#/definitions/dataset_ref"
        },
        "response": {
          "oneOf": [
            {
              "$ref": "#/definitions/response_ref"
            },
            {
              "type": "array",
              "items": {
                "$ref": "#/definitions/response_ref"
              }
            }
          ]
        },
        "multiResponsesLooped": {
          "type": "boolean"
        },
        "datasetLooped": {
          "type": "boolean"
        },
        "performanceProfile": {
          "type": "string"
        }
      },
      "required": [
        "path"
      ],
      "additionalProperties": false
    },
    "response_ref": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "object",
          "properties": {
            "headers": {
              "$ref": "#/definitions/headers_ref"
            },
            "status": {
              "type": [
                "string",
                "integer"
              ]
            },
            "body": {
              "type": "string"
            },
            "useTemplating": {
              "type": "boolean"
            },
            "templatingEngine": {
              "type": "string"
            },
            "tag": {
              "type": "string"
            },
            "triggerAsyncProducer": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          "additionalProperties": false
        }
      ]
    },
    "dataset_ref": {
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        {
          "type": "string"
        }
      ]
    },
    "headers_ref": {
      "type": "object",
      "patternProperties": {
        ".+": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          ]
        }
      }
    },
    "amqp_properties_ref": {
      "type": "object",
      "properties": {
        "content_type": {},
        "content_encoding": {},
        "delivery_mode": {},
        "priority": {},
        "correlation_id": {},
        "reply_to": {},
        "expiration": {},
        "message_id": {},
        "timestamp": {},
        "type": {},
        "user_id": {},
        "app_id": {},
        "cluster_id": {}
      },
      "additionalProperties": false
    },
    "profile_ref": {
      "type": "object",
      "properties": {
        "ratio": {
          "type": "number"
        },
        "delay": {
          "type": "number"
        },
        "faults": {
          "type": "object",
          "propertyNames": {
            "pattern": "^\\d+|RST|FIN|PASS$"
          },
          "items": {
            "type": "number"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "ratio"
      ]
    }
  },
  "type": "object",
  "properties": {
    "management": {
      "type": "object",
      "properties": {
        "port": {
          "type": "integer"
        },
        "ssl": {
          "type": "boolean"
        },
        "sslCertFile": {
          "type": "string"
        },
        "sslKeyFile": {
          "type": "string"
        }
      },
      "required": [
        "port"
      ],
      "additionalProperties": false
    },
    "templatingEngine": {
      "type": "string"
    },
    "globals": {
      "type": "object",
      "properties": {
        "headers": {
          "$ref": "#/definitions/headers_ref"
        },
        "performanceProfile": {
          "type": "string"
        }
      }
    },
    "services": {
      "type": "array",
      "minItems": 1,
      "items": {
        "anyOf": [
          {
            "$ref": "#/definitions/service_ref"
          },
          {
            "$ref": "#/definitions/async_ref"
          }
        ]
      }
    },
    "performanceProfiles": {
      "type": "object",
      "patternProperties": {
        ".+": {
          "$ref": "#/definitions/profile_ref"
        }
      }
    }
  },
  "additionalProperties": false,
  "required": [
    "services"
  ]
}
