diff --git a/schema/events.json b/schema/events.json index ca98dcdd..66ee65d5 100644 --- a/schema/events.json +++ b/schema/events.json @@ -3,15 +3,19 @@ "$schema": "http://json-schema.org/draft-07/schema#", "description": "Serverless Workflow specification - events schema", "type": "object", - "definitions": { - "events": { - "type": "array", - "description": "Workflow CloudEvent definitions. Defines CloudEvents that can be consumed or produced", - "items": { - "type": "object", - "$ref": "#/definitions/eventdef" - } + "events": { + "type": "array", + "description": "Workflow CloudEvent definitions. Defines CloudEvents that can be consumed or produced", + "items": { + "type": "object", + "$ref": "#/definitions/eventdef" }, + "minItems": 1 + }, + "required": [ + "events" + ], + "definitions": { "eventdef": { "type": "object", "properties": { diff --git a/schema/functions.json b/schema/functions.json index ee107c57..70680f49 100644 --- a/schema/functions.json +++ b/schema/functions.json @@ -3,16 +3,19 @@ "$schema": "http://json-schema.org/draft-07/schema#", "description": "Serverless Workflow specification - functions schema", "type": "object", - "definitions": { - "functions": { - "type": "array", - "description": "Workflow function definitions", - "items": { - "type": "object", - "$ref": "#/definitions/function" - }, - "minLength": 1 + "functions": { + "type": "array", + "description": "Workflow function definitions", + "items": { + "type": "object", + "$ref": "#/definitions/function" }, + "minItems": 1 + }, + "required": [ + "functions" + ], + "definitions": { "function": { "type": "object", "properties": { diff --git a/schema/workflow.json b/schema/workflow.json index 5f81f83d..6a931a91 100644 --- a/schema/workflow.json +++ b/schema/workflow.json @@ -3,96 +3,196 @@ "$schema": "http://json-schema.org/draft-07/schema#", "description": "Serverless Workflow specification - workflow schema", "type": "object", - "properties": { - "id": { - "type": "string", - "description": "Workflow unique identifier", - "minLength": 1 - }, - "name": { - "type": "string", - "description": "Workflow name", - "minLength": 1 - }, - "description": { - "type": "string", - "description": "Workflow description" - }, - "version": { - "type": "string", - "description": "Workflow version", - "minLength": 1 - }, - "schemaVersion": { - "type": "string", - "description": "Serverless Workflow schema version", - "minLength": 1 - }, - "dataInputSchema": { - "type": "string", - "format": "uri", - "description": "URI to JSON Schema that workflow data input adheres to" - }, - "dataOutputSchema": { - "type": "string", - "format": "uri", - "description": "URI to JSON Schema that workflow data output adheres to" - }, - "metadata": { - "$ref": "common.json#/definitions/metadata" - }, - "events": { - "$ref": "events.json#/definitions/events" - }, - "functions": { - "$ref": "functions.json#/definitions/functions" - }, - "states": { - "type": "array", - "description": "State definitions", - "items": { - "anyOf": [ - { - "title": "Delay State", - "$ref": "#/definitions/delaystate" - }, - { - "title": "Event State", - "$ref": "#/definitions/eventstate" - }, - { - "title": "Operation State", - "$ref": "#/definitions/operationstate" - }, - { - "title": "Parallel State", - "$ref": "#/definitions/parallelstate" - }, - { - "title": "Switch State", - "$ref": "#/definitions/switchstate" - }, - { - "title": "SubFlow State", - "$ref": "#/definitions/subflowstate" - }, - { - "title": "Inject State", - "$ref": "#/definitions/injectstate" + "oneOf": [ + { + "properties": { + "id": { + "type": "string", + "description": "Workflow unique identifier", + "minLength": 1 + }, + "name": { + "type": "string", + "description": "Workflow name", + "minLength": 1 + }, + "description": { + "type": "string", + "description": "Workflow description" + }, + "version": { + "type": "string", + "description": "Workflow version", + "minLength": 1 + }, + "schemaVersion": { + "type": "string", + "description": "Serverless Workflow schema version", + "minLength": 1 + }, + "dataInputSchema": { + "type": "string", + "format": "uri", + "description": "URI to JSON Schema that workflow data input adheres to" + }, + "dataOutputSchema": { + "type": "string", + "format": "uri", + "description": "URI to JSON Schema that workflow data output adheres to" + }, + "metadata": { + "$ref": "common.json#/definitions/metadata" + }, + "events": { + "$ref": "events.json#/events" + }, + "functions": { + "$ref": "functions.json#/functions" + }, + "states": { + "type": "array", + "description": "State definitions", + "items": { + "anyOf": [ + { + "title": "Delay State", + "$ref": "#/definitions/delaystate" + }, + { + "title": "Event State", + "$ref": "#/definitions/eventstate" + }, + { + "title": "Operation State", + "$ref": "#/definitions/operationstate" + }, + { + "title": "Parallel State", + "$ref": "#/definitions/parallelstate" + }, + { + "title": "Switch State", + "$ref": "#/definitions/switchstate" + }, + { + "title": "SubFlow State", + "$ref": "#/definitions/subflowstate" + }, + { + "title": "Inject State", + "$ref": "#/definitions/injectstate" + }, + { + "title": "ForEach State", + "$ref": "#/definitions/foreachstate" + }, + { + "title": "Callback State", + "$ref": "#/definitions/callbackstate" + } + ] }, - { - "title": "ForEach State", - "$ref": "#/definitions/foreachstate" + "minItems": 1 + } + } + }, + { + "properties": { + "id": { + "type": "string", + "description": "Workflow unique identifier", + "minLength": 1 + }, + "name": { + "type": "string", + "description": "Workflow name", + "minLength": 1 + }, + "description": { + "type": "string", + "description": "Workflow description" + }, + "version": { + "type": "string", + "description": "Workflow version", + "minLength": 1 + }, + "schemaVersion": { + "type": "string", + "description": "Serverless Workflow schema version", + "minLength": 1 + }, + "dataInputSchema": { + "type": "string", + "format": "uri", + "description": "URI to JSON Schema that workflow data input adheres to" + }, + "dataOutputSchema": { + "type": "string", + "format": "uri", + "description": "URI to JSON Schema that workflow data output adheres to" + }, + "metadata": { + "$ref": "common.json#/definitions/metadata" + }, + "events": { + "type": "string", + "format": "uri", + "description": "URI to a resource containing event definitions (json or yaml)" + }, + "functions": { + "type": "string", + "format": "uri", + "description": "URI to a resource containing function definitions (json or yaml)" + }, + "states": { + "type": "array", + "description": "State definitions", + "items": { + "anyOf": [ + { + "title": "Delay State", + "$ref": "#/definitions/delaystate" + }, + { + "title": "Event State", + "$ref": "#/definitions/eventstate" + }, + { + "title": "Operation State", + "$ref": "#/definitions/operationstate" + }, + { + "title": "Parallel State", + "$ref": "#/definitions/parallelstate" + }, + { + "title": "Switch State", + "$ref": "#/definitions/switchstate" + }, + { + "title": "SubFlow State", + "$ref": "#/definitions/subflowstate" + }, + { + "title": "Inject State", + "$ref": "#/definitions/injectstate" + }, + { + "title": "ForEach State", + "$ref": "#/definitions/foreachstate" + }, + { + "title": "Callback State", + "$ref": "#/definitions/callbackstate" + } + ] }, - { - "title": "Callback State", - "$ref": "#/definitions/callbackstate" - } - ] - }, - "minLength": 1 + "minItems": 1 + } + } } - }, + ], "required": [ "id", "name", @@ -1756,4 +1856,4 @@ "required": [] } } -} +} \ No newline at end of file diff --git a/specification.md b/specification.md index f67515cf..68b4da29 100644 --- a/specification.md +++ b/specification.md @@ -84,13 +84,12 @@ Following sections provide a detailed descriptions of all parts of the workflow The Serverless Workflow model is composed of: * Set of [functions](#Function-Definition) (services) that need to be `invoked` during workflow execution. -* Set of [events](#Event-Definition) that need to be `consumed` to start workflow instances, trigger functions, or be `produced` during workflow execution. +* Set of [events](#Event-Definition) that need to be `consumed` to start or continue workflow instances, trigger function/service execution, or be `produced` during workflow execution. * Set of [states](#State-Definition) and [transitions](#Transitions) between them. States define the workflow `control flow logic`, manage workflow data, and can reference defined functions and events. Transitions connect workflow states. -The defined workflow model is a declarative language that can be used to model small or complex orchestrations +Workflow model defines a declarative language that can be used to model simple or complex orchestrations for event-driven, serverless applications. -to start workflow instances or trigger functions, ### Workflow Data @@ -246,8 +245,8 @@ which would set the workflow version to `1.0.0`. | schemaVersion | Workflow schema version | string | no | | [dataInputSchema](#Workflow-Data-Input) | URI to JSON Schema that workflow data input adheres to | string | no | | [dataOutputSchema](#Workflow-data-output) | URI to JSON Schema that workflow data output adheres to | string | no | -| [events](#Event-Definition) | Workflow event definitions. Defines events that can be consumed or produced | array | no | -| [functions](#Function-Definition) | Workflow function definitions | array | no | +| [events](#Event-Definition) | Workflow event definitions. | array or string | no | +| [functions](#Function-Definition) | Workflow function definitions. Can be either inline function definitions (if array) or URI pointing to a resource containing json/yaml function definitions (if string) | array or string| no | | [states](#State-Definition) | Workflow states | array | yes | | [metadata](#Workflow-Metadata) | Metadata information| object | no | @@ -300,6 +299,79 @@ Following figure describes the main workflow definition blocks. Serverless Workflow Definitions Blocks

+The `functions` property can be either an in-line [function](#Function-Definition) definition array, or an URI reference to +a resource containing an array [functions](#Function-Definition) definition. +Referenced resource can be used by multiple workflow definitions. + +Here is an example of using external resource for function definitions: + +1. Workflow definition: +```json +{ + "id": "sampleWorkflow", + "version": "1.0", + "name": "Sample Workflow", + "description": "Sample Workflow", + "functions": "http://myhost:8080/functiondefs.json", + "states":[ + ... + ] +} +``` + +2. Function definitions resource +```json +{ + "functions": [ + { + "name":"HelloWorldFunction", + "resource":"https://hellworldservice.test.com:8443/api/hellofunction" + } + ] +} +``` + +Referenced resource must conform to the specifications [Workflow Functions JSON Schema](schema/functions.json). + +The `events` property can be either an in-line [event](#Event-Definition) definition array, or an [URI](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier) reference to +a resource containing an array of [event](#Event-Definition) definition. Referenced resource can be used by multiple workflow definitions. + +Here is an example of using external resource for event definitions: + +1. Workflow definition: +```json +{ + "id": "sampleWorkflow", + "version": "1.0", + "name": "Sample Workflow", + "description": "Sample Workflow", + "events": "http://myhost:8080/eventsdefs.json", + "states":[ + ... + ] +} +``` + +2. Event definitions resource +```json +{ + "events": [ + { + "name": "ApplicantInfo", + "type": "org.application.info", + "source": "applicationssource", + "correlation": [ + { + "contextAttributeName": "applicantId" + } + ] + } + ] +} +``` + +Referenced resource must conform to the specifications [Workflow Events JSON Schema](schema/events.json). + #### Function Definition | Parameter | Description | Type | Required | @@ -324,7 +396,6 @@ Following figure describes the main workflow definition blocks. { "name": "HelloWorldFunction", "resource": "https://hellworldservice.test.com:8443/api/hellofunction", - "type": "REST", "metadata": { "authToken": "{{ $.token }}" } @@ -337,7 +408,6 @@ Following figure describes the main workflow definition blocks. ```yaml name: HelloWorldFunction resource: https://hellworldservice.test.com:8443/api/hellofunction -type: REST metadata: authToken: "{{ $.token }}" ```