From 142bb4eae4de8cbef71403206a3b78bf2cbdaaab Mon Sep 17 00:00:00 2001 From: Jon Bartels Date: Mon, 9 Nov 2026 21:59:33 -0500 Subject: [PATCH] Defer reading the OpenAPI spec until it is first requested SwaggerServlet read the full OpenAPI spec during server startup. Nothing used that result: OpenApiResource, which serves /api/openapi.json and /api/openapi.yaml, builds its own child context from the configuration SwaggerServlet registers and reads the spec again on the first request. Register the configuration only. The served spec is unchanged, and the Swagger servlet's init drops from about 660 ms to about 120 ms on a warm start, taking about 0.5 s off the time until the web server is up. The startup read did warm up class loading and Jackson introspection, so the first spec request now takes longer (about 460 ms to 700 ms on a warm start). That request normally comes from someone opening the Swagger UI, which is a better place for the cost than server startup. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Jon Bartels --- .../com/mirth/connect/server/servlets/SwaggerServlet.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/mirth/connect/server/servlets/SwaggerServlet.java b/server/src/main/java/com/mirth/connect/server/servlets/SwaggerServlet.java index 5ac2d1186..4c169665f 100644 --- a/server/src/main/java/com/mirth/connect/server/servlets/SwaggerServlet.java +++ b/server/src/main/java/com/mirth/connect/server/servlets/SwaggerServlet.java @@ -70,12 +70,14 @@ public void init(ServletConfig config) throws ServletException { .openAPI(oas) .resourceClasses(resourceClasses.stream().map(Class::getName).collect(Collectors.toSet())); + // Only register the configuration here. OpenApiResource builds its own child context from it + // and reads the spec on the first request; it never uses a read done here. Reading here would + // only warm up classes for that first request, at the cost of slower server startup. try { new ServletOpenApiContextBuilder() .servletConfig(config) .openApiConfiguration(oasConfig) - .buildContext(true) - .read(); + .buildContext(true); } catch (OpenApiConfigurationException e) { logger.error("Failed to initialize Swagger servlet", e); throw new ServletException(e.getMessage(), e);