mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 18:35:17 +08:00
7bcfe60a76
Why this change? This change adds validation for the default value for `type: objects` theme settings when a setting theme field is uploaded. This helps the theme author to ensure that the objects which they specifc in the default value adhere to the schema which they have declared. When an error is encountered in one of the objects, the error message will look something like: `"The property at JSON Pointer '/0/title' must be at least 5 characters long."` We use a JSON Pointer to reference the property in the object which is something most json-schema validator uses as well. What does this change do? 1. This commit once again changes the shape of hash returned by `ThemeSettingsObjectValidator.validate`. Instead of using the property name as the key previously, we have decided to avoid multiple levels of nesting and instead use a JSON Pointer as the key which helps to simplify the implementation. 2 Introduces `ThemeSettingsObjectValidator.validate_objects` which returns an array of validation error messages for all the objects passed to the method.
49 lines
926 B
YAML
49 lines
926 B
YAML
no_match_setting:
|
|
type: bool
|
|
default: "string value"
|
|
|
|
no_default_setting:
|
|
type: string
|
|
|
|
invalid_type_setting:
|
|
type: listt
|
|
default: "name|age|last name"
|
|
|
|
default_out_of_range:
|
|
default: 100
|
|
min: 1
|
|
max: 20
|
|
|
|
string_default_out_of_range:
|
|
default: "abcdefg"
|
|
min: 20
|
|
|
|
invalid_default_objects_setting:
|
|
type: objects
|
|
default:
|
|
- min_5_chars_string: "12345"
|
|
children:
|
|
- required_integer: 1
|
|
- required_string: "some string"
|
|
min_5_chars_string: "123"
|
|
children:
|
|
- non_existent: "string"
|
|
schema:
|
|
name: parent
|
|
properties:
|
|
required_string:
|
|
type: string
|
|
required: true
|
|
min_5_chars_string:
|
|
type: string
|
|
validations:
|
|
min_length: 5
|
|
children:
|
|
type: objects
|
|
schema:
|
|
name: child
|
|
properties:
|
|
required_integer:
|
|
type: integer
|
|
required: true
|