Skip to content
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

feat: improve variable and type naming #164

Merged
merged 2 commits into from
Oct 16, 2024
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
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestServiceCreate(t *testing.T) {
stats, err := c.ServiceClickHouseQueryStats(
ctx, project, in.ServiceName,
clickhouse.ServiceClickHouseQueryStatsLimit(1),
clickhouse.ServiceClickHouseQueryStatsOrderByType(clickhouse.OrderByTypeMaxTimeasc),
clickhouse.ServiceClickHouseQueryStatsOrderByType(clickhouse.OrderByTypeMaxTimeAsc),
)
require.NoError(t, err)
assert.Len(t, stats, 1)
Expand Down
17 changes: 14 additions & 3 deletions generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func exec() error {
if rsp.CamelName != schemaOut.CamelName {
// Takes original name and turns to camel.
// "CamelName" field might have been modified because of name collisions
outReturn.Dot(strcase.ToCamel(rsp.name))
outReturn.Dot(customCamelCase(rsp.name))

if forcePointer {
// return &out.Foo
Expand Down Expand Up @@ -488,7 +488,7 @@ func writeStruct(f *jen.File, s *Schema) error {
continue
}

constant := s.CamelName + strcase.ToCamel(literal)
constant := s.CamelName + customCamelCase(literal)

// KafkaMirror ReplicationPolicyClassType makes bad generated name
if strings.HasPrefix(literal, "org.apache.kafka.connect.mirror.") {
Expand Down Expand Up @@ -529,7 +529,7 @@ func fmtStruct(s *Schema) *jen.Statement {
fields := make([]jen.Code, 0, len(s.Properties))
for _, k := range s.propertyNames {
p := s.Properties[k]
field := jen.Id(strcase.ToCamel(k)).Add(getType(p))
field := jen.Id(customCamelCase(k)).Add(getType(p))
tag := k

if !p.required {
Expand Down Expand Up @@ -648,3 +648,14 @@ func fmtQueryParam(funcName, queryParamType string, p *Parameter) (*jen.Statemen
func fmtQueryParamType() *jen.Statement {
return jen.Index(jen.Lit(queryParamArraySize)).String()
}

func customCamelCase(s string) string {
// Split the string by ":"
parts := strings.Split(s, ":")
for i, part := range parts {
// Convert each part to camelCase using strcase.ToCamel
parts[i] = strcase.ToCamel(part)
}
// Join the parts back together
return strings.Join(parts, "")
}
10 changes: 5 additions & 5 deletions generator/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ func (s *Schema) init(doc *Doc, scope map[string]*Schema, name string) {
}

s.name = name
s.CamelName = strcase.ToCamel(s.name)
s.CamelName = customCamelCase(s.name)

if s.isEnum() {
const enumTypeSuffix = "Type"

betterName := getEnumName(s)
if betterName != s.name {
s.CamelName = cleanEnumName.ReplaceAllString(strcase.ToCamel(betterName), "") + s.CamelName
s.CamelName = cleanEnumName.ReplaceAllString(customCamelCase(betterName), "") + s.CamelName
}

if !strings.Contains(s.CamelName, enumTypeSuffix) {
Expand Down Expand Up @@ -236,7 +236,7 @@ func (s *Schema) init(doc *Doc, scope map[string]*Schema, name string) {
}

if s.parent != nil && s.parent.isPrivate() {
s.CamelName = strcase.ToCamel(s.parent.CamelName)
s.CamelName = customCamelCase(s.parent.CamelName)
}

// Some cases just impossible to cover
Expand Down Expand Up @@ -305,9 +305,9 @@ func (s *Schema) init(doc *Doc, scope map[string]*Schema, name string) {
}

if parent.isPrivate() {
s.CamelName = strcase.ToCamel(parent.CamelName)
s.CamelName = customCamelCase(parent.CamelName)
} else {
s.CamelName = strings.TrimSuffix(strcase.ToCamel(parent.CamelName), suffix) + s.CamelName
s.CamelName = strings.TrimSuffix(customCamelCase(parent.CamelName), suffix) + s.CamelName
}

// Marks all have collision
Expand Down
44 changes: 24 additions & 20 deletions handler/account/account.go

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

4 changes: 4 additions & 0 deletions handler/accountauthentication/accountauthentication.go

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

16 changes: 9 additions & 7 deletions handler/accountteam/accountteam.go

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

28 changes: 14 additions & 14 deletions handler/clickhouse/clickhouse.go

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

32 changes: 18 additions & 14 deletions handler/project/project.go

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

3 changes: 2 additions & 1 deletion handler/service/service.go

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

16 changes: 9 additions & 7 deletions handler/user/user.go

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

Loading