You can now validate your inputs before running workflows with input schemas.

Users will be allowed to save the JSON schema, just like they are allowed to save the OpenAPI, Swagger, and Async API schema and can then refer to the saved JSON schema in the workflow, using which the payload can be validated. Workflow authors can refer a JSON schema defined for payload in their workflow and users running the workflow can validate their input payload against the saved schema.

Referencing JSON schema in workflow

Serverless workflow spec specifies dataInputSchema to define a schema within the workflow that can be used to validate the input payload with the JSON schema. dataInputSchema defines the schema in two ways:
  • Object
    "dataInputSchema": {
        "schema": "URL to json schema",
        "failOnValidationErrors": false
    }
  • String
    "dataInputSchema": "URL to json schema"

In both the cases, schema property is an URI which points to the JSON schema and failOnValidationErrors property determines if workflow execution should continue in case of validation errors. If dataInputSchema has the string type, the failOnValidationErrors property is assumed to be true.

Example of JSON schema:

Schema Path: /session_schema

Schema:
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "tca": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "password": {
      "type": "string"
    }
  },
  "required": [
    "tca",
    "username",
    "password"
  ]
}
Workflow Hub allows only DB references to refer to the schema in the workflow, i.e., users can save the schema and refer to those in the workflows in the following way:
id: create-tca-session
name: Create TCA Session
version: 0.1.0
description: Workflow to create session
specVersion: 0.7.0
start: Get_TCA_Session
 
functions:
  - name: createTCASession
    operation: https://{tca}/hybridity/docs/apis/tca_platform/platform.json#/paths/~1hybridity~1api~1sessions/post
    metadata:
      tlsVerify: false
      includeResponseHeaders: x-hm-authorization
 
dataInputSchema:
  schema: db://session_schema
  failOnValidationErrors: true
 
states:
 
  - name: Get_TCA_Session
    type: operation
    actions:
      - functionRef:
          refName: createTCASession
          arguments:
            tca: "${ .tca }"
            username: "${ .username }"
            password: "${ .password }"
            Content-Type: application/json
        actionDataFilter:
          results: '${ {"x-hm-authorization"} }'
    end: true

Validating workflow payload against JSON schema

In workflow execution pop-up, VALIDATE PAYLOAD option is provided along with CANCEL and RUN. Users can click on VALIDATE PAYLOAD, to validate the input payload against the saved schema. This option will be disabled for the workflows for which no payload schema is defined.

When a user executes a workflow that has a schema defined, payload validation will be performed automatically against the schema. When the workflow does not have an input schema defined, a warning will be shown. However, the user can still run the workflow.

Referring saved JSON schemas in a JSON Schema

In case, users want to write the schema of Management Cluster Creation workflow which requires session creation, users can refer the session schema in following way:
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "tca": {
      "type": "string"
    },
    "username": {
      "type": "string"
    },
    "password": {
      "type": "string"
    }
  },
  "required": [
    "tca",
    "username",
    "password"
  ]
}
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "session": {
      "$ref": "db://session_schema"
    },
    "managementCluster": {
      "type": "object"
    }
  },
  "required": [
    "session",
    "managementCluster"
  ]
}