Skip to content

Commit

Permalink
fix: OpenAPI - only cache the full default response [DHIS2-17684] (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbee authored Sep 4, 2024
1 parent 1379999 commit 9ef15d9
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static class OpenApiScopeParams {
Set<String> domain = Set.of();

@OpenApi.Ignore
boolean isFull() {
boolean isCachable() {
return path.isEmpty() && domain.isEmpty();
}
}
Expand Down Expand Up @@ -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;
}
}

/*
Expand All @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9ef15d9

Please sign in to comment.