Change validator so root resource id is not in the same space as all other ids

This commit is contained in:
Grahame Grieve 2020-04-06 10:11:33 +10:00
parent 3e49000188
commit 7400263b86
3 changed files with 12 additions and 4 deletions

View File

@ -695,10 +695,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
long t = System.nanoTime();
if (profiles == null || profiles.isEmpty()) {
validateResource(new ValidatorHostContext(appContext, element), errors, element, element, null, resourceIdRule, new NodeStack(context, element, validationLanguage));
validateResource(new ValidatorHostContext(appContext, element), errors, element, element, null, resourceIdRule, new NodeStack(context, element, validationLanguage).resetIds());
} else {
for (StructureDefinition defn : profiles) {
validateResource(new ValidatorHostContext(appContext, element), errors, element, element, defn, resourceIdRule, new NodeStack(context, element, validationLanguage));
validateResource(new ValidatorHostContext(appContext, element), errors, element, element, defn, resourceIdRule, new NodeStack(context, element, validationLanguage).resetIds());
}
}
if (hintAboutNonMustSupport) {
@ -3953,8 +3953,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (stack.getIds().containsKey(id) && stack.getIds().get(id) != element) {
rule(errors, IssueType.BUSINESSRULE, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.DUPLICATE_ID, id);
}
if (!stack.isResetPoint()) {
stack.getIds().put(id, element);
}
}
if (definition.getPath().equals("StructureDefinition.snapshot")) {
// work around a known issue in the spec, that idsa are duplicated in snapshot and differential
stack.resetIds();

View File

@ -26,6 +26,7 @@ public class NodeStack {
private ElementDefinition type;
private String workingLang;
private Map<String, Element> ids;
private boolean resetPoint = false;
public NodeStack(IWorkerContext context) {
this.context = context;
@ -147,6 +148,7 @@ public class NodeStack {
public NodeStack resetIds() {
ids = new HashMap<>();
resetPoint = true;
return this;
}
public Map<String, Element> getIds() {
@ -178,5 +180,9 @@ public class NodeStack {
}
public boolean isResetPoint() {
return resetPoint;
}
}

View File

@ -17,7 +17,7 @@
<properties>
<hapi_fhir_version>4.2.0</hapi_fhir_version>
<validator_test_case_version>1.1.4-SNAPSHOT</validator_test_case_version>
<validator_test_case_version>1.1.5-SNAPSHOT</validator_test_case_version>
</properties>
<artifactId>org.hl7.fhir.core</artifactId>