You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2024/08/30 05:49:24 UTC

(pinot) branch master updated: Remove Hardcoded Swagger Version (#13917)

This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new e14d887a7e Remove Hardcoded Swagger Version (#13917)
e14d887a7e is described below

commit e14d887a7e445947080b1f54c61b1397ef5c38e1
Author: Ankit Sultana <an...@uber.com>
AuthorDate: Fri Aug 30 00:49:18 2024 -0500

    Remove Hardcoded Swagger Version (#13917)
---
 .../pinot/common/swagger/SwaggerSetupUtils.java    | 26 +++++++++++++++++++++-
 .../apache/pinot/spi/utils/CommonConstants.java    |  3 ++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/pinot-common/src/main/java/org/apache/pinot/common/swagger/SwaggerSetupUtils.java b/pinot-common/src/main/java/org/apache/pinot/common/swagger/SwaggerSetupUtils.java
index 30e30b49f4..ae97abff6c 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/swagger/SwaggerSetupUtils.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/swagger/SwaggerSetupUtils.java
@@ -19,8 +19,12 @@
 package org.apache.pinot.common.swagger;
 
 import io.swagger.jaxrs.config.BeanConfig;
+import java.io.InputStream;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Objects;
+import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.pinot.common.utils.PinotStaticHttpHandler;
 import org.apache.pinot.spi.utils.CommonConstants;
 import org.glassfish.grizzly.http.server.CLStaticHttpHandler;
@@ -53,8 +57,28 @@ public class SwaggerSetupUtils {
     // map both /api and /help to swagger docs. /api because it looks nice. /help for backward compatibility
     httpServer.getServerConfiguration().addHttpHandler(staticHttpHandler, "/api/", "/help/");
 
-    URL swaggerDistLocation = classLoader.getResource(CommonConstants.CONFIG_OF_SWAGGER_RESOURCES_PATH);
+    String swaggerVersion = findSwaggerVersion(classLoader);
+    URL swaggerDistLocation = classLoader.getResource(
+            CommonConstants.CONFIG_OF_SWAGGER_RESOURCES_PATH + swaggerVersion + "/");
     CLStaticHttpHandler swaggerDist = new PinotStaticHttpHandler(new URLClassLoader(new URL[]{swaggerDistLocation}));
     httpServer.getServerConfiguration().addHttpHandler(swaggerDist, "/swaggerui-dist/");
   }
+
+  private static String findSwaggerVersion(ClassLoader classLoader) {
+    try {
+      Properties pomProperties = new Properties();
+      InputStream inputStream = Objects.requireNonNull(
+              classLoader.getResourceAsStream(CommonConstants.SWAGGER_POM_PROPERTIES_PATH),
+              "Unable to find pom properties file: " + CommonConstants.SWAGGER_POM_PROPERTIES_PATH);
+      pomProperties.load(inputStream);
+      String version = pomProperties.getProperty("version");
+      if (StringUtils.isEmpty(version)) {
+        throw new IllegalStateException("Unable to find version in swagger pom properties file. Available keys: "
+                + pomProperties.keySet());
+      }
+      return version;
+    } catch (Exception e) {
+      throw new RuntimeException("Error finding swagger version", e);
+    }
+  }
 }
diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
index c1c4dbce49..eb98800591 100644
--- a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java
@@ -52,7 +52,8 @@ public class CommonConstants {
       "org.apache.pinot.spi.eventlistener.query.NoOpBrokerQueryEventListener";
 
   public static final String SWAGGER_AUTHORIZATION_KEY = "oauth";
-  public static final String CONFIG_OF_SWAGGER_RESOURCES_PATH = "META-INF/resources/webjars/swagger-ui/5.17.14/";
+  public static final String SWAGGER_POM_PROPERTIES_PATH = "META-INF/maven/org.webjars/swagger-ui/pom.properties";
+  public static final String CONFIG_OF_SWAGGER_RESOURCES_PATH = "META-INF/resources/webjars/swagger-ui/";
   public static final String CONFIG_OF_TIMEZONE = "pinot.timezone";
 
   public static final String DATABASE = "database";


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org