Skip to content

fix!: kafka native acl enum duplicates #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -422,7 +422,6 @@ func exec() error {
}

dirPath := filepath.Join(cfg.HandlerDir, fileName)

err = os.MkdirAll(dirPath, dirMode)
if err != nil {
return err
Expand Down
21 changes: 11 additions & 10 deletions generator/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,9 @@ func (s *Schema) init(doc *Doc, scope map[string]*Schema, name string) {
}

if s.isObject() || s.isEnum() { //nolint:nestif
for s.parent != nil {
v, ok := scope[s.CamelName]
if !ok {
break
}

v, ok := scope[s.CamelName]
// Takes parent's name to resolve name collision
if ok {
if v.hash() == s.hash() {
v.duplicates = append(v.duplicates, s)
return
Expand All @@ -337,7 +334,11 @@ func (s *Schema) init(doc *Doc, scope map[string]*Schema, name string) {
if parent.isPrivate() {
s.CamelName = customCamelCase(parent.CamelName)
} else {
s.CamelName = strings.TrimSuffix(customCamelCase(parent.CamelName), suffix) + s.CamelName
// Adds parent's name
s.CamelName = strings.TrimSuffix(parent.CamelName, suffix) + s.CamelName
if s.isEnum() {
s.CamelName = dedupCamelName(cleanEnumName.ReplaceAllString(s.CamelName, ""))
}
}

// Marks all have collision
Expand Down Expand Up @@ -487,9 +488,8 @@ func getType(s *Schema) *jen.Statement {
} else if s.name == "tags" {
// tags are everywhere in the schema, better not to use the patch
return a.String()
} else {
return a.Any()
}
return a.Any()
default:
panic(fmt.Errorf("unknown type %q for %q and parent %q", s.Type, s.name, s.parent.name))
}
Expand Down Expand Up @@ -522,7 +522,7 @@ func sortedKeys[T any](m map[string]T) []string {
return keys
}

var cleanEnumName = regexp.MustCompile("(Create|Get|Update|Delete|Stop|Cancel|Verify|Put)")
var cleanEnumName = regexp.MustCompile("(Create|Get|Update|Delete|Stop|Cancel|Verify|Put|Add)")

// getEnumName enum can't have just "state" name, drills to the root until finds something
func getEnumName(s *Schema) string {
Expand All @@ -538,6 +538,7 @@ func getEnumName(s *Schema) string {

var camelFinder = regexp.MustCompile("[A-Z]+[a-z]+")

// dedupCamelName removes duplicates: KafkaAclKafkaAcl -> KafkaAcl
func dedupCamelName(src string) string {
result := make([]string, 0)
for _, s := range camelFinder.FindAllString(src, -1) {
Expand Down
28 changes: 8 additions & 20 deletions handler/domain/domain.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 33 additions & 43 deletions handler/kafka/kafka.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading