Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions pkg/fftypes/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ func FFEnumParseString(ctx context.Context, t, val string) (FFEnum, error) {
return "", i18n.NewError(ctx, i18n.MsgInvalidEnum, t)
}
for _, possible := range e {
if possible == strings.ToLower(val) {
return FFEnum(strings.ToLower(val)), nil
possibleStr, ok := possible.(string)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just (string)possible simple type casting should be possible here for a known type, rather than interface

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. conversion to interface{} is only needed for FFEnumValues as that function is used for openapi.

Updated the code to make that clear.

if !ok {
continue
}
if strings.EqualFold(possibleStr, val) {
return FFEnum(strings.ToLower(possibleStr)), nil
}
}
return "", i18n.NewError(ctx, i18n.MsgInvalidEnumValue, val, t, e)
Expand Down
6 changes: 6 additions & 0 deletions pkg/fftypes/enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@ func TestFFEnumParseString(t *testing.T) {
v, err = FFEnumParseString(ctx, "ut", "foobar")
assert.Regexp(t, "FF00172", err)
assert.Empty(t, v)

mixed := FFEnumValue("ut_mixed", "Test_Enum_Mixed")
v, err = FFEnumParseString(ctx, "ut_mixed", "test_enum_mixed")
assert.NoError(t, err)
assert.Equal(t, FFEnum("test_enum_mixed"), v)
assert.Equal(t, mixed.Lower(), v)
}
Loading