Skip to content

Commit 560bf03

Browse files
committed
feat(swagger): update swagger
1 parent d2d0170 commit 560bf03

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

cmd/check.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ var checkCmd = &cobra.Command{
5252
log.Fatalln("[jzero-env] env check failed, protoc-gen-go-grpc is not installed")
5353
}
5454

55-
log.Info("\n[jzero-env]: looking up goctl-swagger")
56-
_, err = env.LookPath("goctl-swagger")
55+
log.Info("\n[jzero-env]: looking up jzero-swagger")
56+
_, err = env.LookPath("jzero-swagger")
5757
if err != nil {
58-
_ = golang.Install("github.com/jzero-io/goctl-swagger@latest")
58+
_ = golang.Install("github.com/jzero-io/jzero-swagger@latest")
5959
}
60-
if _, err = env.LookPath("goctl-swagger"); err == nil {
61-
log.Success(`[jzero-env]: "goctl-swagger" is installed`)
60+
if _, err = env.LookPath("jzero-swagger"); err == nil {
61+
log.Success(`[jzero-env]: "jzero-swagger" is installed`)
6262
} else {
63-
log.Warning("[jzero-env] warning: env check failed, goctl-swagger is not installed")
63+
log.Warning("[jzero-env] warning: env check failed, jzero-swagger is not installed")
6464
}
6565

6666
log.Info("\n[jzero-env]: looking up protoc-gen-openapiv2")

cmd/gen.go

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ func init() {
298298
genCmd.AddCommand(genSwaggerCmd)
299299

300300
genSwaggerCmd.Flags().StringP("output", "o", filepath.Join("desc", "swagger"), "set swagger output dir")
301+
genSwaggerCmd.Flags().BoolP("route2code", "", false, "is generate route2code")
301302
}
302303

303304
{

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type GenSwaggerConfig struct {
122122
Desc []string `mapstructure:"desc"`
123123
DescIgnore []string `mapstructure:"desc-ignore"`
124124
Output string `mapstructure:"output"`
125+
Route2Code bool `mapstructure:"route2code"`
125126
}
126127

127128
type GenZrpcclientConfig struct {

internal/gen/genswagger/gen.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/pkg/errors"
1111
"github.com/samber/lo"
12+
"github.com/zeromicro/go-zero/core/logx"
1213
"github.com/zeromicro/go-zero/tools/goctl/api/parser"
1314
"github.com/zeromicro/go-zero/tools/goctl/rpc/execx"
1415
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
@@ -84,7 +85,12 @@ func Gen() (err error) {
8485
if goPackage, ok := parse.Info.Properties["go_package"]; ok {
8586
apiFile = fmt.Sprintf("%s.swagger.json", strings.ReplaceAll(goPackage, "/", "-"))
8687
}
87-
cmd := exec.Command("goctl", "api", "plugin", "-plugin", "goctl-swagger=swagger -filename "+apiFile+" --schemes http,https", "-api", cv, "-dir", config.C.Gen.Swagger.Output)
88+
cmd := exec.Command("goctl", "api", "plugin", "-plugin", "jzero-swagger=swagger -filename "+apiFile+" --schemes http,https", "-api", cv, "-dir", config.C.Gen.Swagger.Output)
89+
if config.C.Gen.Route2Code || config.C.Gen.Swagger.Route2Code {
90+
cmd = exec.Command("goctl", "api", "plugin", "-plugin", "jzero-swagger=swagger -filename "+apiFile+" --schemes http,https --route2code", "-api", cv, "-dir", config.C.Gen.Swagger.Output)
91+
}
92+
93+
logx.Debug(cmd.String())
8894
resp, err := cmd.CombinedOutput()
8995
if err != nil {
9096
return errors.Wrap(err, strings.TrimRight(string(resp), "\r\n"))

0 commit comments

Comments
 (0)