Forms Bridge utilizes JSON Schemas to describe settings and perform data validations.
An example of this use is the Workflow Jobs registration. This is the schema of a workflow job setting data:
{
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"method": {
"type": "string"
},
"input": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"required": {
"type": "boolean"
},
"schema": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"string",
"integer",
"number",
"array",
"object",
"boolean",
"null"
]
},
"items": {
"type": [
"array",
"object"
],
"additionalProperties": true,
"additionalItems": true
},
"properties": {
"type": "object",
"additionalProperties": true
},
"maxItems": {
"type": "integer"
},
"minItems": {
"type": "integer"
},
"additionalProperties": {
"type": "boolean"
},
"additionalItems": {
"type": "boolean"
},
"required": {
"type": "array",
"items": {
"type": "string"
},
"additionalItems": true
}
},
"required": [
"type"
],
"additionalProperties": false
}
},
"required": [
"name",
"schema"
],
"additionalProperties": false
}
},
"output": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"touch": {
"type": "boolean"
},
"forward": {
"type": "boolean"
},
"schema": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"string",
"integer",
"number",
"array",
"object",
"boolean",
"null"
]
},
"items": {
"type": [
"array",
"object"
],
"additionalItems": true
},
"properties": {
"type": "object",
"additionalProperties": true
},
"maxItems": {
"type": "integer"
},
"minItems": {
"type": "integer"
},
"additionalProperties": {
"type": "boolean"
},
"additionalItems": {
"type": "boolean"
}
},
"required": [
"type"
],
"additionalProperties": false
}
},
"required": [
"name",
"schema"
],
"additionalProperties": false
}
},
"callbacks": {
"type": "object",
"properties": {
"before": {
"type": "string"
},
"after": {
"type": "string"
}
},
"additionalProperties": false
}
}
And this is an example of a valid workflow job setting data:
{
"title": "Contact ID",
"description": "Creates a new contact and sets its ID as the contactId field of the payload",
"method": "forms_bridge_holded_contact_id",
"input": [
{
"name": "name",
"schema": {
"type": "string"
},
"required": true
},
{
"name": "tradeName",
"schema": {
"type": "string"
}
},
{
"name": "email",
"schema": {
"type": "string"
}
},
{
"name": "mobile",
"schema": {
"type": "string"
}
},
{
"name": "phone",
"schema": {
"type": "string"
}
},
{
"name": "type",
"schema": {
"type": "string"
}
},
{
"name": "code",
"schema": {
"type": "string"
}
},
{
"name": "vatnumber",
"schema": {
"type": "string"
}
},
{
"name": "iban",
"schema": {
"type": "string"
}
},
{
"name": "swift",
"schema": {
"type": "string"
}
},
{
"name": "billAddress",
"schema": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"postalCode": {
"type": "string"
},
"city": {
"type": "string"
},
"countryCode": {
"type": "string"
}
},
"additionalProperties": true
}
},
{
"name": "defaults",
"schema": {
"type": "object",
"properties": {
"language": {
"type": "string"
}
},
"additionalProperties": true
}
},
{
"name": "tags",
"schema": {
"type": "array",
"items": {
"type": "string"
},
"additionalItems": true
}
},
{
"name": "note",
"schema": {
"type": "string"
}
},
{
"name": "isperson",
"schema": {
"type": "integer"
}
},
{
"name": "contactPersons",
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"phone": {
"type": "string"
}
},
"additionalProperties": false
}
}
}
],
"output": [
{
"name": "contactId",
"schema": {
"type": "string"
}
}
]
}
To validate this settings on registration time Forms Bridge utilizes the JSON Schema validation API included with the REST API package of WordPress. In addition to the validation of the schema, Forms Bridge checks that the method
value exists as a function on the global scope, same as callbacks
. The same check is performed for callback functions if they are declared. If the workflow job does not pass the validation, it will be skipped from registration.