File tree Expand file tree Collapse file tree 4 files changed +6
-16
lines changed
Expand file tree Collapse file tree 4 files changed +6
-16
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ module github.com/invopop/jsonschema
33go 1.18
44
55require (
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)
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
1010github.com/mailru/easyjson v0.7.7 /go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc =
1111github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
1212github.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 =
1315github.com/stretchr/objx v0.1.0 /go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME =
1416github.com/stretchr/objx v0.4.0 /go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw =
1517github.com/stretchr/objx v0.5.0 /go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo =
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11package jsonschema
22
33import (
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.
249func NewProperties () * orderedmap.OrderedMap [string , * Schema ] {
You can’t perform that action at this time.
0 commit comments