diff --git a/springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerWebMvcConfigurer.java b/springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerWebMvcConfigurer.java index 5954f25b2..998bc904e 100644 --- a/springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerWebMvcConfigurer.java +++ b/springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerWebMvcConfigurer.java @@ -49,6 +49,7 @@ import static org.springdoc.core.Constants.CLASSPATH_RESOURCE_LOCATION; import static org.springdoc.core.Constants.DEFAULT_WEB_JARS_PREFIX_URL; +import static org.springdoc.core.Constants.SWAGGER_INITIALIZER_JS; import static org.springdoc.core.Constants.SWAGGER_UI_PREFIX; import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR; @@ -96,6 +97,12 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { if (actuatorProvider.isPresent() && actuatorProvider.get().isUseManagementPort()) uiRootPath.append(actuatorProvider.get().getBasePath()); + registry.addResourceHandler(uiRootPath + SWAGGER_UI_PREFIX + "*/*" + SWAGGER_INITIALIZER_JS) + .addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR) + .setCachePeriod(0) + .resourceChain(false) + .addTransformer(swaggerIndexTransformer); + registry.addResourceHandler(uiRootPath + SWAGGER_UI_PREFIX + "*/**") .addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR) .resourceChain(false) diff --git a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/AbstractSpringDocTest.java b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/AbstractSpringDocTest.java index 6ccd61012..1601e8249 100644 --- a/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/AbstractSpringDocTest.java +++ b/springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/AbstractSpringDocTest.java @@ -37,6 +37,7 @@ protected void checkJS(String fileName, String uri)throws Exception { MvcResult mvcResult = mockMvc.perform(get(uri)).andExpect(status().isOk()).andReturn(); String transformedIndex = mvcResult.getResponse().getContentAsString(); assertTrue(transformedIndex.contains("window.ui")); + assertEquals("no-store", mvcResult.getResponse().getHeader("Cache-Control")); assertEquals(this.getContent(fileName), transformedIndex.replace("\r", "")); }