| description | Simplified version of JSON Schema |
|---|
In a scenario, the variables, process result, and actors are defined using JSON Schema. JSON Schema is a standard for defining the structure, format, and validation rules of JSON data.
To simplify usage, LetsFlow supports both standard and simplified schemas.
{% tabs %} {% tab title="YAML" %}
vars:
message: string
contract:
properties:
id: !format uri
name: !required string
date: !format date-time
signed: !default false
books:
items:
properties:
id: !format uuid
title: string
isbn: !pattern: "^\\d{13}$"{% endtab %}
{% tab title="JSON" %}
{
"vars": {
"message": "string",
"contract": {
"properties": {
"id": {
"type": "string",
"format": "uri"
},
"name": {
"type": "string",
"required": true
},
"date": {
"type": "string",
"format": "date-time"
},
"signed": {
"type": "boolean",
"default": false
}
}
},
"books": {
"items": {
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"title": "string",
"isbn": {
"type": "string",
"pattern": "^\\d{13}$"
}
}
}
}
}
}{% endtab %} {% endtabs %}
For more information about JSON Schema, please visit:
{% embed url="https://json-schema.org/" %}
https://schemas.letsflow.io/v1.0/schema
Simplified schemas are converted into their full JSON Schema equivalent before use. This is done when a scenario or a standalone schema is normalized.
Simplified schemas supersede full JSON Schema, thus any valid JSON Schema is also a valid LetsFlow schema.
Basic types like string, number, or boolean can be specified directly without wrapping in a type field.
name: string
age: integernormalizes to
name:
type: string
age:
type: integerIn JSON Schema, you can reference an external schema or subsection of the current schema using $ref.
In LetsFlow's simplified schema, references can be written directly as strings. Any string starting with http://, https://, or # is seen as a reference, rather than a type.
client: https://schema.example.com/actors/clientnormalizes to
client:
$ref: https://schema.example.com/actors/clientYAML tags in LetsFlow provide a concise way to define additional metadata or constraints in your schema.
These tags are not available when defining a schema in JSON.
Defines a constant value:
status: !const "active"Defines an enumerated set of values:
role: !enum ["admin", "user", "guest"]The type is determined based on the values of the enum.
Specifies a data format:
email: !format emailThe type is always set to string.
Defines a regular expression for validation:
phone: !pattern "^\\+?[0-9]{10,15}$"The type is always set to string.
Provides a default value:
enabled: !default trueThe type is determined based on the default value.
!required
Marks a property as required:
properties:
name: !required string
age: !required
type: integer
minimum: 16
maximum: 120The !required tag should only be used on properties, as the property is automatically appended to the required field of the parent object.
If type is omitted, it may be automatically determined based on the structure:
- The presence of
propertiesimplies an object. - The presence of
itemsimplies an array. - For
constorenumthe type is determined based on the const or enum value.
Properties that aren't defined don't exist and can't be set unless additionalProperties is set in the definition.
In other words; additionalProperties defaults to false in contrary to the default behavior of JSON Schema.
{% hint style="warning" %} For schema files; LetsFlow assumes that schemas are immutable to be deterministic. It's highly recommended that the URI of the schema ID includes a version number. Modifying a published schema can lead to unexpected behavior. {% endhint %}