From 5cc4c48695c58752b764208caa82b0f2db7c6055 Mon Sep 17 00:00:00 2001 From: davidtrafela Date: Wed, 29 Nov 2023 11:03:17 +0100 Subject: [PATCH] Added support for Java 21, migrated to Jakarta namespace, updated versions of dependencies to latest --- common/pom.xml | 2 +- core/pom.xml | 14 +++-- .../ee/openapi/mp/OpenApiMPServlet.java | 8 +-- .../ee/openapi/mp/OpenApiMpExtension.java | 14 ++--- .../ee/openapi/DependencyAppender.java | 6 +- .../ee/openapi/tests/AcceptHeaderTest.java | 22 +++---- .../kumuluzee/openapi/versions.properties | 3 +- pom.xml | 49 +++++++-------- tools/maven-plugin/pom.xml | 2 +- .../openapi/mp/mavenplugin/MavenConfig.java | 59 ++++--------------- tools/pom.xml | 2 +- ui/pom.xml | 2 +- .../mp/ui/filters/SwaggerUIFilter.java | 12 ++-- .../ee/openapi/mp/ui/servlets/UiServlet.java | 3 +- .../SwaggerUIFilterAutoConfigTest.java | 6 +- 15 files changed, 89 insertions(+), 115 deletions(-) diff --git a/common/pom.xml b/common/pom.xml index b14cf8b..8bf9b45 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ kumuluzee-openapi-mp-parent com.kumuluz.ee.openapi - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT 4.0.0 diff --git a/core/pom.xml b/core/pom.xml index 48a39e1..108b931 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ kumuluzee-openapi-mp-parent com.kumuluz.ee.openapi - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT 4.0.0 @@ -53,9 +53,15 @@ - javax.xml.bind - jaxb-api - ${jaxb-api.version} + jakarta.xml.bind + jakarta.xml.bind-api + ${jakarta-xml-bind-api.version} + + + com.sun.xml.bind + jaxb-impl + ${jaxb-impl.version} + runtime diff --git a/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMPServlet.java b/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMPServlet.java index 7f89030..7c94620 100644 --- a/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMPServlet.java +++ b/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMPServlet.java @@ -24,11 +24,11 @@ import io.smallrye.openapi.api.OpenApiDocument; import io.smallrye.openapi.runtime.io.Format; import io.smallrye.openapi.runtime.io.OpenApiSerializer; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; diff --git a/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMpExtension.java b/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMpExtension.java index 58fc404..0e9999a 100644 --- a/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMpExtension.java +++ b/core/src/main/java/com/kumuluz/ee/openapi/mp/OpenApiMpExtension.java @@ -49,13 +49,11 @@ import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.ServiceLoader; +import java.util.Set; import java.util.logging.Logger; -import java.util.regex.Pattern; -import java.util.stream.Collectors; /** * MicroProfile OpenAPI extension. @@ -233,18 +231,18 @@ public boolean isEnabled() { .orElse(true)); } - private String[] patternToStringArray(Pattern pattern) { + private String[] patternToStringArray(Set pattern) { if (pattern == null) { - return new String[] {}; + return new String[]{}; } - return Arrays.stream(pattern.pattern().split("\\|")) + return pattern.stream() .map(s -> s.replaceAll("\\(", "")) .map(s -> s.replaceAll("\\)", "")) .map(s -> s.replaceAll("\\\\Q", "")) .map(s -> s.replaceAll("\\\\E", "")) .filter(s -> !s.isEmpty()) - .collect(Collectors.toList()) - .toArray(new String[] {}); + .toList() + .toArray(new String[]{}); } } diff --git a/core/src/test/java/com/kumuluz/ee/openapi/DependencyAppender.java b/core/src/test/java/com/kumuluz/ee/openapi/DependencyAppender.java index a3f4815..c86e4ba 100644 --- a/core/src/test/java/com/kumuluz/ee/openapi/DependencyAppender.java +++ b/core/src/test/java/com/kumuluz/ee/openapi/DependencyAppender.java @@ -48,8 +48,10 @@ public List addLibraries() { versionsBundle.getString("smallrye-open-api.version")); libs.add("io.github.classgraph:classgraph:" + versionsBundle.getString("classgraph.version")); - libs.add("javax.xml.bind:jaxb-api:" + - versionsBundle.getString("jaxb-api.version")); + libs.add("com.sun.xml.bind:jaxb-impl:" + + versionsBundle.getString("jaxb-impl.version")); + libs.add("jakarta.xml.bind:jakarta.xml.bind-api:" + + versionsBundle.getString("jakarta-xml-bind-api.version")); libs.add("com.beust:jcommander:" + versionsBundle.getString("jcommander.version")); diff --git a/core/src/test/java/com/kumuluz/ee/openapi/tests/AcceptHeaderTest.java b/core/src/test/java/com/kumuluz/ee/openapi/tests/AcceptHeaderTest.java index cdb403e..8939a3b 100644 --- a/core/src/test/java/com/kumuluz/ee/openapi/tests/AcceptHeaderTest.java +++ b/core/src/test/java/com/kumuluz/ee/openapi/tests/AcceptHeaderTest.java @@ -21,6 +21,7 @@ package com.kumuluz.ee.openapi.tests; import io.restassured.RestAssured; +import jakarta.ws.rs.core.MediaType; import org.hamcrest.Matcher; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; @@ -31,7 +32,6 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.ws.rs.core.MediaType; import java.util.regex.Pattern; import static io.restassured.RestAssured.given; @@ -66,9 +66,9 @@ private Matcher isYaml() { public void acceptNoHeaderTest() { given() .noFilters() - .when() + .when() .get("/openapi") - .then() + .then() .log().ifValidationFails() .statusCode(200) .body(isYaml()); @@ -80,9 +80,9 @@ public void acceptYamlTest() { given() .noFilters() .header("Accept", "text/yaml") - .when() + .when() .get("/openapi") - .then() + .then() .log().ifValidationFails() .statusCode(200) .body(isYaml()); @@ -94,9 +94,9 @@ public void acceptJsonTest() { given() .noFilters() .header("Accept", MediaType.APPLICATION_JSON) - .when() + .when() .get("/openapi") - .then() + .then() .log().ifValidationFails() .statusCode(200) .body("openapi", matchesPattern("3\\.\\d+\\.\\d+")); @@ -108,9 +108,9 @@ public void acceptJsonFormatOverrideYamlTest() { given() .noFilters() .header("Accept", MediaType.APPLICATION_JSON) - .when() + .when() .get("/openapi?format=yaml") - .then() + .then() .log().ifValidationFails() .statusCode(200) .body(isYaml()); @@ -122,9 +122,9 @@ public void acceptYamlFormatOverrideJsonTest() { given() .noFilters() .header("Accept", "text/yaml") - .when() + .when() .get("/openapi?format=json") - .then() + .then() .log().ifValidationFails() .statusCode(200) .body("openapi", matchesPattern("3\\.\\d+\\.\\d+")); diff --git a/core/src/test/resources/META-INF/kumuluzee/openapi/versions.properties b/core/src/test/resources/META-INF/kumuluzee/openapi/versions.properties index 4e902ef..4d4d09c 100644 --- a/core/src/test/resources/META-INF/kumuluzee/openapi/versions.properties +++ b/core/src/test/resources/META-INF/kumuluzee/openapi/versions.properties @@ -1,5 +1,6 @@ kumuluzee-config-mp.version=${kumuluzee-config-mp.version} smallrye-open-api.version=${smallrye-open-api.version} classgraph.version=${classgraph.version} -jaxb-api.version=${jaxb-api.version} +jaxb-impl.version=${jaxb-impl.version} +jakarta-xml-bind-api.version=${jakarta-xml-bind-api.version} jcommander.version=${jcommander.version} diff --git a/pom.xml b/pom.xml index f15d46a..f226448 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.kumuluz.ee.openapi kumuluzee-openapi-mp-parent pom - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT core ui @@ -25,37 +25,38 @@ https://ee.kumuluz.com - 11 - 11 + 21 + 21 UTF-8 - 2.3.1 + 4.0.1 + 4.0.4 - 4.1.0-SNAPSHOT - 2.0.0-SNAPSHOT - 1.1.1 + 5.0.0-SNAPSHOT + 3.0.0-SNAPSHOT + 2.0.0-SNAPSHOT - 2.0.1 - 2.1.22 - 4.8.147 - 3.52.5 - 3.8.5 + 3.1.1 + 3.7.0 + 4.8.164 + 5.9.4 + 3.9.5 - 6.14.3 - 1.6.0.Final - 3.12.4 - 3.23.1 + 7.8.0 + 1.8.0.Final + 5.7.0 + 3.24.2 1.82 - 3.10.1 - 1.6.8 - 1.6 - 2.22.1 - 3.2.0 - 1.6.8 - 3.6.4 + 3.11.0 + 1.6.13 + 3.1.0 + 3.2.2 + 3.3.1 + 1.7.1 + 3.10.2 - 29.0-jre + 32.1.3-jre diff --git a/tools/maven-plugin/pom.xml b/tools/maven-plugin/pom.xml index 9abd91c..6dab11e 100644 --- a/tools/maven-plugin/pom.xml +++ b/tools/maven-plugin/pom.xml @@ -5,7 +5,7 @@ kumuluzee-openapi-mp-tools com.kumuluz.ee.openapi - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT 4.0.0 diff --git a/tools/maven-plugin/src/main/java/com/kumuluz/ee/openapi/mp/mavenplugin/MavenConfig.java b/tools/maven-plugin/src/main/java/com/kumuluz/ee/openapi/mp/mavenplugin/MavenConfig.java index d15dcae..d0a42c7 100644 --- a/tools/maven-plugin/src/main/java/com/kumuluz/ee/openapi/mp/mavenplugin/MavenConfig.java +++ b/tools/maven-plugin/src/main/java/com/kumuluz/ee/openapi/mp/mavenplugin/MavenConfig.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.Set; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.regex.Pattern; import org.eclipse.microprofile.openapi.OASConfig; @@ -42,53 +44,28 @@ public MavenConfig(Map properties) { } @Override - public String modelReader() { - return properties.getOrDefault(OASConfig.MODEL_READER, null); - } - - @Override - public String filter() { - return properties.getOrDefault(OASConfig.FILTER, null); - } - - @Override - public boolean scanDisable() { - return Boolean.parseBoolean(properties.getOrDefault(OASConfig.SCAN_DISABLE, "false")); - } - - @Override - public Pattern scanPackages() { - return patternOf(properties.getOrDefault(OASConfig.SCAN_PACKAGES, null)); - } - - @Override - public Pattern scanClasses() { - return patternOf(properties.getOrDefault(OASConfig.SCAN_CLASSES, null)); - } - - @Override - public Pattern scanExcludePackages() { - return patternOf(properties.getOrDefault(OASConfig.SCAN_EXCLUDE_PACKAGES, null), OpenApiConstants.NEVER_SCAN_PACKAGES); + public T getConfigValue(String s, Class aClass, Function function, Supplier supplier) { + return null; } @Override - public Pattern scanExcludeClasses() { - return patternOf(properties.getOrDefault(OASConfig.SCAN_EXCLUDE_CLASSES, null), OpenApiConstants.NEVER_SCAN_CLASSES); + public Map getConfigValueMap(String s, Class aClass, Function function) { + return null; } @Override - public Set servers() { - return asCsvSet(properties.getOrDefault(OASConfig.SERVERS, null)); + public String modelReader() { + return properties.getOrDefault(OASConfig.MODEL_READER, null); } @Override - public Set pathServers(String path) { - return asCsvSet(properties.getOrDefault(OASConfig.SERVERS_PATH_PREFIX + path, null)); + public String filter() { + return properties.getOrDefault(OASConfig.FILTER, null); } @Override - public Set operationServers(String operationId) { - return asCsvSet(properties.getOrDefault(OASConfig.SERVERS_OPERATION_PREFIX + operationId, null)); + public boolean scanDisable() { + return Boolean.parseBoolean(properties.getOrDefault(OASConfig.SCAN_DISABLE, "false")); } @Override @@ -96,11 +73,6 @@ public boolean scanDependenciesDisable() { return Boolean.parseBoolean(properties.getOrDefault(OpenApiConstants.SMALLRYE_SCAN_DEPENDENCIES_DISABLE, "false")); } - @Override - public Set scanDependenciesJars() { - return asCsvSet(properties.getOrDefault(OpenApiConstants.SMALLRYE_SCAN_DEPENDENCIES_JARS, null)); - } - @Override public String customSchemaRegistryClass() { return properties.getOrDefault(OpenApiConstants.SMALLRYE_CUSTOM_SCHEMA_REGISTRY_CLASS, null); @@ -171,12 +143,7 @@ public OperationIdStrategy getOperationIdStrategy() { } @Override - public Set getScanProfiles() { - return asCsvSet(properties.getOrDefault(OpenApiConstants.SCAN_PROFILES, null)); - } + public void setAllowNakedPathParameter(Boolean aBoolean) { - @Override - public Set getScanExcludeProfiles() { - return asCsvSet(properties.getOrDefault(OpenApiConstants.SCAN_EXCLUDE_PROFILES, null)); } } diff --git a/tools/pom.xml b/tools/pom.xml index a1ca4a0..ceba529 100644 --- a/tools/pom.xml +++ b/tools/pom.xml @@ -5,7 +5,7 @@ kumuluzee-openapi-mp-parent com.kumuluz.ee.openapi - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT 4.0.0 diff --git a/ui/pom.xml b/ui/pom.xml index 5c5ed4c..edd4e22 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -5,7 +5,7 @@ kumuluzee-openapi-mp-parent com.kumuluz.ee.openapi - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT 4.0.0 diff --git a/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilter.java b/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilter.java index c8ad22e..a7a0721 100644 --- a/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilter.java +++ b/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilter.java @@ -23,14 +23,14 @@ import com.google.common.annotations.VisibleForTesting; import com.kumuluz.ee.configuration.utils.ConfigurationUtil; import io.smallrye.openapi.api.OpenApiDocument; +import jakarta.annotation.Nullable; +import jakarta.servlet.*; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.Request; import org.eclipse.microprofile.openapi.models.OpenAPI; import org.eclipse.microprofile.openapi.models.servers.Server; -import javax.annotation.Nullable; -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URI; import java.util.*; @@ -79,7 +79,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; - String path = httpServletRequest.getContextPath()+httpServletRequest.getServletPath(); + String path = httpServletRequest.getContextPath() + httpServletRequest.getServletPath(); // check if request is for UI if (path.contains(uiPath)) { @@ -119,7 +119,7 @@ private String createRedirectPathFromRequest(HttpServletRequest httpServletReque return rootPath + uiPath + URL_QUERY + rootUrl + specPath + OAUTH_QUERY + rootUrl + uiPath + OAUTH_HTML_PAGE; } catch (Exception e) { LOG.warning("Failed to dynamically resolve redirect from request header, " + - "falling back to static configuration. Reason of failure: " + e.getMessage()); + "falling back to static configuration. Reason of failure: " + e.getMessage()); return getStaticRedirect(); } } diff --git a/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/servlets/UiServlet.java b/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/servlets/UiServlet.java index 15fce4a..b24442b 100644 --- a/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/servlets/UiServlet.java +++ b/ui/src/main/java/com/kumuluz/ee/openapi/mp/ui/servlets/UiServlet.java @@ -20,13 +20,12 @@ */ package com.kumuluz.ee.openapi.mp.ui.servlets; +import jakarta.servlet.UnavailableException; import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; -import javax.servlet.UnavailableException; - /** * Static file server for Swagger UI, modified to remove relative UI path when looking for resources. * diff --git a/ui/src/test/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilterAutoConfigTest.java b/ui/src/test/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilterAutoConfigTest.java index 998a2c8..88955e8 100644 --- a/ui/src/test/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilterAutoConfigTest.java +++ b/ui/src/test/java/com/kumuluz/ee/openapi/mp/ui/filters/SwaggerUIFilterAutoConfigTest.java @@ -1,6 +1,9 @@ package com.kumuluz.ee.openapi.mp.ui.filters; import com.kumuluz.ee.configuration.utils.ConfigurationUtil; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.Request; import org.eclipse.microprofile.openapi.models.OpenAPI; import org.eclipse.microprofile.openapi.models.servers.Server; @@ -11,9 +14,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; import java.util.Optional;