Skip to content

Commit

Permalink
Add check for duplicate ids on contained resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Jan 27, 2025
1 parent d455a81 commit a45c05f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1188,4 +1188,5 @@ public class I18nConstants {
public static final String VALIDATION_AI_TEXT_CODE = "VALIDATION_AI_TEXT_CODE";
public static final String VALIDATION_AI_FAILED = "VALIDATION_AI_FAILED";
public static final String VALIDATION_AI_FAILED_LOG = "VALIDATION_AI_FAILED_LOG";
public static final String RESOURCE_DUPLICATE_CONTAINED_ID = "RESOURCE_DUPLICATE_CONTAINED_ID";
}
Original file line number Diff line number Diff line change
Expand Up @@ -1219,4 +1219,5 @@ REFERENCE_RESOLUTION_FAILED = Fetching ''{0}'' failed. System details: {1}: {2}
VALIDATION_AI_TEXT_CODE = Apparent mis-match between code ''{0}'' and text ''{1}'': {3} ({2} confidence)
VALIDATION_AI_FAILED = Consulting AI failed: {0}
VALIDATION_AI_FAILED_LOG = Consulting AI failed: {0} (see {1} for further details)
RESOURCE_DUPLICATE_CONTAINED_ID = Duplicate ID for contained resource: {0}

Original file line number Diff line number Diff line change
Expand Up @@ -6375,6 +6375,16 @@ private boolean validateContains(ValidationContext valContext, List<ValidationMe
hc = valContext.forContained(element);
}

if (special == SpecialElement.CONTAINED) {
String id = element.getNamedChildValue("id");
if (id == null) {
// this is an error handled elsewhere
} else {
ok = rule(errors, "2025-01-28", IssueType.DUPLICATE, element.line(), element.col(), stack.getLiteralPath(),
!stack.getIds().containsKey("!"+id), I18nConstants.RESOURCE_DUPLICATE_CONTAINED_ID, id) && ok;
stack.getIds().put("!"+id, element);
}
}
stack.resetIds();
if (special != null) {
switch (special) {
Expand Down

0 comments on commit a45c05f

Please sign in to comment.