Adding a New Correction Rule Type
Correction rules run before validation. They clean, normalize, and transform field values before business rules are applied.
Where Corrections Fitβ
Built-in Correction Typesβ
Stepsβ
1. Add the enum valueβ
In FileSpec.kt, add to CorrectionType:
enum class CorrectionType {
TRIM, PAD_LEFT, PAD_RIGHT, UPPER_CASE, LOWER_CASE, REGEX_REPLACE,
COERCE_DATE, DEFAULT_IF_NULL,
YOUR_NEW_TYPE // β add here
}
2. Add the when branch in CorrectionEngineβ
fun applyCorrection(value: Any?, rule: CorrectionRule, fieldSpec: FieldSpec): Any? {
return when (rule.correctionType) {
CorrectionType.TRIM -> (value as? String)?.trim()
// ... existing cases ...
CorrectionType.YOUR_NEW_TYPE -> {
// implement transformation
value
}
}
}
3. Write tests using ShouldSpecβ
class CorrectionEngineTest : ShouldSpec({
val engine = CorrectionEngine()
context("YOUR_NEW_TYPE correction") {
should("transform value correctly") {
val rule = CorrectionRule(
ruleId = "test",
field = "amount",
correctionType = CorrectionType.YOUR_NEW_TYPE
)
engine.applyCorrection("input", rule, fieldSpec) shouldBe "expected output"
}
}
})
./gradlew :platform-core:test
Correction Rule Execution Orderβ
Rules are applied in applyOrder β the order they appear in the correctionRules list in the spec.
Checklistβ
- New enum value added to
CorrectionType -
whenbranch added inCorrectionEngine.applyCorrection() -
ShouldSpectests added toCorrectionEngineTest -
AGENTS.mdΒ§6 updated