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:

5.12.1.0.1System 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.

5.12.1.0.2User 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:

<dependency>
	<groupId>ca.uhn.hapi.fhir</groupId>
	<artifactId>hapi-fhir-server-openapi</artifactId>
	<version>VERSION</version>
</dependency>

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

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

   @Override
   protected void initialize() throws ServletException {

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

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

5.12.3Demonstration

 

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