Skip to content

Commit b593732

Browse files
enahancement: added dos2unix command for openapi files
1 parent bb98b5c commit b593732

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

.github/workflows/core-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- name: Test
4545
run: |
4646
cd core
47+
sudo apt install dos2unix -y
4748
# install openapi-generator-cli
4849
mkdir -p $HOME/ogc
4950
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > $HOME/ogc/openapi-generator-cli && chmod a+x $HOME/ogc/openapi-generator-cli
@@ -145,4 +146,4 @@ jobs:
145146
format: 'github'
146147
output: 'dependency-results.sbom.json'
147148
image-ref: '.'
148-
github-pat: ${{ secrets.GH_TOKEN }}
149+
github-pat: ${{ secrets.GH_TOKEN }}

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
/app/scratch/
88
/core/core
99
/.idea
10-
/core/openapitools.json
1110
/core/coverage.out
12-
/app/coverage
11+
/app/coverage
12+
openapitools.json

core/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FROM alpine:3.18.2
2222
# Create project directory (workdir)
2323
WORKDIR /app
2424

25-
RUN apk update && apk add protoc && apk add openjdk8 && apk add make && apk add bash && apk add curl && apk add jq && apk add --update go \
25+
RUN apk update && apk add protoc && apk add dos2unix && apk add openjdk8 && apk add make && apk add bash && apk add curl && apk add jq && apk add --update go \
2626
&& curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh \
2727
> /app/openapi-generator-cli \
2828
&& chmod a+x /app/openapi-generator-cli

core/internal/languages/openapi-generator-runner.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import (
1111

1212
// runs openapi-generator-cli with args passed.
1313
func runOpenAPIGenerator(args ...string) error {
14-
output, err := exec.Command("openapi-generator-cli", args...).Output()
14+
path, err := exec.LookPath("openapi-generator-cli")
15+
if err != nil {
16+
log.Debugf("err : %s", err)
17+
return errors.New("'openapi-generator-cli' command doesn't exist")
18+
}
19+
log.Debugf("openapi-generator-cli is available at %s", path)
20+
output, err := exec.Command(path, args...).Output()
1521
if err != nil {
1622
log.Debugf("Output : %s", string(output))
1723
log.Debugf("err : %s", err)
@@ -46,6 +52,12 @@ func ProcessOpenAPITemplate(ctx context.Context) error {
4652
return err
4753
}
4854

55+
// dos2unix on the file
56+
if err = runDos2Unix(fileName); err != nil {
57+
log.Debugf("err : %s", err)
58+
return err
59+
}
60+
4961
// generate code by openapi.yaml
5062
if err0 := runOpenAPIGenerator("generate", "-i", fileName, "-g", strings.ToLower(values.LanguageNode.RestConfig.Framework), "-o", values.NodeDirectoryName, "--git-user-id", values.TemplateVars[UserName], "--git-repo-id", values.TemplateVars[RepositoryName]+"/"+values.LanguageNode.Name); err0 != nil {
5163
log.Debugf("err : %s", err0)
@@ -59,3 +71,20 @@ func ProcessOpenAPITemplate(ctx context.Context) error {
5971
}
6072
return nil
6173
}
74+
75+
func runDos2Unix(fileName string) error {
76+
path, err := exec.LookPath("dos2unix")
77+
if err != nil {
78+
log.Debugf("err : %s", err)
79+
return errors.New("'dos2unix' command doesn't exist")
80+
}
81+
log.Debugf("dos2unix is available at %s", path)
82+
args := []string{fileName}
83+
output, err := exec.Command(path, args...).Output()
84+
log.Debugf("Output : %s", string(output))
85+
if err != nil {
86+
log.Debugf("err : %s", err)
87+
return err
88+
}
89+
return nil
90+
}

0 commit comments

Comments
 (0)