Skip to content

Commit

Permalink
remove unused function vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored and Pantani committed Apr 10, 2024
1 parent 020c0b0 commit 7cfcd78
Showing 1 changed file with 21 additions and 40 deletions.
61 changes: 21 additions & 40 deletions ignite/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func (g *generator) generateOpenAPISpec(ctx context.Context) error {
return dirchange.SaveDirChecksum(specCache, out, g.appPath, out)
}

// generateModuleOpenAPISpec generates a spec for a module where it's source code resides at src.
// and adds needed swaggercombine configure for it.
func (g *generator) generateModuleOpenAPISpec(ctx context.Context, m module.Module, out string) error {
var (
specDirs []string
Expand All @@ -157,55 +159,34 @@ func (g *generator) generateModuleOpenAPISpec(ctx context.Context, m module.Modu
}
}()

// gen generates a spec for a module where it's source code resides at src.
// and adds needed swaggercombine configure for it.
gen := func(m module.Module) (err error) {
dir, err := os.MkdirTemp("", "gen-openapi-module-spec")
if err != nil {
return err
}

err = g.buf.Generate(ctx, m.Pkg.Path, dir, g.openAPITemplateForSTA(), "module.proto")
if err != nil {
return err
}

specs, err := xos.FindFiles(dir, xos.JSONFile)
if err != nil {
return err
}

for _, spec := range specs {
if err != nil {
return err
}
if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, false); err != nil {
return err
}
}
specDirs = append(specDirs, dir)

return nil
}

// generate specs for each module and persist them in the file system
// after add their path and config to swaggercombine.Config so we can combine them
// into a single spec.
dir, err := os.MkdirTemp("", "gen-openapi-module-spec")
if err != nil {
return err
}

add := func(modules []module.Module) error {
for _, m := range modules {
if err := gen(m); err != nil {
return err
}
}
return nil
err = g.buf.Generate(ctx, m.Pkg.Path, dir, g.openAPITemplateForSTA(), "module.proto")
if err != nil {
return err
}

// protoc openapi generator acts weird on concurrent run, so do not use goroutines here.
if err := add([]module.Module{m}); err != nil {
specs, err := xos.FindFiles(dir, xos.JSONFile)
if err != nil {
return err
}

for _, spec := range specs {
if err != nil {
return err
}
if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, false); err != nil {
return err
}
}
specDirs = append(specDirs, dir)

// combine specs into one and save to out.
return conf.Combine(out)
}

0 comments on commit 7cfcd78

Please sign in to comment.