Resolve collection identity during strict composition

This commit is contained in:
2026-10-23 18:39:04 +00:00
parent 628fc53d2c
commit d03e56398b
5 changed files with 319 additions and 116 deletions

View File

@@ -214,6 +214,10 @@ func (index sequenceMappingIndex) identity(fields []string) (string, []document.
// validateSequenceIdentity checks mapping shape, direct identity fields, and
// uniqueness in one tuple-to-first-location index. It does not alter the nodes.
func validateSequenceIdentity(sequence *document.Node, path Path, fields []string, codes sequenceIdentityDiagnosticCodes) (map[string]sequenceIdentityRecord, []Diagnostic) {
return validateSequenceIdentityFrom(sequence, path, fields, codes, 0)
}
func validateSequenceIdentityFrom(sequence *document.Node, path Path, fields []string, codes sequenceIdentityDiagnosticCodes, startIndex int) (map[string]sequenceIdentityRecord, []Diagnostic) {
normalized, err := normalizeSequenceIdentityFields(fields)
if err != nil {
location := (*Location)(nil)
@@ -223,6 +227,10 @@ func validateSequenceIdentity(sequence *document.Node, path Path, fields []strin
}
return nil, []Diagnostic{{Code: codes.invalid, Severity: SeverityError, Path: path, Message: "sequence identity requires at least one field", Primary: location}}
}
return validateNormalizedSequenceIdentityFrom(sequence, path, normalized, codes, startIndex)
}
func validateNormalizedSequenceIdentityFrom(sequence *document.Node, path Path, normalized []string, codes sequenceIdentityDiagnosticCodes, startIndex int) (map[string]sequenceIdentityRecord, []Diagnostic) {
if sequence == nil || sequence.Kind != document.Sequence {
location := (*Location)(nil)
if sequence != nil {
@@ -234,7 +242,7 @@ func validateSequenceIdentity(sequence *document.Node, path Path, fields []strin
firstByTuple := make(map[string]sequenceIdentityRecord, len(sequence.Sequence))
for itemIndex, item := range sequence.Sequence {
itemPath := path.Index(itemIndex)
itemPath := path.Index(startIndex + itemIndex)
if item == nil || item.Kind != document.Mapping {
var primary *Location
if item != nil {