5.12.1OpenAPI / Swagger Support


In HAPI FHIR, support for OpenAPI (aka Swagger) is supported via the OpenApiInterceptor.

Note that this interceptor supports servers using the RestfulServer (aka HAPI FHIR Plain Server and JPA Server), and does not currently support JAX-RS servers.

When this interceptor is registered against the server, it performs the following 3 tasks: Functionality

  • OpenAPI 3.0 Documentation will be served at [baseUrl]/api-docs. This documentation is generated by the interceptor using information from the server's CapabilityStatement as well as from its automatically generated OperationDefinitions. Functionality

5.12.2Enabling OpenAPI


The HAPI FHIR OpenAPI functionality is supplied in a dedicated module called hapi-fhir-server-openapi. To enable this functionality you must first include this module in your project. For example, Maven users should include the following dependency:


You then simply have to register the interceptor against your RestfulServer instance.

      urlPatterns = {"/fhir/*"},
      displayName = "FHIR Server")
public class RestfulServerWithOpenApi extends RestfulServer {

   protected void initialize() throws ServletException {

      // ... define your resource providers here ...

      // Now register the interceptor
      OpenApiInterceptor openApiInterceptor = new OpenApiInterceptor();



See the HAPI FHIR Test Server for a demonstration of HAPI FHIR OpenAPI functionality: http://hapi.fhir.org/baseR4/swagger-ui/