Skip to main content

Form Schema

The form schema is used by an Action to generate a form that the user can fillout when requesting a new signal. The forms will be validated with the schema you define and will not let the user request the signal without a valididating all the requirements of the schema. SignalFire's Form schema is based on the AJV Schema format.

Common Schema Properties

These are some of the most commonly used properties and keywords for JSON schemas for AJV, to learn about more see AJV documenation. JSON schemas can become more complex as you define intricate validation rules for your data structures. The schema structure allows you to define powerful and flexible validation rules for your JSON data.

Types

Defines the JSON data type expected for the current schema. Common types include object, array, string, number, boolean, and null.

"type": "object"

Object Properties

Describes the expected properties and their respective schemas for an object.

"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
}

Number Minimum and Maximum

Sets the minimum and maximum numeric values allowed for a number.

"minimum": 0,
"maximum": 100

String Format

Provides additional constraints on string values, often used for common formats like dates, emails, and URIs. Learn about all formats?

"format": "email"

String Patterns

Defines a regular expression pattern that a string property must match.

"pattern": "^\\d{3}-\\d{2}-\\d{4}$"

Enums

Specifies an array of allowed values. The data must match one of the values in the array.

"enum": ["red", "green", "blue"]

Object Required

Lists the required properties for an object. It specifies which properties must be present in the validated data.

"required": ["name", "age"]

Object Dependencies

Describes dependencies between properties. It specifies which properties are required when certain other properties are present.

"dependencies": {
"required_property": ["dependent_property"]
}

Array Items

Defines the schema for elements within an array. It can be used to specify a schema for all elements in an array or a different schema for each element.

"items": { "type": "string" }

Examples

Example 1: Simple Object Schema

This schema defines a simple JSON object with two properties: "name" and "age." Both properties are required, and "age" must be a positive integer.

{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
},
"required": ["name", "age"]
}

Example 2: Enum Values Schema

This schema defines an object where the "color" property must have one of three allowed values: "red," "green," or "blue."

{
"type": "object",
"properties": {
"color": {
"type": "string",
"enum": ["red", "green", "blue"]
}
},
"required": ["color"]
}

Example 3: Schema with Dependencies

This schema defines an object where "property_a" and "property_b" are required. Additionally, if "property_a" is present, "property_c" must also be present.

{
"type": "object",
"properties": {
"property_a": { "type": "string" },
"property_b": { "type": "number" },
"property_c": { "type": "boolean" }
},
"required": ["property_a", "property_b"],
"dependencies": {
"property_a": ["property_c"]
}
}

Example 4: Conditional Properties

This schema defines an object with conditional properties. Depending on the "category" value, different properties are required. For example, if "category" is "book," then "author" and "pages" are required.

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"category": { "type": "string" },
"title": { "type": "string" },
"author": { "type": "string" },
"pages": { "type": "integer" }
},
"required": ["category", "title"],
"if": { "properties": { "category": { "const": "book" } } },
"then": { "required": ["author", "pages"] }
}