forked from grpc-ecosystem/protoc-gen-grpc-gateway-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: invalid TS module name for proto files with dash or dot chars
Fixes grpc-ecosystem#42 The fix patches `data.GetModuleName` func to return a camel cased string to be used as a unique module name in TS artifacts. Here we replace manual conversion of a package name and base file name with `ToCamel` func of the `github.com/iancoleman/strcase` package. This helper package has already been included in go.mod. `ToCamel` removes `.`, `-`, `_` or whitespace chars from the input string and uses those as a mark to capitalize the next letter.
- Loading branch information
Showing
3 changed files
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package data | ||
|
||
import "testing" | ||
|
||
func TestGetModuleName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
packageName string | ||
fileName string | ||
want string | ||
}{ | ||
{"empty", "", "", ""}, | ||
{"simple", "mypackage", "service.proto", "MypackageService"}, | ||
{"with file path", "mypackage", "path/to/proto/file/service.proto", "MypackageService"}, | ||
{"with underscore", "my_package", "cool_service.proto", "MyPackageCoolService"}, | ||
{"with dash", "my-package", "cool-service.proto", "MyPackageCoolService"}, | ||
{"with dash and underscore", "my-package", "cool_service.proto", "MyPackageCoolService"}, | ||
{"with dots", "my.package", "cool.service.proto", "MyPackageCoolService"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := GetModuleName(tt.packageName, tt.fileName); got != tt.want { | ||
t.Errorf("GetModuleName() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters