Skip to content

Commit

Permalink
fix: Optimise ts-client generation
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworkgr committed Nov 2, 2023
1 parent 54bb6b4 commit 24d6be1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
17 changes: 13 additions & 4 deletions ignite/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ignite/cli/ignite/pkg/cache"
"github.com/ignite/cli/ignite/pkg/cosmosanalysis/module"
"github.com/ignite/cli/ignite/pkg/dirchange"
"github.com/ignite/cli/ignite/pkg/nodetime"
swaggercombine "github.com/ignite/cli/ignite/pkg/nodetime/programs/swagger-combine"
"github.com/ignite/cli/ignite/pkg/xos"
)
Expand Down Expand Up @@ -39,7 +40,11 @@ func (g *generator) generateOpenAPISpec() error {
},
}
)

command, cleanup, err := nodetime.Command(nodetime.CommandSwaggerCombine)
if err != nil {
return err
}
defer cleanup()
defer func() {
for _, dir := range specDirs {
os.RemoveAll(dir)
Expand Down Expand Up @@ -157,7 +162,7 @@ func (g *generator) generateOpenAPISpec() error {
}

// combine specs into one and save to out.
if err := swaggercombine.Combine(g.ctx, conf, out); err != nil {
if err := swaggercombine.Combine(g.ctx, conf, command, out); err != nil {
return err
}

Expand All @@ -174,6 +179,11 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error
},
}
)
command, cleanup, err := nodetime.Command(nodetime.CommandSwaggerCombine)
if err != nil {
return err
}
defer cleanup()

defer func() {
for _, dir := range specDirs {
Expand Down Expand Up @@ -242,7 +252,6 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error
if err := os.MkdirAll(outDir, 0o766); err != nil {
return err
}

// combine specs into one and save to out.
return swaggercombine.Combine(g.ctx, conf, out)
return swaggercombine.Combine(g.ctx, conf, command, out)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"regexp"

"github.com/ignite/cli/ignite/pkg/cmdrunner/exec"
"github.com/ignite/cli/ignite/pkg/nodetime"
)

// Config represent swagger-combine config.
Expand Down Expand Up @@ -81,13 +80,7 @@ func (c *Config) AddSpec(id, path string, makeUnique bool) error {

// Combine combines openapi specs into one and saves to out path.
// specs is a spec id-fs path pair.
func Combine(ctx context.Context, c Config, out string) error {
command, cleanup, err := nodetime.Command(nodetime.CommandSwaggerCombine)
if err != nil {
return err
}
defer cleanup()

func Combine(ctx context.Context, c Config, command []string, out string) error {
f, err := os.CreateTemp("", "*.json")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion ignite/templates/app/files/go.mod.plush
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand Down
1 change: 1 addition & 0 deletions ignite/templates/app/files/proto/buf.gen.sta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ plugins:
opt:
- logtostderr=true
- openapi_naming_strategy=simple
- ignore_comments=true
- simple_operation_ids=false
- json_names_for_fields=false

0 comments on commit 24d6be1

Please sign in to comment.