Schema Protection for JSON Configuration Content
Schema protection allows you to define a JSON schema for a particular configuration. Schema protection is a great way to ensure that the content of your configurations are always valid. This is especially useful when you have multiple team members working on the same configurations. Schema protection will prevent invalid configurations from being saved.
What You Can Do With Schema Protection
- Prevent missing values
- Ensure values are of the correct type
- Ensure number values are within a certain range
- Ensure values are in a particular format
- Constrain strings to certain lengths and/or values
Refer to the JSON Schema Validation documentation for information on the exact syntax to validate for different types of values.
Using Schema Protection
Setting up Schema Protection for Remote Configuration Content
You can access the schema panel from the configuration editor. Click "Add Schema" to get started.
You will see the option to attach an existing schema or create a new one. Click "Create New Schema".
You can then define your schema to use for validating your config.
Hint
You can quickly generate a basic JSON schema for any existing JSON configuration by using our Developer Tools.
Using Schema Protection
Once you have activated schema protection, you will see "Validation Active" on the right panel.
When editing a configuration, you will get feedback in the editor on whether your configuration is valid or not. Invalid values will be indicated with a brown underline.
Refer to the JSON Schema Validation documentation for more information on the validation options available.
Sample Schema
{
"myNumber": 10,
"myBoolean": true,
"myColor": "red",
"myArray": [
"one",
"two",
"three"
],
"myObject": {}
}
{
"type": "object",
"properties": {
"myNumber": {
// only allow integer values between 0 and 100 inclusive
"type": "integer",
"minimum": 0,
"maximum": 100
},
"myBoolean": {
// must be a boolean value
"type": "boolean"
},
"myColor": {
"type": "string",
"enum": [ // allow for only these values specified in enum
"red",
"green",
"blue"
]
},
"myArray": {
"type": "array",
"minItems": 2, // array must have at least 1 item
"items": {
"type": "string" // array items must be strings
}
},
"myObject": {
"type": "object"
}
},
// require myNumber and myBoolean to be present. Other properties are optional.
"required": ["myNumber", "myBoolean"]
}
Saving an Invalid Configuration
When you save a configuration that has schema protection activated, we will validate the contents against the schema. If the configuration is invalid, it will not be saved.
Schema Manager
We have a Schema Manager where you can manage all of the schemas in a particular Product.
- Schemas can be attached to multiple configurations.
- Schema relationships are persisted when syncing configurations across environments.