Skip to content

Commit

Permalink
not cache swagger-initializer.js. #1929 #1930
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Nov 13, 2022
1 parent e7c744b commit 69ebc6e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import static org.springdoc.core.utils.Constants.DEFAULT_WEB_JARS_PREFIX_URL;
import static org.springdoc.core.utils.Constants.SWAGGER_UI_PREFIX;
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;

import static org.springdoc.core.utils.Constants.SWAGGER_INITIALIZER_JS;
/**
* The type Swagger web mvc configurer.
* @author bnasslahsen
Expand Down Expand Up @@ -98,6 +98,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""));
}

Expand Down

0 comments on commit 69ebc6e

Please sign in to comment.