Skip to content

Commit 9a76bed

Browse files
committed
not cache swagger-initializer.js. #1929
1 parent 00e7cc2 commit 9a76bed

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerWebMvcConfigurer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
import static org.springdoc.core.Constants.CLASSPATH_RESOURCE_LOCATION;
5151
import static org.springdoc.core.Constants.DEFAULT_WEB_JARS_PREFIX_URL;
52+
import static org.springdoc.core.Constants.SWAGGER_INITIALIZER_JS;
5253
import static org.springdoc.core.Constants.SWAGGER_UI_PREFIX;
5354
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;
5455

@@ -96,6 +97,12 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
9697
if (actuatorProvider.isPresent() && actuatorProvider.get().isUseManagementPort())
9798
uiRootPath.append(actuatorProvider.get().getBasePath());
9899

100+
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PREFIX + "*/*" + SWAGGER_INITIALIZER_JS)
101+
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR)
102+
.setCachePeriod(0)
103+
.resourceChain(false)
104+
.addTransformer(swaggerIndexTransformer);
105+
99106
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PREFIX + "*/**")
100107
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR)
101108
.resourceChain(false)

springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/AbstractSpringDocTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected void checkJS(String fileName, String uri)throws Exception {
3737
MvcResult mvcResult = mockMvc.perform(get(uri)).andExpect(status().isOk()).andReturn();
3838
String transformedIndex = mvcResult.getResponse().getContentAsString();
3939
assertTrue(transformedIndex.contains("window.ui"));
40+
assertEquals("no-store", mvcResult.getResponse().getHeader("Cache-Control"));
4041
assertEquals(this.getContent(fileName), transformedIndex.replace("\r", ""));
4142
}
4243

0 commit comments

Comments
 (0)