From 1dfedc88bcdf521fa0637aae7f18debd201d1dd4 Mon Sep 17 00:00:00 2001 From: Chengxuan Xing Date: Fri, 5 Jun 2026 16:03:18 +0100 Subject: [PATCH 1/2] fixing enum compare to be case insensitive Signed-off-by: Chengxuan Xing --- pkg/fftypes/enum.go | 8 ++++++-- pkg/fftypes/enum_test.go | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/fftypes/enum.go b/pkg/fftypes/enum.go index 8b6fbf4d..93f07ad6 100644 --- a/pkg/fftypes/enum.go +++ b/pkg/fftypes/enum.go @@ -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) + if !ok { + continue + } + if strings.EqualFold(possibleStr, val) { + return FFEnum(strings.ToLower(possibleStr)), nil } } return "", i18n.NewError(ctx, i18n.MsgInvalidEnumValue, val, t, e) diff --git a/pkg/fftypes/enum_test.go b/pkg/fftypes/enum_test.go index 4124d655..02604c6f 100644 --- a/pkg/fftypes/enum_test.go +++ b/pkg/fftypes/enum_test.go @@ -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) } From d28788be609c414ae6388f60cbfc39b49a52035a Mon Sep 17 00:00:00 2001 From: Chengxuan Xing Date: Wed, 10 Jun 2026 15:39:03 +0100 Subject: [PATCH 2/2] address review comments Signed-off-by: Chengxuan Xing --- pkg/fftypes/enum.go | 20 ++++++++++++-------- pkg/fftypes/enum_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/pkg/fftypes/enum.go b/pkg/fftypes/enum.go index 93f07ad6..0744ba0c 100644 --- a/pkg/fftypes/enum.go +++ b/pkg/fftypes/enum.go @@ -27,15 +27,23 @@ import ( type FFEnum string -var enumValues = map[string][]interface{}{} +var enumValues = map[string][]string{} func FFEnumValue(t string, val string) FFEnum { + t = strings.ToLower(t) enumValues[t] = append(enumValues[t], val) return FFEnum(val) } func FFEnumValues(t string) []interface{} { - return enumValues[t] + values := enumValues[strings.ToLower(t)] + + // Convert []string to []interface{} for openapi3.Schema.Enum. + result := make([]interface{}, len(values)) + for i, v := range values { + result[i] = v + } + return result } func (ts FFEnum) String() string { @@ -74,12 +82,8 @@ func FFEnumParseString(ctx context.Context, t, val string) (FFEnum, error) { return "", i18n.NewError(ctx, i18n.MsgInvalidEnum, t) } for _, possible := range e { - possibleStr, ok := possible.(string) - if !ok { - continue - } - if strings.EqualFold(possibleStr, val) { - return FFEnum(strings.ToLower(possibleStr)), nil + if strings.EqualFold(possible, val) { + return FFEnum(strings.ToLower(possible)), nil } } return "", i18n.NewError(ctx, i18n.MsgInvalidEnumValue, val, t, e) diff --git a/pkg/fftypes/enum_test.go b/pkg/fftypes/enum_test.go index 02604c6f..f61c288a 100644 --- a/pkg/fftypes/enum_test.go +++ b/pkg/fftypes/enum_test.go @@ -58,6 +58,18 @@ func TestFFEnumValues(t *testing.T) { assert.Equal(t, []interface{}{"test_enum_val1", "test_enum_val2"}, FFEnumValues("ut")) } +func TestFFEnumTypeCaseInsensitive(t *testing.T) { + ctx := context.Background() + enumVal := FFEnumValue("UT_Case", "case_val1") + + assert.Equal(t, []interface{}{"case_val1"}, FFEnumValues("ut_case")) + assert.Equal(t, []interface{}{"case_val1"}, FFEnumValues("UT_CASE")) + + v, err := FFEnumParseString(ctx, "UT_CASE", "case_val1") + assert.NoError(t, err) + assert.Equal(t, enumVal.Lower(), v) +} + func TestFFEnumParseString(t *testing.T) { ctx := context.Background() v, err := FFEnumParseString(ctx, "ut", "test_enum_val1")