Add custom mimetypes to capability statement
This commit is contained in:
parent
db44244405
commit
27cac16de6
|
@ -59,6 +59,12 @@ public class Constants {
|
|||
*/
|
||||
public static final String CT_FHIR_JSON_NEW = "application/fhir+json";
|
||||
public static final String CT_FHIR_XML = "application/xml+fhir";
|
||||
|
||||
/**
|
||||
* Special Conformance Formats that don't follow normal mediatype rules
|
||||
*/
|
||||
public static final String CT_JSON_RAW = "json";
|
||||
public static final String CT_XML_RAW = "xml";
|
||||
/**
|
||||
* The FHIR MimeType for XML encoding in FHIR DSTU3+
|
||||
*/
|
||||
|
|
|
@ -224,6 +224,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState
|
|||
retVal.getSoftware().setVersion(serverConfiguration.getServerVersion());
|
||||
retVal.addFormat(Constants.CT_FHIR_XML_NEW);
|
||||
retVal.addFormat(Constants.CT_FHIR_JSON_NEW);
|
||||
retVal.addFormat(Constants.CT_JSON_RAW);
|
||||
retVal.addFormat(Constants.CT_XML_RAW);
|
||||
retVal.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
CapabilityStatementRestComponent rest = retVal.addRest();
|
||||
|
|
|
@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.annotation.Description;
|
|||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
|
@ -47,17 +48,20 @@ import org.junit.jupiter.api.Disabled;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
@ -172,6 +176,26 @@ public class ServerCapabilityStatementProviderDstu3Test {
|
|||
assertTrue(res.getConditionalUpdate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException {
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider();
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs));
|
||||
|
||||
List<String> formatCodes = serverConformance.getFormat().stream().map(c -> c.asStringValue()).collect(Collectors.toList());;
|
||||
|
||||
assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_JSON_RAW));
|
||||
assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_XML_RAW));
|
||||
assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExtendedOperationReturningBundle() throws Exception {
|
||||
|
||||
|
|
|
@ -172,6 +172,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState
|
|||
retVal.getSoftware().setVersion(configuration.getServerVersion());
|
||||
retVal.addFormat(Constants.CT_FHIR_XML_NEW);
|
||||
retVal.addFormat(Constants.CT_FHIR_JSON_NEW);
|
||||
retVal.addFormat(Constants.CT_JSON_RAW);
|
||||
retVal.addFormat(Constants.CT_XML_RAW);
|
||||
retVal.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
CapabilityStatementRestComponent rest = retVal.addRest();
|
||||
|
|
|
@ -20,6 +20,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
|
|||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.annotation.Update;
|
||||
import ca.uhn.fhir.rest.annotation.Validate;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
|
@ -40,6 +41,7 @@ import ca.uhn.fhir.util.TestUtil;
|
|||
import ca.uhn.fhir.validation.FhirValidator;
|
||||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
|
@ -67,6 +69,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -79,6 +82,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
@ -525,6 +529,26 @@ public class ServerCapabilityStatementProviderR4Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException {
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider();
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs));
|
||||
|
||||
List<String> formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());;
|
||||
|
||||
assertThat(formatCodes, hasItem(Constants.CT_JSON_RAW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_XML_RAW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW));
|
||||
}
|
||||
|
||||
/**
|
||||
* See #286
|
||||
*/
|
||||
|
|
|
@ -184,6 +184,8 @@ public class ServerCapabilityStatementProvider extends BaseServerCapabilityState
|
|||
retVal.getSoftware().setVersion(configuration.getServerVersion());
|
||||
retVal.addFormat(Constants.CT_FHIR_XML_NEW);
|
||||
retVal.addFormat(Constants.CT_FHIR_JSON_NEW);
|
||||
retVal.addFormat(Constants.CT_JSON_RAW);
|
||||
retVal.addFormat(Constants.CT_XML_RAW);
|
||||
retVal.setStatus(PublicationStatus.ACTIVE);
|
||||
|
||||
CapabilityStatementRestComponent rest = retVal.addRest();
|
||||
|
|
|
@ -6,6 +6,7 @@ import ca.uhn.fhir.model.api.annotation.Description;
|
|||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
|
@ -42,17 +43,20 @@ import org.junit.jupiter.api.Disabled;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
@ -197,6 +201,26 @@ public class ServerCapabilityStatementProviderR5Test {
|
|||
assertThat(conf, containsString("<interaction><code value=\"" + TypeRestfulInteraction.HISTORYINSTANCE.toCode() + "\"/></interaction>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatIncludesSpecialNonMediaTypeFormats() throws ServletException {
|
||||
RestfulServer rs = new RestfulServer(ourCtx);
|
||||
rs.setProviders(new SearchProvider());
|
||||
|
||||
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider();
|
||||
rs.setServerConformanceProvider(sc);
|
||||
|
||||
rs.init(createServletConfig());
|
||||
CapabilityStatement serverConformance = sc.getServerConformance(createHttpServletRequest(), createRequestDetails(rs));
|
||||
|
||||
List<String> formatCodes = serverConformance.getFormat().stream().map(c -> c.getCode()).collect(Collectors.toList());;
|
||||
|
||||
assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_JSON_RAW));
|
||||
assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_XML_RAW));
|
||||
assertThat(formatCodes, hasItem(ca.uhn.fhir.rest.api.Constants.CT_FHIR_JSON_NEW));
|
||||
assertThat(formatCodes, hasItem(Constants.CT_FHIR_XML_NEW));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMultiOptionalDocumentation() throws Exception {
|
||||
|
||||
|
|
Loading…
Reference in New Issue