From ff9bcc718df44c273ebd5798347bdc2818ae671d Mon Sep 17 00:00:00 2001 From: Pantani Date: Fri, 3 Nov 2023 10:51:20 +0100 Subject: [PATCH 1/5] fix wrong parser for proto package names --- go.mod | 2 +- go.sum | 4 +- ignite/pkg/cosmosanalysis/module/module.go | 3 +- ignite/pkg/cosmosgen/cosmosgen.go | 4 +- ignite/pkg/cosmosgen/cosmosgen_test.go | 2 +- ignite/pkg/cosmosgen/generate_openapi.go | 8 +- ignite/pkg/cosmosgen/generate_typescript.go | 2 +- ignite/pkg/protoanalysis/builder.go | 2 +- ignite/pkg/protoanalysis/package.go | 186 ++++++++++++-------- ignite/pkg/protoanalysis/package_test.go | 82 +++++++++ ignite/services/chain/generate.go | 10 +- 11 files changed, 208 insertions(+), 97 deletions(-) create mode 100644 ignite/pkg/protoanalysis/package_test.go diff --git a/go.mod b/go.mod index 7481359fae..14bd50e4d4 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.1.0 - github.com/emicklei/proto v1.11.2 + github.com/emicklei/proto v1.12.1 github.com/emicklei/proto-contrib v0.14.0 github.com/go-delve/delve v1.20.2 github.com/go-git/go-git/v5 v5.6.1 diff --git a/go.sum b/go.sum index 624e6325ba..ba6420ea47 100644 --- a/go.sum +++ b/go.sum @@ -388,8 +388,8 @@ github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+m github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQxaLAeM= github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= github.com/emicklei/proto v1.11.1/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= -github.com/emicklei/proto v1.11.2 h1:DiIeyTJ+gPSyJI+RIAqvuTeKb0tLUmaGXbYg6aFKsnE= -github.com/emicklei/proto v1.11.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= +github.com/emicklei/proto v1.12.1 h1:6n/Z2pZAnBwuhU66Gs8160B8rrrYKo7h2F2sCOnNceE= +github.com/emicklei/proto v1.12.1/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A= github.com/emicklei/proto-contrib v0.14.0 h1:wFdptRZZ+JpkJtKTqOt2sXNPgwRGUkPzUL44cK9cMGE= github.com/emicklei/proto-contrib v0.14.0/go.mod h1:fpwMx68czS8x9ithaRGdLioTAadH01LLmND1Mr+FvP0= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= diff --git a/ignite/pkg/cosmosanalysis/module/module.go b/ignite/pkg/cosmosanalysis/module/module.go index 16d538e847..8a29ef18b5 100644 --- a/ignite/pkg/cosmosanalysis/module/module.go +++ b/ignite/pkg/cosmosanalysis/module/module.go @@ -229,9 +229,8 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) { return Module{}, nil } - namesplit := strings.Split(pkg.Name, ".") m := Module{ - Name: namesplit[len(namesplit)-1], + Name: pkg.Name.Name(), GoModulePath: d.basegopath, Pkg: pkg, } diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 57eb8417b3..956c7201b9 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -238,7 +238,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir // The root path is used as prefix for the generated paths. func TypescriptModulePath(rootPath string) ModulePathFunc { return func(m module.Module) string { - return filepath.Join(rootPath, m.Pkg.Name) + return filepath.Join(rootPath, m.Pkg.Name.String()) } } @@ -247,7 +247,7 @@ func TypescriptModulePath(rootPath string) ModulePathFunc { func ComposableModulePath(rootPath string) ModulePathFunc { return func(m module.Module) string { replacer := strings.NewReplacer("-", "_", ".", "_") - modPath := strcase.ToCamel(replacer.Replace(m.Pkg.Name)) + modPath := strcase.ToCamel(replacer.Replace(m.Pkg.Name.String())) return filepath.Join(rootPath, "use"+modPath) } } diff --git a/ignite/pkg/cosmosgen/cosmosgen_test.go b/ignite/pkg/cosmosgen/cosmosgen_test.go index f986d40689..ef1d27a0c7 100644 --- a/ignite/pkg/cosmosgen/cosmosgen_test.go +++ b/ignite/pkg/cosmosgen/cosmosgen_test.go @@ -49,7 +49,7 @@ func TestTypescriptModulePath(t *testing.T) { m := module.Module{ GoModulePath: tt.goModulePath, Pkg: protoanalysis.Package{ - Name: tt.protoPkgName, + Name: protoanalysis.PkgName(tt.protoPkgName), }, } diff --git a/ignite/pkg/cosmosgen/generate_openapi.go b/ignite/pkg/cosmosgen/generate_openapi.go index f4897d5472..31f5a30e31 100644 --- a/ignite/pkg/cosmosgen/generate_openapi.go +++ b/ignite/pkg/cosmosgen/generate_openapi.go @@ -74,7 +74,7 @@ func (g *generator) generateOpenAPISpec() error { if err := os.WriteFile(specPath, existingSpec, 0o644); err != nil { return err } - return conf.AddSpec(strcase.ToCamel(m.Pkg.Name), specPath, true) + return conf.AddSpec(strcase.ToCamel(m.Pkg.Name.String()), specPath, true) } hasAnySpecChanged = true @@ -101,7 +101,7 @@ func (g *generator) generateOpenAPISpec() error { if err := specCache.Put(cacheKey, f); err != nil { return err } - if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, true); err != nil { + if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name.String()), spec, true); err != nil { return err } } @@ -170,7 +170,7 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error conf = swaggercombine.Config{ Swagger: "2.0", Info: swaggercombine.Info{ - Title: "HTTP API Console " + m.Pkg.Name, + Title: "HTTP API Console " + m.Pkg.Name.String(), }, } ) @@ -208,7 +208,7 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error if err != nil { return err } - if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, false); err != nil { + if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name.String()), spec, false); err != nil { return err } } diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 05f988a75e..1bcac57bd4 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -57,7 +57,7 @@ func (g *generator) generateTS() error { for _, modules := range g.thirdModules { data.Modules = append(data.Modules, modules...) for _, m := range modules { - if strings.HasPrefix(m.Pkg.Name, "interchain_security.ccv.consumer") { + if strings.HasPrefix(m.Pkg.Name.String(), "interchain_security.ccv.consumer") { data.IsConsumerChain = true } } diff --git a/ignite/pkg/protoanalysis/builder.go b/ignite/pkg/protoanalysis/builder.go index 9d7481f67a..3f614a1fdc 100644 --- a/ignite/pkg/protoanalysis/builder.go +++ b/ignite/pkg/protoanalysis/builder.go @@ -17,7 +17,7 @@ func build(p protoPackage) Package { br := builder{p} pk := Package{ - Name: p.name, + Name: PkgName(p.name), Path: p.dir, Files: br.buildFiles(), Messages: br.buildMessages(), diff --git a/ignite/pkg/protoanalysis/package.go b/ignite/pkg/protoanalysis/package.go index 2d53d0e5a3..56ac88171e 100644 --- a/ignite/pkg/protoanalysis/package.go +++ b/ignite/pkg/protoanalysis/package.go @@ -1,58 +1,61 @@ package protoanalysis import ( + "errors" + "regexp" "strings" - "github.com/pkg/errors" + "golang.org/x/mod/semver" ) -type Packages []Package +type ( + // Packages represents slice of Package. + Packages []Package -func (p Packages) Files() Files { - var files []File - for _, pkg := range p { - files = append(files, pkg.Files...) - } - return files -} - -// Package represents a proto pkg. -type Package struct { - // Name of the proto pkg. - Name string + PkgName string - // Path of the package in the fs. - Path string + // Package represents a proto pkg. + Package struct { + // Name of the proto pkg. + Name PkgName - // Files is a list of .proto files in the package. - Files Files + // Path of the package in the fs. + Path string - // GoImportName is the go package name of proto package. - GoImportName string + // Files is a list of .proto files in the package. + Files Files - // Messages is a list of proto messages defined in the package. - Messages []Message + // GoImportName is the go package name of proto package. + GoImportName string - // Services is a list of RPC services. - Services []Service -} + // Messages is a list of proto messages defined in the package. + Messages []Message -type Files []File + // Services is a list of RPC services. + Services []Service + } +) -type File struct { - // Path of the file. - Path string +var regexBetaVersion = regexp.MustCompile("^(v)([0-9]+)(beta|alpha)([0-9]+)") - // Dependencies is a list of imported .proto files in this package. - Dependencies []string +func (p Packages) Files() Files { + var files []File + for _, pkg := range p { + files = append(files, pkg.Files...) + } + return files } -func (f Files) Paths() []string { - var paths []string - for _, ff := range f { - paths = append(paths, ff.Path) +// Name retrieves the single name of the package. +func (p PkgName) Name() (name string) { + names := strings.Split(p.String(), ".") + for i := len(names) - 1; i >= 0; i-- { + name = names[i] + if !semver.IsValid(name) && !regexBetaVersion.MatchString(name) { + break + } } - return paths + return } // MessageByName finds a message by its name inside Package. @@ -70,59 +73,86 @@ func (p Package) GoImportPath() string { return strings.Split(p.GoImportName, ";")[0] } -// Message represents a proto message. -type Message struct { - // Name of the message. - Name string +// String retrieves the string value. +func (p PkgName) String() string { + return string(p) +} + +type ( + Files []File - // Path of the file where message is defined at. - Path string + File struct { + // Path of the file. + Path string - // HighestFieldNumber is the highest field number among fields of the message - // This allows to determine new field number when writing to proto message - HighestFieldNumber int + // Dependencies is a list of imported .proto files in this package. + Dependencies []string + } +) - // Fields contains message's field names and types - Fields map[string]string +func (f Files) Paths() []string { + var paths []string + for _, ff := range f { + paths = append(paths, ff.Path) + } + return paths } -// Service is an RPC service. -type Service struct { - // Name of the services. - Name string +type ( + // Message represents a proto message. + Message struct { + // Name of the message. + Name string - // RPC is a list of RPC funcs of the service. - RPCFuncs []RPCFunc -} + // Path of the file where message is defined at. + Path string -// RPCFunc is an RPC func. -type RPCFunc struct { - // Name of the RPC func. - Name string + // HighestFieldNumber is the highest field number among fields of the message + // This allows to determine new field number when writing to proto message + HighestFieldNumber int - // RequestType is the request type of RPC func. - RequestType string + // Fields contains message's field names and types + Fields map[string]string + } - // ReturnsType is the response type of RPC func. - ReturnsType string + // Service is an RPC service. + Service struct { + // Name of the services. + Name string - // HTTPRules keeps info about http rules of an RPC func. - // spec: - // https://github.com/googleapis/googleapis/blob/master/google/api/http.proto. - HTTPRules []HTTPRule + // RPC is a list of RPC funcs of the service. + RPCFuncs []RPCFunc + } - // Paginated indicates that the RPC function is using pagination. - Paginated bool -} + // RPCFunc is an RPC func. + RPCFunc struct { + // Name of the RPC func. + Name string -// HTTPRule keeps info about a configured http rule of an RPC func. -type HTTPRule struct { - // Params is a list of parameters defined in the http endpoint itself. - Params []string + // RequestType is the request type of RPC func. + RequestType string - // HasQuery indicates if there is a request query. - HasQuery bool + // ReturnsType is the response type of RPC func. + ReturnsType string - // HasBody indicates if there is a request payload. - HasBody bool -} + // HTTPRules keeps info about http rules of an RPC func. + // spec: + // https://github.com/googleapis/googleapis/blob/master/google/api/http.proto. + HTTPRules []HTTPRule + + // Paginated indicates that the RPC function is using pagination. + Paginated bool + } + + // HTTPRule keeps info about a configured http rule of an RPC func. + HTTPRule struct { + // Params is a list of parameters defined in the http endpoint itself. + Params []string + + // HasQuery indicates if there is a request query. + HasQuery bool + + // HasBody indicates if there is a request payload. + HasBody bool + } +) diff --git a/ignite/pkg/protoanalysis/package_test.go b/ignite/pkg/protoanalysis/package_test.go new file mode 100644 index 0000000000..48a9531080 --- /dev/null +++ b/ignite/pkg/protoanalysis/package_test.go @@ -0,0 +1,82 @@ +package protoanalysis + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestPkgName_Name(t *testing.T) { + tests := []struct { + name string + p PkgName + want string + }{ + { + name: "test single name", + p: "staking", + want: "staking", + }, + { + name: "test two names", + p: "cosmos.staking", + want: "staking", + }, + { + name: "test three name", + p: "cosmos.ignite.staking", + want: "staking", + }, + { + name: "test with the version 1", + p: "cosmos.staking.v1", + want: "staking", + }, + { + name: "test with the version 2", + p: "cosmos.staking.v2", + want: "staking", + }, + { + name: "test with the version 10", + p: "cosmos.staking.v10", + want: "staking", + }, + { + name: "test with the version 1 beta 1", + p: "cosmos.staking.v1beta1", + want: "staking", + }, + { + name: "test with the version 1 beta 2", + p: "cosmos.staking.v1beta2", + want: "staking", + }, + { + name: "test with the version 2 beta 1", + p: "cosmos.staking.v2beta1", + want: "staking", + }, + { + name: "test with the version 2 beta 2", + p: "cosmos.staking.v2beta2", + want: "staking", + }, + { + name: "test with the version 3 alpha 5", + p: "cosmos.staking.v3alpha5", + want: "staking", + }, + { + name: "test with the wrong version", + p: "cosmos.staking.v3bank5", + want: "v3bank5", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.p.Name() + require.Equal(t, tt.want, got) + }) + } +} diff --git a/ignite/services/chain/generate.go b/ignite/services/chain/generate.go index 64f5570b6e..2cfbf26efb 100644 --- a/ignite/services/chain/generate.go +++ b/ignite/services/chain/generate.go @@ -179,7 +179,7 @@ func (c *Chain) Generate( openAPIPath = chainconfig.DefaultOpenAPIPath } - // Non absolute OpenAPI paths must be treated as relative to the app directory + // Non-absolute OpenAPI paths must be treated as relative to the app directory if !filepath.IsAbs(openAPIPath) { openAPIPath = filepath.Join(c.app.Path, openAPIPath) } @@ -200,7 +200,7 @@ func (c *Chain) Generate( } } - // Non absolute TS client output paths must be treated as relative to the app directory + // Non-absolute TS client output paths must be treated as relative to the app directory if !filepath.IsAbs(tsClientPath) { tsClientPath = filepath.Join(c.app.Path, tsClientPath) } @@ -225,7 +225,7 @@ func (c *Chain) Generate( updateConfig = true } - // Non absolute Vuex output paths must be treated as relative to the app directory + // Non-absolute Vuex output paths must be treated as relative to the app directory if !filepath.IsAbs(vuexPath) { vuexPath = filepath.Join(c.app.Path, vuexPath) } @@ -251,7 +251,7 @@ func (c *Chain) Generate( } } - // Non absolute Composables output paths must be treated as relative to the app directory + // Non-absolute Composables output paths must be treated as relative to the app directory if !filepath.IsAbs(composablesPath) { composablesPath = filepath.Join(c.app.Path, composablesPath) } @@ -275,7 +275,7 @@ func (c *Chain) Generate( } } - // Non absolute Hooks output paths must be treated as relative to the app directory + // Non-absolute Hooks output paths must be treated as relative to the app directory if !filepath.IsAbs(hooksPath) { hooksPath = filepath.Join(c.app.Path, hooksPath) } From c12460e8fe7219f46e5bf3af730742b65a9f9031 Mon Sep 17 00:00:00 2001 From: Pantani Date: Fri, 3 Nov 2023 10:55:51 +0100 Subject: [PATCH 2/5] add changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index e66c21b220..03e9f1b10f 100644 --- a/changelog.md +++ b/changelog.md @@ -37,6 +37,7 @@ - [#3661](https://github.com/ignite/cli/pull/3661) Change `pkg/cosmosanalysis` to find Cosmos SDK runtime app registered modules - [#3716](https://github.com/ignite/cli/pull/3716) Fix invalid plugin hook check - [#3725](https://github.com/ignite/cli/pull/3725) Fix flaky TS client generation issues on linux +- [#3728](https://github.com/ignite/cli/pull/3728) Fix wrong parser for proto package names ## [`v0.27.0`](https://github.com/ignite/cli/releases/tag/v0.27.0) From ae93d95462b8a6a13125016969712944194bf280 Mon Sep 17 00:00:00 2001 From: Pantani Date: Fri, 3 Nov 2023 11:37:57 +0100 Subject: [PATCH 3/5] fix slice sort --- ignite/pkg/cosmosgen/generate_typescript.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 1bcac57bd4..3f0bc7320d 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -66,7 +66,7 @@ func (g *generator) generateTS() error { // and module registration order consistent so the generated // files are not changed. sort.SliceStable(data.Modules, func(i, j int) bool { - return data.Modules[i].Pkg.Name < data.Modules[j].Pkg.Name + return data.Modules[i].Pkg.Name.String() < data.Modules[j].Pkg.Name.String() }) tsg := newTSGenerator(g) From 4db378aacb2ed7a119b47c7a3d8c505808d4d9db Mon Sep 17 00:00:00 2001 From: Pantani Date: Fri, 3 Nov 2023 12:21:12 +0100 Subject: [PATCH 4/5] rollback some changes --- ignite/pkg/cosmosanalysis/module/module.go | 2 +- ignite/pkg/cosmosgen/cosmosgen.go | 4 +-- ignite/pkg/cosmosgen/cosmosgen_test.go | 2 +- ignite/pkg/cosmosgen/generate_openapi.go | 8 +++--- ignite/pkg/cosmosgen/generate_typescript.go | 4 +-- ignite/pkg/protoanalysis/builder.go | 2 +- ignite/pkg/protoanalysis/package.go | 13 +++------ ignite/pkg/protoanalysis/package_test.go | 30 ++++++++++----------- 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/ignite/pkg/cosmosanalysis/module/module.go b/ignite/pkg/cosmosanalysis/module/module.go index 8a29ef18b5..1f73179ecb 100644 --- a/ignite/pkg/cosmosanalysis/module/module.go +++ b/ignite/pkg/cosmosanalysis/module/module.go @@ -230,7 +230,7 @@ func (d *moduleDiscoverer) discover(pkg protoanalysis.Package) (Module, error) { } m := Module{ - Name: pkg.Name.Name(), + Name: pkg.ModuleName(), GoModulePath: d.basegopath, Pkg: pkg, } diff --git a/ignite/pkg/cosmosgen/cosmosgen.go b/ignite/pkg/cosmosgen/cosmosgen.go index 956c7201b9..57eb8417b3 100644 --- a/ignite/pkg/cosmosgen/cosmosgen.go +++ b/ignite/pkg/cosmosgen/cosmosgen.go @@ -238,7 +238,7 @@ func Generate(ctx context.Context, cacheStorage cache.Storage, appPath, protoDir // The root path is used as prefix for the generated paths. func TypescriptModulePath(rootPath string) ModulePathFunc { return func(m module.Module) string { - return filepath.Join(rootPath, m.Pkg.Name.String()) + return filepath.Join(rootPath, m.Pkg.Name) } } @@ -247,7 +247,7 @@ func TypescriptModulePath(rootPath string) ModulePathFunc { func ComposableModulePath(rootPath string) ModulePathFunc { return func(m module.Module) string { replacer := strings.NewReplacer("-", "_", ".", "_") - modPath := strcase.ToCamel(replacer.Replace(m.Pkg.Name.String())) + modPath := strcase.ToCamel(replacer.Replace(m.Pkg.Name)) return filepath.Join(rootPath, "use"+modPath) } } diff --git a/ignite/pkg/cosmosgen/cosmosgen_test.go b/ignite/pkg/cosmosgen/cosmosgen_test.go index ef1d27a0c7..f986d40689 100644 --- a/ignite/pkg/cosmosgen/cosmosgen_test.go +++ b/ignite/pkg/cosmosgen/cosmosgen_test.go @@ -49,7 +49,7 @@ func TestTypescriptModulePath(t *testing.T) { m := module.Module{ GoModulePath: tt.goModulePath, Pkg: protoanalysis.Package{ - Name: protoanalysis.PkgName(tt.protoPkgName), + Name: tt.protoPkgName, }, } diff --git a/ignite/pkg/cosmosgen/generate_openapi.go b/ignite/pkg/cosmosgen/generate_openapi.go index 6a9121189d..84623e6b68 100644 --- a/ignite/pkg/cosmosgen/generate_openapi.go +++ b/ignite/pkg/cosmosgen/generate_openapi.go @@ -79,7 +79,7 @@ func (g *generator) generateOpenAPISpec() error { if err := os.WriteFile(specPath, existingSpec, 0o644); err != nil { return err } - return conf.AddSpec(strcase.ToCamel(m.Pkg.Name.String()), specPath, true) + return conf.AddSpec(strcase.ToCamel(m.Pkg.Name), specPath, true) } hasAnySpecChanged = true @@ -106,7 +106,7 @@ func (g *generator) generateOpenAPISpec() error { if err := specCache.Put(cacheKey, f); err != nil { return err } - if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name.String()), spec, true); err != nil { + if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, true); err != nil { return err } } @@ -175,7 +175,7 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error conf = swaggercombine.Config{ Swagger: "2.0", Info: swaggercombine.Info{ - Title: "HTTP API Console " + m.Pkg.Name.String(), + Title: "HTTP API Console " + m.Pkg.Name, }, } ) @@ -218,7 +218,7 @@ func (g *generator) generateModuleOpenAPISpec(m module.Module, out string) error if err != nil { return err } - if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name.String()), spec, false); err != nil { + if err := conf.AddSpec(strcase.ToCamel(m.Pkg.Name), spec, false); err != nil { return err } } diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 3f0bc7320d..05f988a75e 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -57,7 +57,7 @@ func (g *generator) generateTS() error { for _, modules := range g.thirdModules { data.Modules = append(data.Modules, modules...) for _, m := range modules { - if strings.HasPrefix(m.Pkg.Name.String(), "interchain_security.ccv.consumer") { + if strings.HasPrefix(m.Pkg.Name, "interchain_security.ccv.consumer") { data.IsConsumerChain = true } } @@ -66,7 +66,7 @@ func (g *generator) generateTS() error { // and module registration order consistent so the generated // files are not changed. sort.SliceStable(data.Modules, func(i, j int) bool { - return data.Modules[i].Pkg.Name.String() < data.Modules[j].Pkg.Name.String() + return data.Modules[i].Pkg.Name < data.Modules[j].Pkg.Name }) tsg := newTSGenerator(g) diff --git a/ignite/pkg/protoanalysis/builder.go b/ignite/pkg/protoanalysis/builder.go index 3f614a1fdc..9d7481f67a 100644 --- a/ignite/pkg/protoanalysis/builder.go +++ b/ignite/pkg/protoanalysis/builder.go @@ -17,7 +17,7 @@ func build(p protoPackage) Package { br := builder{p} pk := Package{ - Name: PkgName(p.name), + Name: p.name, Path: p.dir, Files: br.buildFiles(), Messages: br.buildMessages(), diff --git a/ignite/pkg/protoanalysis/package.go b/ignite/pkg/protoanalysis/package.go index 56ac88171e..5715add848 100644 --- a/ignite/pkg/protoanalysis/package.go +++ b/ignite/pkg/protoanalysis/package.go @@ -17,7 +17,7 @@ type ( // Package represents a proto pkg. Package struct { // Name of the proto pkg. - Name PkgName + Name string // Path of the package in the fs. Path string @@ -46,9 +46,9 @@ func (p Packages) Files() Files { return files } -// Name retrieves the single name of the package. -func (p PkgName) Name() (name string) { - names := strings.Split(p.String(), ".") +// ModuleName retrieves the single module name of the package. +func (p Package) ModuleName() (name string) { + names := strings.Split(p.Name, ".") for i := len(names) - 1; i >= 0; i-- { name = names[i] if !semver.IsValid(name) && !regexBetaVersion.MatchString(name) { @@ -73,11 +73,6 @@ func (p Package) GoImportPath() string { return strings.Split(p.GoImportName, ";")[0] } -// String retrieves the string value. -func (p PkgName) String() string { - return string(p) -} - type ( Files []File diff --git a/ignite/pkg/protoanalysis/package_test.go b/ignite/pkg/protoanalysis/package_test.go index 48a9531080..e21c597f65 100644 --- a/ignite/pkg/protoanalysis/package_test.go +++ b/ignite/pkg/protoanalysis/package_test.go @@ -6,76 +6,76 @@ import ( "github.com/stretchr/testify/require" ) -func TestPkgName_Name(t *testing.T) { +func TestPackage_ModuleName(t *testing.T) { tests := []struct { name string - p PkgName + p Package want string }{ { name: "test single name", - p: "staking", + p: Package{Name: "staking"}, want: "staking", }, { name: "test two names", - p: "cosmos.staking", + p: Package{Name: "cosmos.staking"}, want: "staking", }, { name: "test three name", - p: "cosmos.ignite.staking", + p: Package{Name: "cosmos.ignite.staking"}, want: "staking", }, { name: "test with the version 1", - p: "cosmos.staking.v1", + p: Package{Name: "cosmos.staking.v1"}, want: "staking", }, { name: "test with the version 2", - p: "cosmos.staking.v2", + p: Package{Name: "cosmos.staking.v2"}, want: "staking", }, { name: "test with the version 10", - p: "cosmos.staking.v10", + p: Package{Name: "cosmos.staking.v10"}, want: "staking", }, { name: "test with the version 1 beta 1", - p: "cosmos.staking.v1beta1", + p: Package{Name: "cosmos.staking.v1beta1"}, want: "staking", }, { name: "test with the version 1 beta 2", - p: "cosmos.staking.v1beta2", + p: Package{Name: "cosmos.staking.v1beta2"}, want: "staking", }, { name: "test with the version 2 beta 1", - p: "cosmos.staking.v2beta1", + p: Package{Name: "cosmos.staking.v2beta1"}, want: "staking", }, { name: "test with the version 2 beta 2", - p: "cosmos.staking.v2beta2", + p: Package{Name: "cosmos.staking.v2beta2"}, want: "staking", }, { name: "test with the version 3 alpha 5", - p: "cosmos.staking.v3alpha5", + p: Package{Name: "cosmos.staking.v3alpha5"}, want: "staking", }, { name: "test with the wrong version", - p: "cosmos.staking.v3bank5", + p: Package{Name: "cosmos.staking.v3bank5"}, want: "v3bank5", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := tt.p.Name() + got := tt.p.ModuleName() require.Equal(t, tt.want, got) }) } From 318aff5ff4c06e84ad1b6b43f88039a392d04a21 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 6 Nov 2023 13:16:37 +0100 Subject: [PATCH 5/5] improve regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jerónimo Albi --- ignite/pkg/protoanalysis/package.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/pkg/protoanalysis/package.go b/ignite/pkg/protoanalysis/package.go index 5715add848..3e139c164d 100644 --- a/ignite/pkg/protoanalysis/package.go +++ b/ignite/pkg/protoanalysis/package.go @@ -36,7 +36,7 @@ type ( } ) -var regexBetaVersion = regexp.MustCompile("^(v)([0-9]+)(beta|alpha)([0-9]+)") +var regexBetaVersion = regexp.MustCompile("^v[0-9]+(beta|alpha)[0-9]+") func (p Packages) Files() Files { var files []File