From 1043415942401f092375ab738a3b72db11c96d33 Mon Sep 17 00:00:00 2001 From: Harsh-128 Date: Tue, 11 Aug 2026 23:06:37 +0530 Subject: [PATCH] fix: preserve list markers on named slice types --- pkg/generators/openapi.go | 6 +++++- pkg/generators/openapi_test.go | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/pkg/generators/openapi.go b/pkg/generators/openapi.go index 195620b35..73076c15b 100644 --- a/pkg/generators/openapi.go +++ b/pkg/generators/openapi.go @@ -754,7 +754,11 @@ func (g openAPITypeWriter) generateStructExtensions(t *types.Type, otherExtensio } func (g openAPITypeWriter) generateMemberExtensions(m *types.Member, parent *types.Type, otherExtensions map[string]interface{}) error { - extensions, parseErrors := parseExtensions(m.CommentLines) + comments := m.CommentLines + if m.Type.Kind == types.Alias { + comments = append(append([]string{}, comments...), m.Type.CommentLines...) + } + extensions, parseErrors := parseExtensions(comments) validationErrors := validateMemberExtensions(extensions, m) errors := append(parseErrors, validationErrors...) // Initially, we will only log member extension errors. diff --git a/pkg/generators/openapi_test.go b/pkg/generators/openapi_test.go index c2c064796..1869e9c1c 100644 --- a/pkg/generators/openapi_test.go +++ b/pkg/generators/openapi_test.go @@ -1816,7 +1816,14 @@ func TestExtensions(t *testing.T) { // +listType=map // +listMapKey=port WithListField2 []string - }` + + NamedItems NamedItemList + } + // +k8s:openapi-gen=true + // +listType=map + // +listMapKey=port + type NamedItemList []string + ` packagestest.TestAll(t, func(t *testing.T, x packagestest.Exporter) { e := packagestest.Export(t, x, []packagestest.Module{{ Name: "example.com/base/foo", @@ -1888,8 +1895,29 @@ Format: "", }, }, }, +"NamedItems": { +VendorExtensible: spec.VendorExtensible{ +Extensions: spec.Extensions{ +"x-kubernetes-list-map-keys": []interface{}{ +"port", +}, +"x-kubernetes-list-type": "map", +}, +}, +SchemaProps: spec.SchemaProps{ +Type: []string{"array"}, +Items: &spec.SchemaOrArray{ +Schema: &spec.Schema{ +SchemaProps: spec.SchemaProps{ +Type: []string{"string"}, +Format: "", +}, +}, +}, +}, +}, }, -Required: []string{"WithListField","WithListField2"}, +Required: []string{"WithListField","WithListField2","NamedItems"}, }, VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{