31 lines
862 B
Go
31 lines
862 B
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// ValidateOutputContract validates source-neutral output-contract invariants.
|
|
func ValidateOutputContract(contract OutputContract) error {
|
|
switch contract.Format {
|
|
case FormatText, FormatMarkdown, FormatJSON:
|
|
default:
|
|
return fmt.Errorf("invalid output format: %q", contract.Format)
|
|
}
|
|
|
|
switch contract.ValidationMode {
|
|
case ValidationNone, ValidationBasic, ValidationJSON, ValidationJSONSchema:
|
|
default:
|
|
return fmt.Errorf("invalid validation mode: %q", contract.ValidationMode)
|
|
}
|
|
|
|
if contract.ValidationMode == ValidationJSONSchema && strings.TrimSpace(contract.SchemaPath) == "" {
|
|
return errors.New("schema_path is required when validation_mode is json_schema")
|
|
}
|
|
if contract.RepairAttempts < 0 {
|
|
return errors.New("repair_attempts must be greater than or equal to 0")
|
|
}
|
|
return nil
|
|
}
|