{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "id": "https://github.com/pegasus-isi/craft-schema",
    "type": "object",
    "title": "Design Flow",
    "properties": {
        "name": {
            "id": "https://github.com/pegasus-isi/craft-schema/name",
            "minLength": 1,
            "description": "Design flow name.",
            "type": "string"
        },
        "tools": {
            "id": "https://github.com/pegasus-isi/craft-schema/tools",
            "description": "List of tools from the flow.",
            "type": "array",
            "items": {
                "id": "https://github.com/pegasus-isi/craft-schema/tool",
                "type": "object",
                "properties": {
                    "id": {
                        "id": "https://github.com/pegasus-isi/craft-schema/tool/id",
                        "minLength": 1,
                        "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                        "type": "string",
                        "pattern": "^[0-9a-zA-Z -_]*$"
                    },
                    "sc-id": {
                        "id": "https://github.com/pegasus-isi/craft-schema/tool/sc-id",
                        "minLength": 1,
                        "description": "The id for the tool in the software catalog",
                        "type": "string",
                        "pattern": "^[0-9a-zA-Z -_]*$"
                    },
                    "name": {
                        "id": "https://github.com/pegasus-isi/craft-schema/tool/name",
                        "minLength": 1,
                        "description": "A human-readable name for the tool.",
                        "type": "string"
                    },
                    "version": {
                        "id": "https://github.com/pegasus-isi/craft-schema/tool/version",
                        "minLength": 1,
                        "description": "Tool version.",
                        "type": "string"
                    },
                    "script": {
                        "id": "https://github.com/pegasus-isi/craft-schema/tool/script",
                        "minLength": 1,
                        "description": "Installation and configuration script.",
                        "type": "string"
                    },
                    "functionality": {
                        "id": "https://github.com/pegasus-isi/craft-schema/tool/functionality",
                        "type": "object",
                        "properties": {
                            "description": {
                                "id": "https://github.com/pegasus-isi/craft-schema/tool/functionality/description",
                                "description": "Description of the stage.",
                                "type": "string"
                            },
                            "notes": {
                                "id": "https://github.com/pegasus-isi/craft-schema/tool/functionality/notes",
                                "description": "Additional notes.",
                                "type": "string"
                            }
                        },
                        "required": [
                            "description"
                        ]
                    },
                    "options": {
                        "id": "https://github.com/pegasus-isi/craft-schema/tool/options",
                        "type": "array",
                        "items": {
                            "id": "https://github.com/pegasus-isi/craft-schema/tool/option",
                            "type": "object",
                            "properties": {
                                "id": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/tool/option/id",
                                    "minLength": 1,
                                    "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                                    "type": "string",
                                    "pattern": "^[0-9a-zA-Z -_]*$"
                                },
                                "description": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/tool/option/description",
                                    "type": "string"
                                },
                                "purpose": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/tool/option/purpose",
                                    "type": "string"
                                },
                                "notes": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/tool/option/notes",
                                    "type": "string"
                                }
                            },
                            "required": [
                                "id",
                                "description",
                                "purpose"
                            ]
                        }
                    }
                },
                "oneOf": [
                    {
                        "required": [
                            "id",
                            "name",
                            "version",
                            "functionality"
                        ]
                    },
                    {
                        "required": [
                            "sc-id",
                            "options"
                        ]
                    }
                ]
            }
        },
        "files": {
            "id": "https://github.com/pegasus-isi/craft-schema/files",
            "description": "List of files from the flow.",
            "type": "array",
            "items": {
                "id": "https://github.com/pegasus-isi/craft-schema/file",
                "type": "object",
                "properties": {
                    "id": {
                        "id": "https://github.com/pegasus-isi/craft-schema/file/id",
                        "minLength": 1,
                        "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                        "type": "string",
                        "pattern": "^[0-9a-zA-Z -_]*$"
                    },
                    "content": {
                        "id": "https://github.com/pegasus-isi/craft-schema/file/content",
                        "type": "string"
                    },
                    "format": {
                        "id": "https://github.com/pegasus-isi/craft-schema/file/format",
                        "type": "string"
                    },
                    "description": {
                        "id": "https://github.com/pegasus-isi/craft-schema/file/description",
                        "type": "string"
                    },
                    "notes": {
                        "id": "https://github.com/pegasus-isi/craft-schema/file/notes",
                        "type": "string"
                    },
                    "link": {
                        "id": "https://github.com/pegasus-isi/craft-schema/file/link",
                        "type": "string",
                        "format": "uri",
                        "pattern": "^(https?|ftp|file)://"
                    }
                }
            }
        },
        "stages": {
            "id": "https://github.com/pegasus-isi/craft-schema/stages",
            "description": "List of stages from the flow.",
            "type": "array",
            "items": {
                "id": "https://github.com/pegasus-isi/craft-schema/stage",
                "type": "object",
                "properties": {
                    "id": {
                        "id": "https://github.com/pegasus-isi/craft-schema/stage/id",
                        "minLength": 1,
                        "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                        "type": "string",
                        "pattern": "^[0-9a-zA-Z -_]*$"
                    },
                    "name": {
                        "id": "https://github.com/pegasus-isi/craft-schema/stage/name",
                        "minLength": 1,
                        "description": "A human-readable name for the stage.",
                        "type": "string"
                    },
                    "tool": {
                        "id": "https://github.com/pegasus-isi/craft-schema/stage/tool",
                        "type": "object",
                        "properties": {
                            "tool-id": {
                                "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/tool-id",
                                "description": "ID of a custom defined tool",
                                "type": "string"
                            },
                            "sc-tool-id": {
                                "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/sc-tool-id",
                                "description": "ID of a tool from the software catalog",
                                "type": "string"
                            },
                            "option-control-module": {
                                "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/option-control-modules",
                                "type": "array",
                                "items": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/option-control-module",
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/option-control-module/id",
                                            "minLength": 1,
                                            "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                                            "type": "string",
                                            "pattern": "^[0-9a-zA-Z -_]*$"
                                        },
                                        "description": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/option-control-module/description",
                                            "type": "string"
                                        },
                                        "purpose": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/option-control-module/purpose",
                                            "type": "string"
                                        },
                                        "notes": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/option-control-module/notes",
                                            "type": "string"
                                        },
                                        "designer-guide": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/tool/option-control-module/designer-guide",
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "id",
                                        "description",
                                        "purpose"
                                    ]
                                }
                            }
                        },
                        "oneOf": [
                            {
                                "required": [
                                    "tool-id"
                                ]
                            },
                            {
                                "required": [
                                    "sc-tool-id"
                                ]
                            }
                        ]
                    },
                    "inputs": {
                        "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs",
                        "type": "object",
                        "properties": {
                            "files": {
                                "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/files",
                                "type": "array",
                                "items": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/file",
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/file/input-id",
                                            "description": "ID of an input file.",
                                            "type": "string",
                                            "pattern": "^[0-9a-zA-Z -_]*$"
                                        },
                                        "optional": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/input-file/optional",
                                            "description": "Whether this input is optional.",
                                            "type": "boolean",
                                            "default": false
                                        },
                                        "provided-by": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/input-file/provided-by",
                                            "enum": [
                                                "User",
                                                "Vendor"
                                            ]
                                        }
                                    },
                                    "required": [
                                        "id",
                                        "provided-by"
                                    ]
                                }
                            },
                            "libraries": {
                                "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/libraries",
                                "type": "array",
                                "items": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/library",
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/library/id",
                                            "minLength": 1,
                                            "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                                            "type": "string",
                                            "pattern": "^[0-9a-zA-Z -_]*$"
                                        },
                                        "name": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/library/name",
                                            "type": "string"
                                        },
                                        "compatible_versions": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/library/versions",
                                            "type": "array",
                                            "items": {
                                                "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/library/version",
                                                "type": "string"
                                            }
                                        },
                                        "link": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/library/link",
                                            "type": "string",
                                            "format": "uri",
                                            "pattern": "^(https?|ftp|file)://"
                                        }
                                    },
                                    "required": [
                                        "id",
                                        "name",
                                        "compatible_versions"
                                    ]
                                }
                            },
                            "interaction": {
                                "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/interactions",
                                "type": "array",
                                "items": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/interaction",
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/interaction/input-number",
                                            "minLength": 1,
                                            "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                                            "type": "string",
                                            "pattern": "^[0-9a-zA-Z -_]*$"
                                        },
                                        "name": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/interaction/name",
                                            "type": "string"
                                        },
                                        "notes": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/inputs/interaction/notes",
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "id",
                                        "name"
                                    ]
                                }
                            }
                        },
                        "required": [
                            "files"
                        ]
                    },
                    "outputs": {
                        "id": "https://github.com/pegasus-isi/craft-schema/stage/outputs",
                        "type": "object",
                        "properties": {
                            "files": {
                                "id": "https://github.com/pegasus-isi/craft-schema/stage/outputs/files",
                                "type": "array",
                                "items": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/outputs/file",
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/outputs/file/id",
                                            "minLength": 1,
                                            "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                                            "type": "string",
                                            "pattern": "^[0-9a-zA-Z -_]*$"
                                        },
                                        "report": {
                                            "id": "https://github.com/pegasus-isi/craft-schema/stage/outputs/file/report",
                                            "type": "boolean",
                                            "default": false
                                        }
                                    },
                                    "required": [
                                        "id",
                                        "report"
                                    ]
                                }
                            }
                        },
                        "required": [
                            "files"
                        ]
                    },
                    "flow-control": {
                        "id": "https://github.com/pegasus-isi/craft-schema/stage/controls",
                        "type": "array",
                        "items": {
                            "id": "https://github.com/pegasus-isi/craft-schema/stage/control",
                            "type": "object",
                            "properties": {
                                "id": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/control/id",
                                    "minLength": 1,
                                    "description": "A short, unique, informative identifier containing only alphanumeric characters and underscores.",
                                    "type": "string",
                                    "pattern": "^[0-9a-zA-Z -_]*$"
                                },
                                "condition": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/control/condition",
                                    "enum": [
                                        "Success",
                                        "Error"
                                    ]
                                },
                                "route-to": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/control/route-to",
                                    "type": "string"
                                },
                                "description": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/control/description",
                                    "type": "string"
                                },
                                "notes": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/control/notes",
                                    "type": "string"
                                },
                                "designer-guide": {
                                    "id": "https://github.com/pegasus-isi/craft-schema/stage/control/designer-guide",
                                    "type": "string"
                                }
                            },
                            "required": [
                                "id",
                                "condition",
                                "route-to",
                                "description"
                            ]
                        }
                    }
                },
                "required": [
                    "id",
                    "name",
                    "tool",
                    "inputs",
                    "outputs",
                    "flow-control"
                ]
            }
        }
    },
    "required": [
        "name",
        "tools",
        "stages"
    ]
}