Skip to content

Commit c065b84

Browse files
authored
Merge pull request #54 from SasSwart/bugfix/go-dashes-in-names
Remove dashes from function and attribute names
2 parents 8cb7d24 + 53293e6 commit c065b84

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// SemVer should be updated on any new release!!
12-
const SemVer = "0.0.7"
12+
const SemVer = "0.0.9"
1313

1414
var (
1515
Debug bool

render/go/renderer.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,26 @@ func (g *Renderer) SanitiseName(s []string) string {
7272
caser := cases.Title(language.English)
7373
var temp []string
7474
for _, w := range s {
75+
var delim string
7576
switch true {
7677
case isHttpStatusCode(w):
7778
temp = append(temp, w)
7879
continue
7980
case strings.Contains(w, "/"):
80-
for _, split := range strings.Split(w, "/") {
81-
temp = append(temp, caser.String(CreateFunctionString(split)))
82-
}
83-
continue
81+
delim = "/"
8482
case strings.Contains(w, " "):
85-
for _, split := range strings.Split(w, " ") {
86-
temp = append(temp, caser.String(CreateFunctionString(split)))
87-
}
88-
continue
83+
delim = " "
8984
case strings.Contains(w, "_"):
90-
for _, split := range strings.Split(w, "_") {
91-
temp = append(temp, caser.String(CreateFunctionString(split)))
92-
}
85+
delim = "_"
86+
case strings.Contains(w, "-"):
87+
delim = "-"
88+
default:
89+
temp = append(temp, caser.String(CreateFunctionString(w)))
9390
continue
9491
}
95-
temp = append(temp, caser.String(CreateFunctionString(w)))
92+
for _, split := range strings.Split(w, delim) {
93+
temp = append(temp, caser.String(CreateFunctionString(split)))
94+
}
9695
}
9796
return strings.Join(temp, "")
9897
}

render/go/renderer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestGolang_SanitiseName(t *testing.T) {
2525

2626
specPath := "../../" + test.OpenapiFile
2727
apiSpec, _ := openapi.LoadAPISpec(specPath)
28+
goPropertiesWithDashes := "go-properties-with-dashes"
2829

2930
tests := []struct {
3031
name string
@@ -71,6 +72,11 @@ func TestGolang_SanitiseName(t *testing.T) {
7172
node: test.Dig(apiSpec, test.Endpoint, http.MethodPost, request.BodyKey, media.JSONKey, schema.PropertyKey, "name"),
7273
expected: "ValidationFixtureEndpointPostRequestBodyModelName",
7374
},
75+
{
76+
name: "testopenapi property with dashes in name",
77+
node: test.Dig(apiSpec, test.Endpoint, http.MethodPost, request.BodyKey, media.JSONKey, schema.PropertyKey, goPropertiesWithDashes),
78+
expected: "ValidationFixtureEndpointPostRequestBodyModelGoPropertiesWithDashes",
79+
},
7480
}
7581
for _, testCase := range tests {
7682
t.Run(testCase.name, func(t *testing.T) {

test/fixtures/testRefs/test_ref_post.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
type: object
22
properties:
3+
go-properties-with-dashes:
4+
type: string
35
enabled:
46
type: boolean
57
name:

0 commit comments

Comments
 (0)