Setting Schema
Author:
Christopher Tse
Changed on:
16 Oct 2024
Overview
The Setting Schema is a JSON schema used by the Settings Component to provide metadata for a setting, helping to define its structure. This schema primarily describes the fields that the component will render, allowing for a no-code configuration experience within the Fluent platform.
Key points
- The Setting Schema is defined using JSON schema standards.
- It describes the structure of a setting rather than validating the content of a JSON file.
- Only a subset of JSON schema keywords is utilized to define the structure.
Supported Field Types
Fields
The schema allows for various field types to be defined:
Type | Field |
String | Textfield |
Boolean | Switcher |
Number/Integer | Quantity Selector |
Array | Subform |
Object | Subform |
Keywords and Functionality
Title
The title keyword can be placed in a field to give it a title.
Required
See: https://json-schema.org/understanding-json-schema/reference/object#required
The required keyword can be used to mark which fields in an object are required.
This will be read by the settings component, and it will not allow the user to submit until all required fields have a value.
Enum
See: https://json-schema.org/understanding-json-schema/reference/enum
The enum keyword can be used to specify that a property or field can only have a limited pool of values. When the enum keyword is used, we expect an array of values that the property can take.
Currently, this is only supported for the string type.
When the enum property is specified, then the UI will switch to using a dropdown or radio input. If there are 3 or less options, then the radio input is used to select the option. Otherwise, a dropdown will be displayed instead.
1{
2 "$schema": "http://json-schema.org/draft-04/schema#",
3 "type": "object",
4 "properties": {
5 "letter": {
6 "title": "A letter",
7 "type": "string",
8 "enum": [
9 "A",
10 "B",
11 "C"
12 ]
13 }
14 }
15}
Language: json
Name: Schema with Enum
Description:
[Warning: empty required content area]fcField
The
`fcField`
Extensions
The properties of each field will be passed to the field through the extensions prop. This allows you to extend the schema with your own props as needed. See the how-to guide for an example.
Default
The
`default`
The value must be the same type as the field in question. Defaults are supported for all types, including objects and arrays. You can specify default values for arrays and objects in the same manner as primitives. However, the default value should adhere to the same structure as it would if defined in the setting.
Additionally, defaults also work for array items. Defaults for an array item's properties will be used for new items, as well as exisiting items that don't have that property in the setting.
Not Supported Keywords
All validation keywords are currently not supported.
Samples
Here are a few examples of schemas and what they represent
Simple Object with One Boolean Value
1{
2 "$schema": "http://json-schema.org/draft-04/schema#",
3 "type": "object",
4 "properties": {
5 "enableFeature": {
6 "title": "Turn on Feature X",
7 "type": "boolean"
8 }
9 }
10}
Language: json
Name: Schema
Description:
[Warning: empty required content area]Simple Object with Multiple Fields
1{
2 "$schema": "http://json-schema.org/draft-04/schema#",
3 "type": "object",
4 "properties": {
5 "enableNotifications": {
6 "title": "Enable order notifications",
7 "type": "boolean"
8 },
9 "maxNotifications": {
10 "title": "Maximum number of notifications to send per day",
11 "type": "integer"
12 },
13 "notificationMessage": {
14 "title": "Notification Message",
15 "type": "An order has been processed."
16 },
17 }
18}
Language: json
Name: Schema Sample
Description:
[Warning: empty required content area]Array of Objects with Two Strings
1{
2 "$schema": "http://json-schema.org/draft-07/schema#",
3 "title": "Return Reasons",
4 "type": "array",
5 "items": {
6 "title": "This is a list of reasons that a store assistant may select when processing a return order. The label is the human readable string displayed in the dropdown menu and the value is the value sent to the orchestration engine when this option is selected.",
7 "type": "object",
8 "properties": {
9 "label": {
10 "title": "label",
11 "type": "string"
12 },
13 "value": {
14 "title": "Value",
15 "type": "string"
16 }
17 }
18 }
19}
Language: plain_text
Name: Schema Sample
Description:
Warning: this component only supports "items" as an schema object, array is not supported.
Scenarios where the component will not render (check the browser console for error messages):
- When context or contextId specified is invalid
- When schema or setting response has error
- When schema top level type does not match setting type
- JSON - The schema type can be anything
- Integer - The schema’s top level property must be an Integer or Number type
- Boolean - The schema’s top level property must be an Boolean type
- String - The schema’s top level property must be a String type