Skip to content
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
12 changes: 11 additions & 1 deletion internal/schema/framework_identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,20 @@ func (identifier FrameworkIdentifier) ToPrefixCamelCase(prefix string) string {
// ToPascalCase will return a pascal case formatted string of the identifier.
// Example:
// - example_resource_thing -> ExampleResourceThing
// - _id -> UnderscoreId
func (identifier FrameworkIdentifier) ToPascalCase() string {
return snakeLetters.ReplaceAllStringFunc(string(identifier), func(s string) string {
input := string(identifier)

result := snakeLetters.ReplaceAllStringFunc(input, func(s string) string {
return strings.ToUpper(strings.Replace(s, "_", "", -1))
})

// Preserve leading underscore to avoid collisions (e.g., _id vs id).
if strings.HasPrefix(input, "_") {
result = "Underscore" + result
}

return result
Comment on lines +83 to +94
}

// ToPrefixPascalCase will return a pascal case formatted string of the identifier,
Expand Down
8 changes: 4 additions & 4 deletions internal/schema/framework_identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestFrameworkIdentifier_ToCamelCase(t *testing.T) {
},
"leading underscore": {
identifier: "_thing",
want: "thing",
want: "underscoreThing",
},
"middle underscore": {
identifier: "fake_thing",
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestFrameworkIdentifier_ToPrefixCamelCase(t *testing.T) {
},
"leading underscore": {
identifier: "_thing",
want: "thing",
want: "underscoreThing",
},
"middle underscore": {
identifier: "fake_thing",
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestFrameworkIdentifier_ToPascalCase(t *testing.T) {
},
"leading underscore": {
identifier: "_thing",
want: "Thing",
want: "UnderscoreThing",
},
Comment on lines 194 to 197
"middle underscore": {
identifier: "fake_thing",
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestFrameworkIdentifier_ToPrefixPascalCase(t *testing.T) {
},
"leading underscore": {
identifier: "_thing",
want: "Thing",
want: "UnderscoreThing",
},
"middle underscore": {
identifier: "fake_thing",
Expand Down