Skip to content

Commit 3e5ff69

Browse files
committed
chore: remove incorrectly named ToSnakeCase func
The function was supposed to convert to kebab-case, but named ToSnakeCase. It was removed in favor of using the github.com/stoewer/go-strcase package's KebabCase. This package was already suggested in the documentation anyway.
1 parent 328cc73 commit 3e5ff69

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/invopop/jsonschema
33
go 1.18
44

55
require (
6+
github.com/stoewer/go-strcase v1.3.1
67
github.com/stretchr/testify v1.8.1
78
github.com/wk8/go-ordered-map/v2 v2.1.8
89
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
1010
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
1111
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1212
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13+
github.com/stoewer/go-strcase v1.3.1 h1:iS0MdW+kVTxgMoE1LAZyMiYJFKlOzLooE4MxjirtkAs=
14+
github.com/stoewer/go-strcase v1.3.1/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
1315
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1416
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
1517
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

reflect.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"strconv"
1616
"strings"
1717
"time"
18+
19+
"github.com/stoewer/go-strcase"
1820
)
1921

2022
// customSchemaImpl is used to detect if the type provides it's own
@@ -205,7 +207,7 @@ func (r *Reflector) ReflectFromType(t reflect.Type) *Schema {
205207
}
206208
}
207209
if baseSchemaID != EmptyID {
208-
s.ID = baseSchemaID.Add(ToSnakeCase(name))
210+
s.ID = baseSchemaID.Add(strcase.KebabCase(name))
209211
}
210212
}
211213

utils.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
package jsonschema
22

33
import (
4-
"regexp"
5-
"strings"
6-
74
orderedmap "github.com/wk8/go-ordered-map/v2"
85
)
96

10-
var matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
11-
var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
12-
13-
// ToSnakeCase converts the provided string into snake case using dashes.
14-
// This is useful for Schema IDs and definitions to be coherent with
15-
// common JSON Schema examples.
16-
func ToSnakeCase(str string) string {
17-
snake := matchFirstCap.ReplaceAllString(str, "${1}-${2}")
18-
snake = matchAllCap.ReplaceAllString(snake, "${1}-${2}")
19-
return strings.ToLower(snake)
20-
}
21-
227
// NewProperties is a helper method to instantiate a new properties ordered
238
// map.
249
func NewProperties() *orderedmap.OrderedMap[string, *Schema] {

0 commit comments

Comments
 (0)