You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by he...@apache.org on 2023/05/03 17:55:40 UTC

[incubator-devlake] branch main updated: fix: Correct Swagger spec template path discovery (#5078)

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

hez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new d78022c28 fix: Correct Swagger spec template path discovery (#5078)
d78022c28 is described below

commit d78022c28e51e583448a09f29af6e90dedd24b02
Author: Keon Amini <ke...@merico.dev>
AuthorDate: Wed May 3 12:55:29 2023 -0500

    fix: Correct Swagger spec template path discovery (#5078)
    
    * fix: Correct Swagger spec template path discovery
    
    * fix: removed unneeded init function
---
 backend/Dockerfile                                        |  4 ++--
 backend/core/config/config_viper.go                       |  1 +
 .../doc => resources/swagger}/open_api_spec.json.tmpl     |  0
 backend/server/services/remote/plugin/doc/open_api.go     | 15 +++++++--------
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/backend/Dockerfile b/backend/Dockerfile
index f388457a9..99b8c7955 100644
--- a/backend/Dockerfile
+++ b/backend/Dockerfile
@@ -142,7 +142,7 @@ RUN python3 -m pip install --no-cache --upgrade pip setuptools && \
 RUN curl -sSL https://install.python-poetry.org | python3 -
 RUN ln -sf /root/.local/bin/poetry /usr/local/bin
 # Build Python plugins
-RUN find /app/python/ -name "*.sh" | xargs -I{} chmod +x {} 
+RUN find /app/python/ -name "*.sh" | xargs -I{} chmod +x {}
 RUN /app/python/build.sh
 
 
@@ -156,7 +156,7 @@ RUN ldconfig -vn /app/libs
 
 # apps
 COPY --from=build /app/bin /app/bin
-COPY --from=build /app/resources/tap /app/resources/tap
+COPY --from=build /app/resources /app/resources
 
 ENV PATH="/app/bin:${PATH}"
 
diff --git a/backend/core/config/config_viper.go b/backend/core/config/config_viper.go
index c05165b57..4302f2d7a 100644
--- a/backend/core/config/config_viper.go
+++ b/backend/core/config/config_viper.go
@@ -76,6 +76,7 @@ func setDefaultValue(v *viper.Viper) {
 	v.SetDefault("TEMPORAL_TASK_QUEUE", "DEVLAKE_TASK_QUEUE")
 	v.SetDefault("TAP_PROPERTIES_DIR", "resources/tap")
 	v.SetDefault("REMOTE_PLUGIN_DIR", "python/plugins")
+	v.SetDefault("SWAGGER_DOCS_DIR", "resources/swagger")
 }
 
 // replaceNewEnvItemInOldContent replace old config to new config in env file content
diff --git a/backend/server/services/remote/plugin/doc/open_api_spec.json.tmpl b/backend/resources/swagger/open_api_spec.json.tmpl
similarity index 100%
rename from backend/server/services/remote/plugin/doc/open_api_spec.json.tmpl
rename to backend/resources/swagger/open_api_spec.json.tmpl
diff --git a/backend/server/services/remote/plugin/doc/open_api.go b/backend/server/services/remote/plugin/doc/open_api.go
index 811c19309..1d0e2db7c 100644
--- a/backend/server/services/remote/plugin/doc/open_api.go
+++ b/backend/server/services/remote/plugin/doc/open_api.go
@@ -19,10 +19,10 @@ package doc
 
 import (
 	"encoding/json"
+	"github.com/apache/incubator-devlake/core/config"
 	"io"
 	"os"
-	"path"
-	"runtime"
+	"path/filepath"
 	"strings"
 	"text/template"
 
@@ -62,7 +62,11 @@ func GenerateOpenApiSpec(pluginInfo *models.PluginInfo) (*string, errors.Error)
 }
 
 func specTemplate() (*template.Template, errors.Error) {
-	file, err := os.Open(specTemplatePath())
+	path := config.GetConfig().GetString("SWAGGER_DOCS_DIR")
+	if path == "" {
+		return nil, errors.Default.New("path for Swagger docs resources is not set")
+	}
+	file, err := os.Open(filepath.Join(path, "open_api_spec.json.tmpl"))
 	if err != nil {
 		return nil, errors.Default.Wrap(err, "could not open swagger doc template")
 	}
@@ -76,8 +80,3 @@ func specTemplate() (*template.Template, errors.Error) {
 	}
 	return specTemplate, nil
 }
-
-func specTemplatePath() string {
-	_, currentFile, _, _ := runtime.Caller(0)
-	return path.Join(path.Dir(currentFile), "open_api_spec.json.tmpl")
-}