Package cloud.opencode.base.config.validation
package cloud.opencode.base.config.validation
Configuration Validation Package
配置验证包
This package provides configuration validation capabilities for ensuring configuration values meet specified requirements.
此包提供配置验证能力,确保配置值满足指定要求。
Features | 主要功能:
- Required field validation - 必填字段验证
- Range validation - 范围验证
- Pattern validation - 模式验证
- Custom validator support - 自定义验证器支持
- Validation result aggregation - 验证结果聚合
Components | 组件:
ConfigValidator- Validator interface (SPI) - 验证器接口RequiredValidator- Required field validator - 必填验证器ValidationResult- Validation result - 验证结果
Usage Examples | 使用示例:
// Add validation during build
Config config = OpenConfig.builder()
.addClasspathResource("application.properties")
.required("database.url", "database.username", "database.password")
.addValidator(new RangeValidator("server.port", 1024, 65535))
.build();
// Custom validator
public class PortValidator implements ConfigValidator {
@Override
public ValidationResult validate(Config config) {
int port = config.getInt("server.port", 8080);
if (port < 1024 || port > 65535) {
return ValidationResult.failure("Port must be between 1024 and 65535");
}
return ValidationResult.success();
}
}
Validation Failure Behavior | 验证失败行为:
When validation fails during ConfigBuilder.build(), an
OpenConfigException is thrown with
aggregated error messages.
当在ConfigBuilder.build()期间验证失败时,将抛出
OpenConfigException,包含聚合的错误消息。
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
ClassDescriptionConfiguration Validator Interface 配置验证器接口Pattern Validator - Validates configuration values match specified regex pattern 模式验证器 - 验证配置值匹配指定的正则表达式模式Range Validator - Validates numeric configuration values are within specified range 范围验证器 - 验证数字配置值在指定范围内Required Keys Validator 必填键验证器Validation Module Adapter with Optional Validation Module Delegation 支持可选 Validation 模块委托的验证适配器Configuration Validation Result 配置验证结果