GFConfigValidationRule¶
API Reference / Standard / 类索引
- 路径:
addons/gf/standard/utilities/config/validation/gf_config_validation_rule.gd - 模块:
Standard - 继承:
Resource - API:
public - 类别:协议与扩展点 (
protocol) - 首次版本:
3.17.0
导表校验规则基类。 用于把字段、记录或整表校验拆成可组合 Resource,便于项目按需声明范围、 正则、资源路径或本地化 key 等规则,而不把业务表结构写进框架。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 枚举 | IssueSeverity |
enum IssueSeverity |
| 属性 | rule_id |
var rule_id: StringName = &"" |
| 属性 | enabled |
var enabled: bool = true |
| 属性 | severity |
var severity: IssueSeverity = IssueSeverity.ERROR |
| 属性 | allow_null |
var allow_null: bool = true |
| 属性 | metadata |
var metadata: Dictionary = {} |
| 方法 | get_rule_id |
func get_rule_id() -> StringName: |
| 方法 | validate_value |
func validate_value(value: Variant, context: Dictionary = {}) -> Dictionary: |
| 方法 | validate_record |
func validate_record(record: Dictionary, context: Dictionary = {}) -> Dictionary: |
| 方法 | validate_table |
func validate_table(rows: Array[Dictionary], context: Dictionary = {}) -> Dictionary: |
| 方法 | duplicate_rule |
func duplicate_rule() -> GFConfigValidationRule: |
| 方法 | describe |
func describe() -> Dictionary: |
| 方法 | _get_default_rule_id |
func _get_default_rule_id() -> StringName: |
| 方法 | _validate_value |
func _validate_value(_value: Variant, _context: Dictionary, _report: Dictionary) -> void: |
| 方法 | _validate_record |
func _validate_record(_record: Dictionary, _context: Dictionary, _report: Dictionary) -> void: |
| 方法 | _validate_table |
func _validate_table(_rows: Array[Dictionary], _context: Dictionary, _report: Dictionary) -> void: |
| 方法 | _add_issue |
func _add_issue(report: Dictionary, context: Dictionary, kind: String, message: String) -> void: |
| 方法 | _make_variant_key |
func _make_variant_key(value: Variant) -> String: |
枚举¶
IssueSeverity¶
- API:
public
校验问题严重级别。
属性¶
rule_id¶
- API:
public
规则稳定标识。为空时使用规则类型默认标识。
enabled¶
- API:
public
是否启用当前规则。
severity¶
- API:
public
规则触发时写入报告的严重级别。
allow_null¶
- API:
public
值为 null 时是否直接跳过值校验。
metadata¶
- API:
public
可选元数据,供编辑器或项目工具扩展使用。
结构:
metadata: Dictionary,保存编辑器或项目层附加到当前规则的元数据。
方法¶
get_rule_id¶
- API:
public
获取稳定规则标识。
返回:规则标识。
validate_value¶
- API:
public
校验单个字段值。
参数:
| 名称 | 说明 |
|---|---|
value |
待校验值。 |
context |
可选上下文,支持 table_name、row_key、field、source、line、column。 |
返回:校验报告字典。
结构:
value: Variant,来自配置表或项目导入器的字段值。context: Dictionary,可包含 table_name、row_key、field、source、line 和 column 字段。return: GFConfigValidationReport 兼容 Dictionary。
validate_record¶
- API:
public
校验单条记录。
参数:
| 名称 | 说明 |
|---|---|
record |
待校验记录。 |
context |
可选上下文,支持 table_name、row_key、source、line。 |
返回:校验报告字典。
结构:
record: Dictionary,正在校验的配置记录。context: Dictionary,可包含 table_name、row_key、source 和 line 字段。return: GFConfigValidationReport 兼容 Dictionary。
validate_table¶
- API:
public
校验整张表。
参数:
| 名称 | 说明 |
|---|---|
rows |
规范化行列表,每项通常包含 row_key、record 和 row_index。 |
context |
可选上下文,支持 table_name、source。 |
返回:校验报告字典。
结构:
rows: Array[Dictionary],元素通常包含 row_key、record 和 row_index。context: Dictionary,可包含 table_name 和 source 字段。return: GFConfigValidationReport 兼容 Dictionary。
duplicate_rule¶
- API:
public
创建同内容拷贝。
返回:新规则。
describe¶
- API:
public
导出规则摘要。
返回:规则摘要字典。
结构:
return: Dictionary,包含 rule_id、enabled、severity、allow_null、metadata 和 script_path。
_get_default_rule_id¶
- API:
protected
返回当前规则的默认稳定标识。
返回:默认规则标识。
_validate_value¶
- API:
protected
校验单个字段值。
参数:
| 名称 | 说明 |
|---|---|
_value |
待校验值。 |
_context |
校验上下文。 |
_report |
当前校验报告。 |
结构:
_value: Variant,来自配置表或项目导入器的字段值。_context: Dictionary,可包含 table_name、row_key、field、source、line 和 column 字段。_report: GFConfigValidationReport 兼容 Dictionary,会被规则修改。
_validate_record¶
- API:
protected
校验单条记录。
参数:
| 名称 | 说明 |
|---|---|
_record |
待校验记录。 |
_context |
校验上下文。 |
_report |
当前校验报告。 |
结构:
_record: Dictionary,正在校验的配置记录。_context: Dictionary,可包含 table_name、row_key、source 和 line 字段。_report: GFConfigValidationReport 兼容 Dictionary,会被规则修改。
_validate_table¶
- API:
protected
校验整张表。
参数:
| 名称 | 说明 |
|---|---|
_rows |
规范化行列表。 |
_context |
校验上下文。 |
_report |
当前校验报告。 |
结构:
_rows: Array[Dictionary],元素通常包含 row_key、record 和 row_index。_context: Dictionary,可包含 table_name 和 source 字段。_report: GFConfigValidationReport 兼容 Dictionary,会被规则修改。
_add_issue¶
- API:
protected
向当前报告追加一个带规则上下文的问题。
参数:
| 名称 | 说明 |
|---|---|
report |
当前校验报告。 |
context |
校验上下文。 |
kind |
稳定问题类型。 |
message |
面向工具或开发者的说明文本。 |
结构:
report: GFConfigValidationReport 兼容 Dictionary,会被当前辅助方法修改。context: Dictionary,可包含 table_name、row_key、field、source、line 和 column 字段。
_make_variant_key¶
- API:
protected
生成可比较的 Variant 稳定字符串键。
参数:
| 名称 | 说明 |
|---|---|
value |
要转换为比较键的值。 |
返回:包含 Variant 类型和值文本的比较键。
结构:
value: Variant,用于集合或默认值校验规则比较的值。