Skip to content

Commit d78022c

Browse files
author
Keon Amini
authored
fix: Correct Swagger spec template path discovery (#5078)
* fix: Correct Swagger spec template path discovery * fix: removed unneeded init function
1 parent 3458930 commit d78022c

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ RUN python3 -m pip install --no-cache --upgrade pip setuptools && \
142142
RUN curl -sSL https://install.python-poetry.org | python3 -
143143
RUN ln -sf /root/.local/bin/poetry /usr/local/bin
144144
# Build Python plugins
145-
RUN find /app/python/ -name "*.sh" | xargs -I{} chmod +x {}
145+
RUN find /app/python/ -name "*.sh" | xargs -I{} chmod +x {}
146146
RUN /app/python/build.sh
147147

148148

@@ -156,7 +156,7 @@ RUN ldconfig -vn /app/libs
156156

157157
# apps
158158
COPY --from=build /app/bin /app/bin
159-
COPY --from=build /app/resources/tap /app/resources/tap
159+
COPY --from=build /app/resources /app/resources
160160

161161
ENV PATH="/app/bin:${PATH}"
162162

backend/core/config/config_viper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func setDefaultValue(v *viper.Viper) {
7676
v.SetDefault("TEMPORAL_TASK_QUEUE", "DEVLAKE_TASK_QUEUE")
7777
v.SetDefault("TAP_PROPERTIES_DIR", "resources/tap")
7878
v.SetDefault("REMOTE_PLUGIN_DIR", "python/plugins")
79+
v.SetDefault("SWAGGER_DOCS_DIR", "resources/swagger")
7980
}
8081

8182
// replaceNewEnvItemInOldContent replace old config to new config in env file content

backend/server/services/remote/plugin/doc/open_api_spec.json.tmpl renamed to backend/resources/swagger/open_api_spec.json.tmpl

File renamed without changes.

backend/server/services/remote/plugin/doc/open_api.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package doc
1919

2020
import (
2121
"encoding/json"
22+
"github.com/apache/incubator-devlake/core/config"
2223
"io"
2324
"os"
24-
"path"
25-
"runtime"
25+
"path/filepath"
2626
"strings"
2727
"text/template"
2828

@@ -62,7 +62,11 @@ func GenerateOpenApiSpec(pluginInfo *models.PluginInfo) (*string, errors.Error)
6262
}
6363

6464
func specTemplate() (*template.Template, errors.Error) {
65-
file, err := os.Open(specTemplatePath())
65+
path := config.GetConfig().GetString("SWAGGER_DOCS_DIR")
66+
if path == "" {
67+
return nil, errors.Default.New("path for Swagger docs resources is not set")
68+
}
69+
file, err := os.Open(filepath.Join(path, "open_api_spec.json.tmpl"))
6670
if err != nil {
6771
return nil, errors.Default.Wrap(err, "could not open swagger doc template")
6872
}
@@ -76,8 +80,3 @@ func specTemplate() (*template.Template, errors.Error) {
7680
}
7781
return specTemplate, nil
7882
}
79-
80-
func specTemplatePath() string {
81-
_, currentFile, _, _ := runtime.Caller(0)
82-
return path.Join(path.Dir(currentFile), "open_api_spec.json.tmpl")
83-
}

0 commit comments

Comments
 (0)