Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tag style "original" for additional tags #313

Merged
merged 1 commit into from
Oct 3, 2023
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
2 changes: 2 additions & 0 deletions cmd/avrogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func parseTags(raw string) (map[string]gen.TagStyle, error) {
style = gen.Kebab
case string(gen.Snake):
style = gen.Snake
case string(gen.Original):
style = gen.Original
default:
return nil, fmt.Errorf("style %q is invalid in %q", parts[1], tag)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/avrogen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func TestParseTags(t *testing.T) {
name: "kebab case",
tags: "json:kebab",
},
{
name: "original case",
tags: "json:original",
},
}

for _, test := range tests {
Expand Down
4 changes: 4 additions & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Config struct {
type TagStyle string

const (
// Original is a style like whAtEVer_IS_InthEInpuT.
Original TagStyle = "original"
// Snake is a style like im_written_in_snake_case.
Snake TagStyle = "snake"
// Camel is a style like imWrittenInCamelCase.
Expand Down Expand Up @@ -355,6 +357,8 @@ func formatTag(tag string, style TagStyle) string {
return strcase.ToCamel(tag)
case Snake:
return strcase.ToSnake(tag)
case Original:
fallthrough
default:
return tag
}
Expand Down
7 changes: 4 additions & 3 deletions gen/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestStruct_ConfigurableFieldTags(t *testing.T) {
"type": "record",
"name": "test",
"fields": [
{ "name": "someString", "type": "string" }
{ "name": "someSTRING", "type": "string" }
]
}`

Expand All @@ -110,7 +110,8 @@ func TestStruct_ConfigurableFieldTags(t *testing.T) {
{tagStyle: gen.Snake, expectedTag: "json:\"some_string\""},
{tagStyle: gen.Kebab, expectedTag: "json:\"some-string\""},
{tagStyle: gen.UpperCamel, expectedTag: "json:\"SomeString\""},
{tagStyle: gen.TagStyle(""), expectedTag: "json:\"someString\""},
{tagStyle: gen.Original, expectedTag: "json:\"someSTRING\""},
{tagStyle: gen.TagStyle(""), expectedTag: "json:\"someSTRING\""},
}

for _, test := range tests {
Expand All @@ -127,7 +128,7 @@ func TestStruct_ConfigurableFieldTags(t *testing.T) {
for _, expected := range []string{
"package something",
"type Test struct {",
"SomeString string `avro:\"someString\" " + test.expectedTag + "`",
"SomeString string `avro:\"someSTRING\" " + test.expectedTag + "`",
"}",
} {
assert.Contains(t, lines, expected)
Expand Down
Loading