panic in DefaultNamifier
Closed this issue · 3 comments
nickchen commented
go: downloading github.com/lerenn/asyncapi-codegen v0.41.3
panic: runtime error: slice bounds out of range [:1] with length 0
goroutine 1 [running]:
github.com/lerenn/asyncapi-codegen/pkg/utils/template.DefaultNamifier({0x10331f418, 0x1})
/Users/nickchen/go/pkg/mod/github.com/lerenn/asyncapi-codegen@v0.41.3/pkg/utils/template/helpers.go:66 +0x30c
github.com/lerenn/asyncapi-codegen/pkg/utils/template.Namify(...)
- spec from https://demo.dxfeed.com/dxlink-ws/debug/assets/asyncapi-12629c76.yml
- command
go run github.com/lerenn/asyncapi-codegen/cmd/asyncapi-codegen@main -i api/ws/dxfeed/asyncapi.yaml -o ./test.gen.go -g types
Propose fix:
diff --git a/pkg/utils/template/helpers.go b/pkg/utils/template/helpers.go
index 0d5c21c..2491a2e 100644
--- a/pkg/utils/template/helpers.go
+++ b/pkg/utils/template/helpers.go
@@ -61,7 +61,9 @@ func DefaultNamifier(sentence string) string {
// Remove leading numbers
re = regexp.MustCompile("^[0-9]+")
sentence = string(re.ReplaceAll([]byte(sentence), []byte("")))
-
+ if len(sentence) == 0 {
+ return sentence
+ }
// Upper first letter
sentence = strings.ToUpper(sentence[:1]) + sentence[1:]
lerenn commented
Hello @nickchen ! Thanks for reporting this bug !
The fix looks great !
I can create the MR and merge it for you, but if you prefer to do it and be credited in the Github contributors, let me know !
nickchen commented
#236 here you go. Ran into couple of other issues, will open separate PR for them.
lerenn commented
Thanks for opening those issues/PR. It's really helpful for the project :)
I'll close this issue, as you solved it in a now merged PR.