From 7dc2e5efe7208ffe9b69b1735c23ef8538374806 Mon Sep 17 00:00:00 2001 From: Thomas Vahrst Date: Wed, 18 Oct 2023 14:26:01 +0200 Subject: [PATCH] cache 'effective' Docket instance in DefaultAsyncApiDocketService --- .../DefaultAsyncApiDocketService.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java index 5d096ddbe..a66671935 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java @@ -25,18 +25,27 @@ public class DefaultAsyncApiDocketService implements AsyncApiDocketService { */ private final SpringwolfConfigProperties configProperties; + /** + * valid Docket instance, either reference to customDocket (if set) or environment based Docket. + * Lazy initialized on first invocation of getAsyncApiDocket(). + */ + private AsyncApiDocket effectiveDocket; + @Override public AsyncApiDocket getAsyncApiDocket() { - if (customDocket.isPresent()) { - log.debug("Reading springwolf configuration from custom defined @Bean AsyncApiDocket"); - return customDocket.get(); - } else { - log.debug("Reading springwolf configuration from application.properties files"); - return parseApplicationConfigProperties(configProperties); + if (effectiveDocket == null) { + if (customDocket.isPresent()) { + log.debug("Reading springwolf configuration from custom defined @Bean AsyncApiDocket"); + effectiveDocket = customDocket.get(); + } else { + log.debug("Reading springwolf configuration from application.properties files"); + effectiveDocket = parseApplicationConfigProperties(); + } } + return effectiveDocket; } - private AsyncApiDocket parseApplicationConfigProperties(SpringwolfConfigProperties configProperties) { + private AsyncApiDocket parseApplicationConfigProperties() { if (configProperties.getDocket() == null || configProperties.getDocket().getBasePackage() == null) { throw new IllegalArgumentException( "One or more required fields (docket, basePackage) " + "in application.properties with path prefix "