Reuse document indexes in D&D validators
This commit is contained in:
@@ -37,7 +37,7 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
if err := combatshape.Validate(req.Value); err != nil {
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
issues := sourceRefIssues(req.Source, req.Value)
|
||||
issues := sourceRefIssues(source.NewDocumentIndex(req.Source), req.Value)
|
||||
if len(issues) == 0 {
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
@@ -48,11 +48,11 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
}, nil
|
||||
}
|
||||
|
||||
func sourceRefIssues(doc *source.SourceDocument, value dnd.CombatTurnList) []string {
|
||||
func sourceRefIssues(index source.DocumentIndex, value dnd.CombatTurnList) []string {
|
||||
issues := make([]string, 0)
|
||||
for turnIndex, turn := range value.CombatTurns {
|
||||
for refIndex, ref := range turn.SourceRefs {
|
||||
if err := source.ValidateRef(doc, ref); err != nil {
|
||||
if err := index.ValidateRef(ref); err != nil {
|
||||
issues = append(issues, fmt.Sprintf("combat_turns[%d].source_refs[%d]: %s", turnIndex, refIndex, diagnostics.Truncate(err.Error())))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user