{
    "title": "Flower 0.1 schema",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "required": [
        "flower",
        "id",
        "flows"
    ],
    "additionalProperties": false,
    "patternProperties": {
        "^x-[\\w\\d\\.\\-\\_]+$": {
            "$ref": "#/definitions/specificationExtension"
        }
    },
    "properties": {
        "flower": {
            "type": [
                "string"
            ],
            "enum": [
                "0.1"
            ],
            "description": "The Flower specification version of this document."
        },
        "id": {
            "type": "string",
            "description": "A unique id representing the workflow set."
        },
        "title": {
            "type": "string"
        },
        "description": {
            "type": "string"
        },
        "flows": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/flow"
            }
        }
    },
    "definitions": {
        "flow": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                },
                "inputs": {
                    "$ref": "#/definitions/schema"
                },
                "outputs": {
                    "$ref": "#/definitions/expressionMap"
                },
                "steps": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/step"
                    }
                }
            },
            "required": [
                "id",
                "steps"
            ]
        },
        "step": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "string"
                },
                "outputs": {
                    "$ref": "#/definitions/expressionMap"
                },
                "request": {
                    "type": "object",
                    "properties": {
                        "method": {
                            "type": "string"
                        },
                        "url": {
                            "type": "string"
                        },
                        "headers": {
                            "$ref": "#/definitions/expressionMap"
                        },
                        "query": {
                            "$ref": "#/definitions/expressionMap"
                        },
                        "body": {
                            "$ref": "#/definitions/expressionMap"
                        }
                    }
                },
                "actions": {
                    "type": "array",
                    "items": {
                        "oneOf": [
                            {
                                "$ref": "#/definitions/next"
                            },
                            {
                                "$ref": "#/definitions/retry"
                            },
                            {
                                "$ref": "#/definitions/goto"
                            },
                            {
                                "$ref": "#/definitions/end"
                            }
                        ]
                    }
                }
            },
            "required": [
                "id",
                "request"
            ]
        },
        "action": {
            "type": "object",
            "required": [
                "do"
            ],
            "properties": {
                "id": {
                    "type": "string"
                },
                "when": {
                    "type": "string",
                    "description": "A runtime expression conditioning this action"
                },
                "do": {
                    "type": "string"
                }
            },
            "discriminator": {
                "propertyName": "do",
                "mapping": {
                    "next": "#/definitions/next",
                    "retry": "#/definitions/retry",
                    "goto": "#/definitions/goto",
                    "end": "#/definitions/end"
                }
            }
        },
        "next": {
            "allOf": [
                {
                    "$ref": "#/definitions/action"
                },
                {
                    "type": "object",
                    "properties": {
                        "do": {
                            "type": "string",
                            "const": "next"
                        }
                    }
                }
            ]
        },
        "retry": {
            "allOf": [
                {
                    "$ref": "#/definitions/action"
                },
                {
                    "type": "object",
                    "properties": {
                        "do": {
                            "type": "string",
                            "const": "retry"
                        },
                        "wait": {
                            "type": "integer",
                            "description": "Number of seconds to wait",
                            "default": 5
                        },
                        "max_retry": {
                            "type": "integer",
                            "description": "Maximum number of subsequent retries to execute",
                            "default": 5
                        }
                    }
                }
            ]
        },
        "goto": {
            "allOf": [
                {
                    "$ref": "#/definitions/action"
                },
                {
                    "type": "object",
                    "required": [
                        "step"
                    ],
                    "properties": {
                        "do": {
                            "type": "string",
                            "const": "goto"
                        },
                        "step": {
                            "type": "string",
                            "description": "The target step ID to jump to"
                        }
                    }
                }
            ]
        },
        "end": {
            "allOf": [
                {
                    "$ref": "#/definitions/action"
                },
                {
                    "type": "object",
                    "properties": {
                        "do": {
                            "type": "string",
                            "const": "end"
                        }
                    }
                }
            ]
        },
        "expressionMap": {
            "type": "object",
            "description": "A map of names to runtime expressions.",
            "additionalProperties": {
                "type": "string",
                "description": "A runtime expression."
            }
        },
        "schema": {
            "allOf": [
                {
                    "$ref": "http://json-schema.org/draft-07/schema#"
                },
                {
                    "type": "object",
                    "patternProperties": {
                        "^x-[\\w\\d\\.\\-\\_]+$": {
                            "$ref": "#/definitions/specificationExtension"
                        }
                    }
                }
            ]
        },
        "specificationExtension": {
            "oneOf": [
                {
                    "type": "object",
                    "description": "Any property starting with x- is valid.",
                    "additionalProperties": true
                },
                {}
            ]
        }
    }
}
