diff --git a/protoc-gen-swagger/genswagger/BUILD.bazel b/protoc-gen-swagger/genswagger/BUILD.bazel index 929d0cf11d5..c89eb04477d 100644 --- a/protoc-gen-swagger/genswagger/BUILD.bazel +++ b/protoc-gen-swagger/genswagger/BUILD.bazel @@ -7,6 +7,8 @@ go_library( srcs = [ "doc.go", "generator.go", + "helpers.go", + "helpers_go111_old.go", "template.go", "types.go", ], diff --git a/protoc-gen-swagger/genswagger/generator.go b/protoc-gen-swagger/genswagger/generator.go index 31409ac4c19..61c5a537661 100644 --- a/protoc-gen-swagger/genswagger/generator.go +++ b/protoc-gen-swagger/genswagger/generator.go @@ -67,10 +67,6 @@ func mergeTargetFile(targets []*wrapper, mergeFileName string) *wrapper { return mergedTarget } -func fieldName(k string) string { - return strings.ReplaceAll(strings.Title(k), "-", "_") -} - // Q: What's up with the alias types here? // A: We don't want to completely override how these structs are marshaled into // JSON, we only want to add fields (see below, extensionMarshalJSON). diff --git a/protoc-gen-swagger/genswagger/helpers.go b/protoc-gen-swagger/genswagger/helpers.go new file mode 100644 index 00000000000..3615596f7c1 --- /dev/null +++ b/protoc-gen-swagger/genswagger/helpers.go @@ -0,0 +1,9 @@ +//+build go1.12 + +package genswagger + +import "strings" + +func fieldName(k string) string { + return strings.ReplaceAll(strings.Title(k), "-", "_") +} diff --git a/protoc-gen-swagger/genswagger/helpers_go111_old.go b/protoc-gen-swagger/genswagger/helpers_go111_old.go new file mode 100644 index 00000000000..8e9458dd8d6 --- /dev/null +++ b/protoc-gen-swagger/genswagger/helpers_go111_old.go @@ -0,0 +1,9 @@ +//+build !go1.12 + +package genswagger + +import "strings" + +func fieldName(k string) string { + return strings.Replace(strings.Title(k), "-", "_", -1) +}