From c27f6de8ffae52c63a98f19ce952f3cb09ff920a Mon Sep 17 00:00:00 2001 From: Neela Reddy Bollu Date: Tue, 16 Jun 2026 14:30:09 +0200 Subject: [PATCH 1/2] fix(openapi): guard non-struct kind in getContentID ref loop Fixes free5gc/free5gc#1040 and free5gc/free5gc#1041. FieldByName and Type().NumField() are only valid on struct kinds. A non-struct value at this point means the ref path resolved to a leaf before all components were consumed. Adding an IsValid+Kind guard at the top of the for loop prevents panics in all three FieldByName call sites within the loop body. --- client.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client.go b/client.go index ed3309e6..1e614c96 100644 --- a/client.go +++ b/client.go @@ -267,6 +267,15 @@ func getContentID(v reflect.Value, ref string, class string) (contentID string, } for _, part := range strings.Split(ref, ".") { + // Guard: FieldByName and Type().NumField() are only defined for struct kinds. + // A non-struct here means the ref path resolved to a leaf before all + // components were consumed. Fixes free5gc/free5gc#1040 and #1041. + if !recursiveVal.IsValid() || recursiveVal.Kind() != reflect.Struct { + return "", fmt.Errorf( + "getContentID: ref %q: expected struct at component %q, got kind %v", + ref, part, recursiveVal.Kind(), + ) + } lastValType := recursiveVal.Type() listIndex := -1 From 9f341b2a776b75611352309444f29b71df59c49e Mon Sep 17 00:00:00 2001 From: Neela Reddy Bollu Date: Thu, 18 Jun 2026 08:44:13 +0200 Subject: [PATCH 2/2] style(openapi): trim getContentID guard comment to one line --- client.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client.go b/client.go index 1e614c96..b39d5ff7 100644 --- a/client.go +++ b/client.go @@ -267,9 +267,7 @@ func getContentID(v reflect.Value, ref string, class string) (contentID string, } for _, part := range strings.Split(ref, ".") { - // Guard: FieldByName and Type().NumField() are only defined for struct kinds. - // A non-struct here means the ref path resolved to a leaf before all - // components were consumed. Fixes free5gc/free5gc#1040 and #1041. + // Guard against non-struct kinds; fixes free5gc/free5gc#1040 and #1041. if !recursiveVal.IsValid() || recursiveVal.Kind() != reflect.Struct { return "", fmt.Errorf( "getContentID: ref %q: expected struct at component %q, got kind %v",