Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AbstractSwaggerResourceResolver(SwaggerUiConfigProperties swaggerUiConfig
@Nullable
protected String findWebJarResourcePath(String path) {
String webjar = webjar(path);
if (webjar.length() > 0) {
if (webjar.length() > 0 && !path.equals(webjar)) {
String version = swaggerUiConfigProperties.getVersion();
if (version != null) {
String partialPath = path(webjar, path);
Expand Down Expand Up @@ -67,9 +67,9 @@ private String webjar(String path) {
* @return the string
*/
private String path(String webjar, String path) {
if (path.startsWith(webjar)) {
if (path.startsWith(webjar) && path.length() > webjar.length()) {
path = path.substring(webjar.length() + 1);
}
return path;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.springdoc.ui;

import java.util.Objects;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springdoc.core.properties.SwaggerUiConfigProperties;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class AbstractSwaggerResourceResolverTest {
private SwaggerUiConfigProperties swaggerUiConfigProperties;

private AbstractSwaggerResourceResolver abstractSwaggerResourceResolver;

private final String VERSION = "4.18.2";

@BeforeEach
public void setup(){
swaggerUiConfigProperties = new SwaggerUiConfigProperties();
swaggerUiConfigProperties.setVersion(VERSION);
abstractSwaggerResourceResolver = new AbstractSwaggerResourceResolver(swaggerUiConfigProperties);
}

@Test
void findWebJarResourcePath() {
String path = "swagger-ui/swagger-initializer.js";

String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path);
assertEquals("swagger-ui/4.18.2/swagger-initializer.js", actual);
}

@Test
void returNullWhenPathIsSameAsWebjar() {
String path = "swagger-ui";

String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path);
assertTrue(Objects.isNull(actual));
}

@Test
void returNullWhenVersionIsNull() {
String path = "swagger-ui/swagger-initializer.js";
swaggerUiConfigProperties.setVersion(null);

String actual = abstractSwaggerResourceResolver.findWebJarResourcePath(path);
assertTrue(Objects.isNull(actual));
}
}