From 9ef15d9c54303578dec26f25fe8d3e99903b86e0 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Wed, 4 Sep 2024 20:45:29 +0200 Subject: [PATCH] fix: OpenAPI - only cache the full default response [DHIS2-17684] (#18526) --- .../dhis/webapi/openapi/OpenApiController.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/OpenApiController.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/OpenApiController.java index b1d7a95fc210..f2d50b292fa4 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/OpenApiController.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/openapi/OpenApiController.java @@ -94,7 +94,7 @@ public static class OpenApiScopeParams { Set domain = Set.of(); @OpenApi.Ignore - boolean isFull() { + boolean isCachable() { return path.isEmpty() && domain.isEmpty(); } } @@ -128,6 +128,11 @@ and as a consequence types occur fully expanded (with all their properties). @Maturity.Beta @OpenApi.Since(42) boolean expandedRefs = false; + + @OpenApi.Ignore + boolean isCachable() { + return !skipCache && !expandedRefs; + } } /* @@ -151,7 +156,8 @@ public void getOpenApiHtml( HttpServletResponse response) { if (notModified(request, response, generation)) return; - if (scope.isFull() && !generation.isSkipCache() && fullHtml != null) { + boolean cached = scope.isCachable() && generation.isCachable(); + if (cached && fullHtml != null) { String fullHtml = OpenApiController.fullHtml.get(); if (fullHtml != null) { getWriter(response, TEXT_HTML_VALUE).get().write(fullHtml); @@ -164,7 +170,7 @@ public void getOpenApiHtml( request, generation, scope, () -> new PrintWriter(json), OpenApiGenerator::generateJson); String html = OpenApiRenderer.render(json.toString(), rendering); - if (scope.isFull()) updateFullHtml(html); + if (cached) updateFullHtml(html); getWriter(response, TEXT_HTML_VALUE).get().write(html); } @@ -294,7 +300,7 @@ private void writeDocument( @Nonnull private Api getApiCached(OpenApiGenerationParams generation, OpenApiScopeParams scope) { - if (scope.isFull() && !generation.isSkipCache()) { + if (scope.isCachable() && generation.isCachable()) { Api api = fullApi == null ? null : fullApi.get(); if (api == null) { api = getApiUncached(generation, scope);