Skip to content
Closed
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.6</version>
<version>2.2.0</version>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Dependency version downgrade confirmed as necessary

The downgrade from 2.8.6 to 2.2.0 for springdoc-openapi-starter-webmvc-ui addresses the runtime NoClassDefFoundError for LiteWebJarsResourceResolver mentioned in the PR objectives.


🌐 Web query:

Are there any known issues or compatibility problems with springdoc-openapi-starter-webmvc-ui version 2.2.0 when used with Spring Boot 3.1.8?

💡 Result:

Yes, there are known compatibility issues with springdoc-openapi-starter-webmvc-ui 2.2.0 when used with Spring Boot 3.1.8:


1. Multipart Request Content-Type Support

  • Version 2.2.0 uses an outdated swagger-ui dependency (5.2.0), which lacks support for boundary-specific Content-Type headers in multipart requests[2][8]. This prevents proper rendering of multipart endpoints in Swagger UI.
  • Fix: Upgrade to a newer springdoc-openapi version (≥2.7.0), which includes swagger-ui 5.4.2+[2][6].

2. Parameter Name Discovery Issues

  • Spring Boot 3.2.0+ introduced changes affecting parameter name resolution, but similar issues may arise in earlier versions if the -parameters compiler flag is missing[1][3]. This can cause parameters to be incorrectly marked as required or omitted.
  • Mitigation: Add the -parameters flag to the Maven/Gradle compiler plugin[1]:
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <parameters>true</parameters>
      </configuration>
    </plugin>

3. Dependency Vulnerabilities

  • Version 2.2.0 includes dependencies with critical vulnerabilities (e.g., spring-webmvc, spring-security-config)[5][8]. These expose risks like path traversal and improper access control.
  • Recommendation: Upgrade to the latest stable springdoc-openapi version (2.8.6) and ensure Spring Boot dependencies are updated to patched versions (e.g., Spring Boot 3.2.10)[5][6].

4. Jakarta EE Compatibility

  • While Spring Boot 3.1.x uses Jakarta EE 9+, older springdoc-openapi versions may require manual adjustments for imports (e.g., replacing javax with jakarta)[6]. Version 2.2.0 generally handles this correctly but may conflict with non-updated dependencies.

Recommended Upgrade Path

  • Use springdoc-openapi-starter-webmvc-ui ≥2.8.6 with Spring Boot 3.1.8 for full compatibility and security fixes[1][4].
  • Update webjars/swagger-ui to 5.20.3+ to resolve multipart issues[8].

For migration steps, see the Spring Boot 3 migration guide[6].

Citations:


Action Required: Revisit Dependency Version for springdoc-openapi-starter-webmvc-ui

While the downgrade to version 2.2.0 was originally applied to work around the NoClassDefFoundError for LiteWebJarsResourceResolver, recent findings show that springdoc-openapi-starter-webmvc-ui 2.2.0 has several compatibility issues with Spring Boot 3.1.8. In particular, it suffers from:

  • Multipart Request Issues: Uses an outdated swagger-ui (5.2.0) that does not support boundary-specific Content-Type headers for multipart requests.
  • Parameter Name Discovery Problems: Potential misidentification of required parameters if the -parameters compiler flag is not enabled.
  • Dependency Vulnerabilities: Critical vulnerabilities in some of its transitive dependencies (e.g., spring-webmvc, spring-security-config).
  • Jakarta EE Compatibility Concerns: Although generally handling package changes, it may require additional adjustments in certain cases.

Recommendation:
- Instead of downgrading to 2.2.0, consider retaining or upgrading to version ≥2.8.6, which addresses the runtime error while ensuring better compatibility with Spring Boot 3.1.8.
- Additionally, verify that the Maven compiler plugin is set to use the -parameters flag for proper parameter name resolution.

Diff Snapshot:

            <version>2.2.0</version>

Please review these points and update the dependency version accordingly to avoid the highlighted compatibility issues.

</dependency>
<!--
Spring Boot Starter Actuator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package ar.com.nanotaboada.java.samples.spring.boot.listeners;

import java.awt.Desktop;
import java.net.URI;
import java.util.Arrays;
import java.awt.GraphicsEnvironment;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("local")


public class SwaggerUiOpener implements ApplicationListener<ApplicationReadyEvent>{
private static final Logger log = LoggerFactory.getLogger(SwaggerUiOpener.class);

@Value("${server.port}")
private int port;

@Value("${springdoc.swagger-ui.path:/swagger/index.html}")
private String swaggerPath;

@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed.

String url = "http://localhost:" + port + swaggerPath;
log.info("✅ Swagger UI will open at: {}", url);

try {
if (Desktop.isDesktopSupported() && !GraphicsEnvironment.isHeadless()) {
Desktop.getDesktop().browse(new URI(url));
} else {
launchBrowserByOS(url);
}
} catch (Exception e) {
log.error("❌ Failed to open Swagger UI", e);
}
}

private void launchBrowserByOS(String url) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method launchBrowserByOS has 31 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method launchBrowserByOS has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.

String os = System.getProperty("os.name").toLowerCase();
try {
if (os.contains("win")) {
new ProcessBuilder("rundll32", "url.dll,FileProtocolHandler", url).start();
} else if (os.contains("mac")) {
new ProcessBuilder("open", url).start();
} else if (os.contains("nix") || os.contains("nux")) {
boolean launched = false;
for (String browser : Arrays.asList("xdg-open", "google-chrome", "firefox")) {
Process process = new ProcessBuilder("which", browser).start();
try {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this nested try block into a separate method.

int exitCode = process.waitFor();
if (exitCode == 0) {
new ProcessBuilder(browser, url).start();
launched = true;
break;
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
log.warn("Browser detection was interrupted", ie);
}
}
if (!launched) {
log.warn("⚠️ No supported browser found to open Swagger.");
}
} else {
log.warn("⚠️ Unsupported OS for automatic browser launch.");
}
} catch (Exception e) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.

log.error("❌ Error while launching browser", e);
}
}
Comment on lines +46 to +78
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify OS detection & browser launch logic.

The method contains nested conditionals, a for-loop over possible Linux browsers, and multiple error-handling blocks, which can inflate its overall complexity. Consider splitting it into separate helper methods (e.g., one for detecting the operating system, another for launching a given browser). This modular approach can reduce complexity and improve testability.

}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ info.app.description=Proof of Concept for a RESTful Web Service made with Spring

springdoc.api-docs.path=/docs
springdoc.swagger-ui.path=/swagger/index.html

spring.profiles.active=local