Skip to content

Commit 000a9fb

Browse files
committed
Changes report: fix failing tests after swagger-ui 4.9.1
1 parent 9fbf333 commit 000a9fb

File tree

81 files changed

+571
-1533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+571
-1533
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/Constants.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ public final class Constants {
117117
*/
118118
public static final String SPRINGDOC_SWAGGER_UI_ENABLED = "springdoc.swagger-ui.enabled";
119119

120-
/**
121-
* The constant SPRING_NATIVE_LISTENER.
122-
*/
123-
public static final String SPRING_NATIVE_LISTENER = "org.springframework.nativex.NativeListener";
124-
125120
/**
126121
* The constant NULL.
127122
*/
@@ -193,6 +188,16 @@ public final class Constants {
193188
*/
194189
public static final String SWAGGER_UI_URL = SWAGGER_UI_PREFIX + INDEX_PAGE;
195190

191+
/**
192+
* The constant SWAGGER_INITIALIZER_JS.
193+
*/
194+
public static final String SWAGGER_INITIALIZER_JS = "swagger-initializer.js";
195+
196+
/**
197+
* The constant SWAGGER_INITIALIZER_URL.
198+
*/
199+
public static final String SWAGGER_INITIALIZER_URL = SWAGGER_UI_PREFIX + "/" + SWAGGER_INITIALIZER_JS;
200+
196201
/**
197202
* The constant SWAGGER_UI_OAUTH_REDIRECT_URL.
198203
*/

springdoc-openapi-starter-common/src/main/java/org/springdoc/ui/AbstractSwaggerIndexTransformer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ public AbstractSwaggerIndexTransformer(SwaggerUiConfigProperties swaggerUiConfig
9494
* @throws JsonProcessingException the json processing exception
9595
*/
9696
protected String addInitOauth(String html) throws JsonProcessingException {
97-
StringBuilder stringBuilder = new StringBuilder("window.ui = ui\n");
97+
StringBuilder stringBuilder = new StringBuilder(" });\n");
9898
stringBuilder.append("ui.initOAuth(\n");
9999
String json = objectMapper.writeValueAsString(swaggerUiOAuthProperties.getConfigParameters());
100100
stringBuilder.append(json);
101101
stringBuilder.append(")");
102-
return html.replace("window.ui = ui", stringBuilder.toString());
102+
return html.replace(" });", stringBuilder.toString());
103103
}
104104

105105
/**
@@ -197,9 +197,9 @@ protected String addParameters(String html) throws JsonProcessingException {
197197
}
198198

199199
private String addParameter(String html, String key, String value) {
200-
StringBuilder stringBuilder = new StringBuilder("const ui = SwaggerUIBundle({\n");
200+
StringBuilder stringBuilder = new StringBuilder("window.ui = SwaggerUIBundle({\n");
201201
stringBuilder.append(key + ": \"" + value + "\",");
202-
return html.replace("const ui = SwaggerUIBundle({", stringBuilder.toString());
202+
return html.replace("window.ui = SwaggerUIBundle({", stringBuilder.toString());
203203
}
204204

205205
/**

springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerIndexPageTransformer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import org.springframework.web.reactive.resource.TransformedResource;
3636
import org.springframework.web.server.ServerWebExchange;
3737

38+
import static org.springdoc.core.utils.Constants.SWAGGER_INITIALIZER_JS;
39+
3840
/**
3941
* The type Swagger index transformer.
4042
* @author bnasslahsen
@@ -65,7 +67,7 @@ public Mono<Resource> transform(ServerWebExchange serverWebExchange, Resource re
6567

6668
final AntPathMatcher antPathMatcher = new AntPathMatcher();
6769
try {
68-
boolean isIndexFound = antPathMatcher.match("**/swagger-ui/**/index.html", resource.getURL().toString());
70+
boolean isIndexFound = antPathMatcher.match("**/swagger-ui/**/" + SWAGGER_INITIALIZER_JS, resource.getURL().toString());
6971
if (isIndexFound) {
7072
String html = defaultTransformations(resource.getInputStream());
7173
return Mono.just(new TransformedResource(resource, html.getBytes()));

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ public abstract class AbstractSpringDocTest extends AbstractCommonTest {
4444
@Autowired
4545
protected WebTestClient webTestClient;
4646

47-
private static final String DEFAULT_SWAGGER_UI_URL= Constants.DEFAULT_WEB_JARS_PREFIX_URL + Constants.SWAGGER_UI_URL;
47+
private static final String DEFAULT_SWAGGER_INITIALIZER_URL= Constants.DEFAULT_WEB_JARS_PREFIX_URL + Constants.SWAGGER_INITIALIZER_URL;
4848

49-
protected void checkHTML(String fileName, String uri) {
49+
protected void checkJS(String fileName, String uri) {
5050
EntityExchangeResult<byte[]> getResult = webTestClient.get().uri(uri)
5151
.exchange()
5252
.expectStatus().isOk()
5353
.expectBody().returnResult();
54-
checkHTMLResult(fileName, new String(getResult.getResponseBody()));
54+
checkJSResult(fileName, new String(getResult.getResponseBody()));
5555
}
5656

57-
protected void checkHTMLResult(String fileName, String result) {
58-
assertTrue(result.contains("Swagger UI"));
57+
protected void checkJSResult(String fileName, String result) {
58+
assertTrue(result.contains("window.ui"));
5959
String expected = getContent("results/" + fileName);
6060
assertEquals(expected, result.replace("\r", ""));
6161
}
6262

63-
protected void checkHTML(String fileName) {
64-
checkHTML(fileName, DEFAULT_SWAGGER_UI_URL);
63+
protected void checkJS(String fileName) {
64+
checkJS(fileName, DEFAULT_SWAGGER_INITIALIZER_URL);
6565
}
6666
}

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirecFilterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void shouldRedirectWithConfigUrlIgnoringQueryParams() {
3737
.expectStatus().isFound();
3838
responseSpec.expectHeader()
3939
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
40-
super.checkHTML("index1-filter");
40+
super.checkJS("index1-filter");
4141
}
4242

4343
@SpringBootApplication

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectConfigUrlTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void shouldRedirectWithConfigUrlIgnoringQueryParams() {
4141
responseSpec.expectHeader()
4242
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
4343

44-
super.checkHTML("index1-configurl");
44+
super.checkJS("index1-configurl");
4545
}
4646

4747
@SpringBootApplication

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectDefaultTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void shouldRedirectWithDefaultQueryParams() {
3838
webTestClient.get().uri("/v3/api-docs/swagger-config").exchange()
3939
.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("");
4040

41-
super.checkHTML("index1-default");
41+
super.checkJS("index1-default");
4242
}
4343

4444
@SpringBootApplication

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectLayoutTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void shouldRedirectWithConfigUrlIgnoringQueryParams() {
3838
responseSpec.expectHeader()
3939
.value("Location", Matchers.is("/webjars/swagger-ui/index.html"));
4040

41-
super.checkHTML("index1-layout");
41+
super.checkJS("index1-layout");
4242
}
4343

4444
@SpringBootApplication

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app1/SpringDocApp1RedirectWithConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void shouldRedirectWithConfiguredParams() {
4343
webTestClient.get().uri("/baf/batz/swagger-config").exchange()
4444
.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("/foo/validate");
4545

46-
super.checkHTML("index1");
46+
super.checkJS("index1");
4747
}
4848

4949
@SpringBootApplication

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app3/SpringDocApp3RedirectDefaultTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.hamcrest.Matchers;
2222
import org.junit.jupiter.api.Test;
23+
import org.springdoc.core.utils.Constants;
2324
import test.org.springdoc.ui.AbstractSpringDocTest;
2425

2526
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -45,7 +46,7 @@ public void shouldRedirectWithDefaultQueryParams() {
4546
.jsonPath("$.validatorUrl").isEqualTo("")
4647
.jsonPath("$.oauth2RedirectUrl").isEqualTo("/documentation/webjars/swagger-ui/oauth2-redirect.html");
4748

48-
super.checkHTML("index3", "/documentation/webjars/swagger-ui/index.html");
49+
super.checkJS("index3", "/documentation/webjars"+ Constants.SWAGGER_INITIALIZER_URL);
4950
}
5051

5152
@SpringBootApplication

0 commit comments

Comments
 (0)