OpenAPI and Swagger UI for a HAPI FHIR server

The OpenApiInterceptor generates OpenAPI 3.0 documentation and a Swagger UI from your server's CapabilityStatement. This page covers setup, the case for keeping it out of production, and what to confirm first.

On this page

What OpenAPI and Swagger UI add to a HAPI FHIR server

Developers and integration partners need to know which resources and operations a FHIR server exposes before they write a line of client code. The HAPI FHIR OpenApiInterceptor answers that need: it serves OpenAPI 3.0 documentation at [baseUrl]/api-docs, generated from the server's CapabilityStatement and OperationDefinitions, and redirects browsers to a customized Swagger UI at [baseUrl]/swagger-ui/. Teams usually need this when several internal applications or external partners build against the same server, when the list of supported resource types and search parameters changes between releases, or when a reviewer wants a readable, machine-generated description of the API surface instead of a hand-written document that drifts from the code.

The output is only as accurate as the CapabilityStatement the server returns. Before you publish the documentation, check that the CapabilityStatement lists the resource types, search parameters, interactions and operations you actually support, including any custom operations you have added. Stale or overly broad capability declarations will show up in the OpenAPI document as well, so this review belongs to the implementation work, not to the documentation step. Confirm with your HAPI FHIR version which CapabilityStatement settings and interceptor options apply, using the HAPI FHIR OpenAPI and Swagger support documentation as the starting point.

The interceptor does not support JAX-RS servers, so confirm that your deployment runs the HAPI FHIR plain server model before you plan around it. Teams on a JAX-RS based setup need a different documentation approach, and that gap should be found during design rather than during rollout. Interactive Swagger UI access is convenient for developers, but whether it stays available beyond development is a separate decision, covered in the exposure guidance below.

How to enable the OpenApiInterceptor step by step

This sequence takes a HAPI FHIR JPA server from a confirmed version and runtime to a served OpenAPI 3.0 document and a working Swagger UI, with a check at each stage so problems surface before anyone relies on the output.

  1. Confirm the server version and runtime

    Before changing anything, confirm that the server is built on the HAPI FHIR JPA server starter or an equivalent JPA-based build, that the HAPI FHIR version is one your team has chosen to run, and that the JDK matches the version's requirement. HAPI FHIR 8.2.0 requires JDK 17, and the versions page lists requirements for other releases. Record the version and JDK in your change ticket. The step is done when someone can state both values from the running environment, not from memory.

  2. Register the OpenApiInterceptor on the server

    Add the OpenApiInterceptor to the server's interceptor registration, using the approach your build uses (for example, Java configuration in a custom server or the starter's configuration). The interceptor is part of the HAPI FHIR server code, so confirm the class name and registration method against the official OpenAPI and Swagger support documentation for your version rather than copying snippets from older articles. The step is done when the change is committed to version control and the build compiles without errors.

  3. Start the server and watch the logs

    Build and start the server in a non-production environment, such as a developer workstation or a test namespace. Watch startup logs for interceptor registration messages and for errors related to the CapabilityStatement or OperationDefinitions, which the generated documentation depends on. The step is done when the server reports a clean startup and answers a basic metadata request at its base URL.

  4. Check the CapabilityStatement loads

    Request the server's metadata endpoint at the base URL and confirm it returns a CapabilityStatement with the resource types, search parameters and operations you expect. The OpenAPI document is generated from this statement, so gaps here become gaps in the documentation. The step is done when the resource list matches the configuration you intended to ship, and any missing resource types have been traced to configuration rather than assumed to be a documentation issue.

  5. Confirm the OpenAPI 3.0 document at api-docs

    Request the path ending in api-docs under the base URL and confirm it returns a JSON document that declares OpenAPI version 3.0. Check that paths for resource types and operations appear. Validate the document with an OpenAPI validator your team already uses, since a document that loads in a browser can still contain structural problems. The step is done when the document parses, declares OpenAPI 3.0, and the validator reports no blocking errors.

  6. Open the Swagger UI in a browser

    Open a browser and go to the swagger-ui path under the base URL. The OpenApiInterceptor redirects browsers to a customized Swagger UI, so the path you request should land on the UI rather than on an error page. Test with a browser that your users use and confirm that the UI loads the API document you checked in the previous step. The step is done when the UI renders the resource list and an example request can be run against a non-production dataset.

  7. Verify base URL and reverse proxy paths

    If the server sits behind a reverse proxy, load balancer or ingress with a path prefix, check that the base URL configured in the server matches the public address users type. Documentation generated with the wrong base URL will point try-it-out requests at internal hosts or broken paths. Request the api-docs and swagger-ui paths through the public address, not only the internal one, and confirm the server URLs in the OpenAPI document are correct. Confirm the exact base URL and proxy settings against the official documentation, since configuration keys vary by version and deployment method. The step is done when both paths work through the proxy and the server URLs in the document resolve to the intended public endpoint.

  8. Record the result and decide on exposure

    Write down the version, JDK, base URL, the paths tested and the validator result, then decide who may reach the api-docs and Swagger UI paths outside development. Those paths reveal the resource types and operations the server supports, so the exposure decision belongs with your security owner and should follow your access control design rather than be left at default. The step is done when the record is stored with the configuration and the exposure decision is approved.

Whether to expose Swagger UI in each environment

On a developer workstation, the OpenApiInterceptor is most useful. Developers use the generated OpenAPI document at [baseUrl]/api-docs and the Swagger UI at [baseUrl]/swagger-ui/ to see which resource types, search parameters and operations the server advertises, and to try requests before writing client code. The server is usually bound to localhost and seeded with sample data, so the main exposure is the developer's own machine and any port forwarding they set up.

  • Who uses it: Developers and solution architects working against a local or throwaway instance.
  • What it reveals: Every resource type and operation in the CapabilityStatement, which matters little when the data is synthetic.
  • Controls that fit: Bind the server to localhost, avoid public port forwarding, and keep the interceptor enabled by default in the local profile.
  • Watch for: Developers copying a local configuration with the interceptor enabled into a shared environment.
  • Watch for: Real patient data loaded into a local database for testing, which brings the workstation under your data handling rules.

Confirm that the local profile is separate from the configuration used for shared and production deployments, so that the interceptor setting does not travel with a copied file.

Configuration options and when each fits

This table compares four ways to run the OpenApiInterceptor, from enabling it everywhere to publishing a separate API description. Read each row for the developer convenience it buys, the information it may expose, and the operational work it adds. The main takeaway is that the interceptor is easiest to justify in development and test, and production exposure needs a deliberate access decision.

OptionDeveloper convenienceInformation exposureWhen it fits
Enabled in all environmentsHigh: Swagger UI and api-docs are available wherever the server runsHigh: the endpoints reveal resource types, search parameters and operations to anyone who can reach themRarely appropriate for regulated production; only with a documented reason and a network boundary
Enabled only in development or test profilesHigh for engineers working against non-production dataLow in production, since the interceptor is not registered thereCommon default when production data and test data are kept apart
Served behind network or identity controlsMedium: engineers reach the UI through VPN, bastion or SSOMedium: exposure is limited to authorized networks or users, but the surface still existsUseful when production-like docs are needed for reviewers or integrators inside the organization
Not enabled, with a separately published API descriptionLower: consumers read a static spec instead of a live UILow: you choose what the published spec contains and can omit internal operationsFits external integrators or assessors who need documentation without access to the server

Security risks of publishing the API surface

Publishing OpenAPI documentation and Swagger UI makes the server's resource types, operations and search parameters easy to read for anyone who can reach them. HAPI FHIR provides building blocks for security rather than one layer, so each risk below needs an explicit control in your deployment.

Unauthenticated exposure of the surface

The generated documentation lists resource types, operations and search parameters based on the CapabilityStatement. If the docs path is reachable without credentials, an outsider can map your data model and target specific operations before any authorization check runs. Confirm which paths answer without a token, and whether your deployment intends the CapabilityStatement itself to be public. Decide the exposure before you publish the docs.

OpenAPI docs

Swagger UI as a web application

Swagger UI is a browser application with its own JavaScript dependencies, so it carries the usual web risks and needs the same patching discipline as any other front-end component. Ask which Swagger UI version your HAPI FHIR release bundles, how often that bundle is updated, and whether your vulnerability scanning covers it. Treat the UI as a component you own, not as part of the FHIR server.

Interaction with AuthorizationInterceptor and SMART scopes

Documentation describes what exists, not what a caller may do. Where the AuthorizationInterceptor or SMART on FHIR scopes restrict access, the published docs can still show operations that a given token cannot use, which may confuse testers or hint at restricted data. Test the Swagger UI as each role you support, using a token with narrow scopes, and confirm that denied requests return the expected errors.

Reverse proxy path rules

Docs are often reachable only because a proxy forwards paths like /swagger-ui/ or /api-docs to the server. Path rules that allow a documentation prefix but are written loosely can expose other administrative or internal paths. Review the proxy rules for both the docs path and the base FHIR path, and test that unlisted paths return denial. Keep the rule set in version control so changes are reviewed.

Documentation does not replace authorization

Hiding the Swagger UI does not protect the FHIR endpoints. Any client can call the REST API directly with the same requests the docs describe, so access control must live in the server's authorization, consent and search narrowing setup. HAPI FHIR describes these as building blocks that you assemble and test, so the security design should be written and verified separately from the documentation decision.

HAPI FHIR security

Logging access to the docs

Requests for the docs and the UI are part of the access picture, and they can reveal reconnaissance activity. Decide whether requests to the docs paths are logged, how long those logs are kept, and who reviews them. Confirm that audit logging for FHIR data access, such as BALP, is configured separately, and that docs-related log entries do not capture tokens or patient identifiers.

What the generated docs do and do not show

The generated documentation describes what the server declares, not necessarily what it enforces. The OpenApiInterceptor builds its OpenAPI 3.0 output from the server's CapabilityStatement and OperationDefinitions, so the paths, resource types, search parameters and operations that appear in /api-docs and the Swagger UI follow from configuration: which resource types are enabled, which operations are registered, and which interceptors are active when the server starts. A resource type that is declared but restricted by an AuthorizationInterceptor rule will still appear in the output unless your configuration removes it. Treat the page as a map of the declared surface, and confirm with your team which parts of it are reachable by which roles.

The most common source of misleading documentation is a gap between declared capabilities and actual authorization behavior. A reader who sees a search parameter or the $export operation listed may assume every caller can use it, and a security reviewer may take the same listing as evidence of access control that has not been tested. The reverse also occurs: a restriction added by a consent or search narrowing interceptor can change results for one user without changing the documentation at all. Before publishing the output, compare each listed interaction against the results of role-based test calls for each user group you support, including denied requests, and record the expected status code and returned data for each. Where the two disagree, fix the configuration first and regenerate, rather than adding a note to the docs.

Limits to confirm in your environment

The OpenApiInterceptor is narrow in what it covers, so several behaviors depend on your HAPI FHIR version, your proxy layout and your server type. Each card below names one limit to verify, with the check that settles it. Confirm them against the official docs or a test deployment before the documentation endpoint reaches a shared environment.

Plain server support only

The interceptor does not support JAX-RS servers. If your HAPI FHIR deployment runs on the JAX-RS server model rather than the plain server model, the OpenAPI document will not generate as described and you will need another route to documentation. Check which server style your application uses before you plan the rollout, because the choice is made in code and is hard to reverse later in a mature project.

OpenAPI docs

Behavior on your HAPI FHIR version

Interceptor behavior, generated output and the bundled Swagger UI can change between HAPI FHIR releases. Read the release notes for the exact version you run, then confirm the /api-docs output and the /swagger-ui/ redirect on a test deployment built from the same image or WAR. Record the version next to the generated document so reviewers can reproduce it later.

HAPI FHIR releases

Reverse proxy and base URL effects

The redirect to Swagger UI and the server URLs inside the OpenAPI document are built from the base URL the server sees. Behind a load balancer, ingress or TLS-terminating proxy, a mismatch can send browsers to an internal hostname or to http instead of https. Test through the same path your users will use, check the forwarded headers your proxy sets, and verify the redirect and the servers entries in the generated document.

Swagger UI customization depth

The Swagger UI served by the interceptor is customized by HAPI FHIR, but how far you can change its branding, layout, authentication prompts or static assets is a question for the docs and your own testing. Confirm which settings are exposed, which require overlaying files in your build, and whether a change survives an upgrade. Keep a written list of every customization so the upgrade review can recheck it.

Custom operations in the document

The document is generated from the CapabilityStatement and OperationDefinitions. Custom operations you register may or may not appear, and an operation without a matching OperationDefinition may be omitted or described incompletely. Compare the generated document with the operations your clients call, and confirm each custom $operation appears with correct parameters. Missing entries are a common cause of incomplete API reviews.

How a request to the docs reaches the server

A browser request starts on the public network and passes through a reverse proxy before it reaches the HAPI FHIR JPA server. Inside the server, the OpenApiInterceptor builds OpenAPI 3.0 documentation from the CapabilityStatement and OperationDefinitions, then either returns the JSON at /api-docs or redirects a browser to /swagger-ui/. The trust boundary sits in front of the proxy, so check which paths the proxy exposes and whether it enforces any access control before a request reaches the server.

Request path from a browser to the OpenApiInterceptor, with the trust boundary marked.

Questions teams ask before enabling OpenAPI docs

Is it safe to expose OpenAPI docs and Swagger UI in production?

Not by default. The OpenApiInterceptor publishes API documentation at [baseUrl]/api-docs and a Swagger UI at [baseUrl]/swagger-ui/, and that surface tells an outsider which resource types, search parameters and operations your server accepts. Most teams keep it in development and test, or place it behind the same authentication and network controls as the API itself. If you do expose it, add access control at the reverse proxy, restrict it to internal networks or VPN users, and confirm that the documentation matches what your authorization rules actually allow. HAPI FHIR does not provide a single security layer, so treat the docs endpoint as one more route to protect, not as harmless metadata.

How much effort does enabling OpenAPI docs take, and what drives it?

The interceptor itself is a configuration change, but the surrounding work varies with your setup. The main drivers are how the server is deployed (Docker image, Spring Boot, a WAR on Tomcat, Jetty or Wildfly, or Kubernetes with the Helm chart), whether a reverse proxy rewrites paths or hostnames so the generated base URL is correct, how authentication is applied to the docs and Swagger UI routes, and how many HAPI FHIR and JDK versions you must test against. Each deployment target adds its own routing and packaging checks. Ask for the effort split between configuration, proxy and authentication work, and version testing in any written scope.

Can an in-house developer enable OpenAPI docs without outside help?

Usually yes, if the team already runs the HAPI FHIR JPA server and can change its configuration and deploy it. The task is bounded: register the interceptor, confirm the generated documents load, and check that the base URL resolves correctly through your proxy. The harder part is the decisions around it: who may see the docs in each environment, how the docs endpoint sits behind your identity provider, and whether the team will retest after each HAPI FHIR upgrade. Teams without an engineer who owns server configuration and reverse proxy rules tend to find those decisions take longer than the code change.

What does a partner's scope for this work typically include?

A written scope for this kind of work usually covers the interceptor configuration in each environment, the reverse proxy and base URL settings, the access control placed on the docs and Swagger UI routes, verification against the deployed server, and a short operating note explaining who may enable or disable the endpoint. If your server exposes custom operations, the scope should also state how those OperationDefinitions are checked in the generated output. DeployOpen plans and implements engagements as fixed scope, so deliverables and timelines are agreed in writing before work starts, and the quote follows from that scope. Ask for each item to be named, so you can see what is excluded.

How long does verification take when we run several environments?

Verification time grows with the number of environments because each one has its own base URL, proxy rules, identity setup and access policy. A single development server is a short check. Adding test, staging and production multiplies the checks for routing, authentication and the rule that production does not expose the endpoint publicly without approval. Duration also depends on how many HAPI FHIR versions you run and whether each one needs a retest. Ask for the verification steps listed per environment, and for the environments that must be reachable before testing starts, rather than accepting one overall estimate.

What do we need to provide before the work starts?

Three things make the work move quickly. First, access to each environment that will run the interceptor, including the deployment configuration and reverse proxy settings, through whatever access path your security team approves. Second, a test server that mirrors production routing and authentication, so the docs can be checked without touching live patient data. Third, a named owner on your side who decides who may see the docs in each environment and who approves any production exposure. Without that owner, the scope tends to stall at the point where the access decision is needed.

Does the generated documentation reveal anything about patient data?

The documentation describes the API shape, including supported resource types, operations and search parameters, rather than stored records. It does not contain patient data itself. The risk is indirect: it maps the attack surface and the data model your organization uses. Confirm with your compliance and security leads whether that level of detail is acceptable outside your internal network, and review your authorization and consent interceptors so that what the docs advertise matches what callers can actually reach. For broader obligations, see how the operator must add controls around the server.

How DeployOpen works on this

DeployOpen scopes OpenAPI and Swagger UI for your HAPI FHIR server as a defined piece of work inside your own infrastructure, then builds, tests and documents it so your API consumers and reviewers can rely on it. The approach covers which endpoints are published, who can reach the documentation, and how it stays in step with the server over time.

How we scope

  • Confirm which FHIR versions and resource types the server exposes, so the generated documentation matches the live CapabilityStatement
  • Decide whether the documentation serves developers only, internal staff, or partner organizations, and record that decision in writing
  • Agree in writing whether the Swagger UI is enabled outside development and which access controls protect it
  • Engagements are fixed-scope, with deliverables and timelines agreed before work starts

How we build

  • Configure the OpenApiInterceptor on your HAPI FHIR JPA server and confirm the api-docs and swagger-ui paths respond as expected
  • Customize the Swagger UI and check that OperationDefinitions and custom operations appear with correct parameters and descriptions
  • Test the published documentation against the running server in your staging environment, including authentication and CORS behavior
  • Restrict or disable the interface for production according to the scope agreed with your security team

How we hand over

  • Deliver a written configuration record covering interceptor settings, URL paths, access rules and the chosen production exposure
  • Document how to regenerate and verify the OpenAPI output after a server, FHIR version or implementation guide change
  • Walk your platform and security teams through the test results and the reasons behind each exposure decision
  • Provide a runbook for disabling the documentation endpoints quickly if your security review requires it

How we support

  • Retest the documentation after HAPI FHIR upgrades, since the generated output depends on the server's CapabilityStatement
  • Ongoing support, upgrades and continuous testing are available as a retainer, scoped in writing
  • Ask for a quote based on the written scope, which should list each deliverable, the environments covered and the retest plan
  • Confirm with your vendor and your own environment which HAPI FHIR version and JDK requirement apply before planning the upgrade

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.