Skip to content

Commit 142bb4e

Browse files
jonbartelsclaude
andcommitted
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 <noreply@anthropic.com> Signed-off-by: Jon Bartels <jonathan.bartels@gmail.com>
1 parent fdff780 commit 142bb4e

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎server/src/main/java/com/mirth/connect/server/servlets/SwaggerServlet.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ public void init(ServletConfig config) throws ServletException {
7070
.openAPI(oas)
7171
.resourceClasses(resourceClasses.stream().map(Class::getName).collect(Collectors.toSet()));
7272

73+
// Only register the configuration here. OpenApiResource builds its own child context from it
74+
// and reads the spec on the first request; it never uses a read done here. Reading here would
75+
// only warm up classes for that first request, at the cost of slower server startup.
7376
try {
7477
new ServletOpenApiContextBuilder()
7578
.servletConfig(config)
7679
.openApiConfiguration(oasConfig)
77-
.buildContext(true)
78-
.read();
80+
.buildContext(true);
7981
} catch (OpenApiConfigurationException e) {
8082
logger.error("Failed to initialize Swagger servlet", e);
8183
throw new ServletException(e.getMessage(), e);

0 commit comments

Comments
 (0)