Added @Inherited to ResourceDef annotation (#2340)

This change avoids duplication of ResourceDef on custom resources, where there is no changes on resource name or profile.
This commit is contained in:
Marcelo Avancini 2021-02-02 16:25:07 -03:00 committed by GitHub
parent 589d323175
commit 0d00954852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.model.api.annotation;
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@ -28,6 +29,7 @@ import java.lang.annotation.Target;
/**
* Class annotation which indicates a resource definition class
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(value= {ElementType.TYPE})
public @interface ResourceDef {

View File

@ -13,6 +13,7 @@ import ca.uhn.fhir.util.TestUtil;
import org.hl7.fhir.dstu3.model.Binary;
import org.hl7.fhir.dstu3.model.CarePlan;
import org.hl7.fhir.dstu3.model.CodeType;
import org.hl7.fhir.dstu3.model.DomainResource;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.Patient;
@ -89,6 +90,15 @@ public class ModelScannerDstu3Test {
}
}
@Test
public void testResourceWithInheritedDef() {
try {
FhirContext.forDstu3().getResourceDefinition(InheritedResourceDef.class);
} catch (ConfigurationException e) {
fail("The InheritedResourceDef class should contain a valid HAPI-FHIR annotation inherited from superclass");
}
}
@Test
public void testScanExtensionTypes() throws DataFormatException {
@ -238,11 +248,25 @@ public class ModelScannerDstu3Test {
}
}
class NoResourceDef extends Patient {
class NoResourceDef extends DomainResource {
@SearchParamDefinition(name = "foo", path = "Patient.telecom", type = "bar")
public static final String SP_TELECOM = "foo";
private static final long serialVersionUID = 1L;
@Override
public DomainResource copy() {
return null;
}
@Override
public ResourceType getResourceType() {
return null;
}
}
static class InheritedResourceDef extends Patient {
public InheritedResourceDef() {
}
}
@ResourceDef(name = "Patient")