From cd74bc3debb78bc46bfc0bcd0b2b3bfa477f27e1 Mon Sep 17 00:00:00 2001 From: Chad Roberts Date: Wed, 29 Jan 2025 07:09:36 -0500 Subject: [PATCH] Adjust output to match request in issue, update tests to match reality --- pkg/schema/definitions/handler_test.go | 14 +++++++------- pkg/schema/definitions/visitor.go | 7 ++++--- pkg/schema/definitions/visitor_test.go | 12 ++++++------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pkg/schema/definitions/handler_test.go b/pkg/schema/definitions/handler_test.go index 5d99d5b3..54507685 100644 --- a/pkg/schema/definitions/handler_test.go +++ b/pkg/schema/definitions/handler_test.go @@ -305,11 +305,11 @@ func Test_byID(t *testing.T) { Description: "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata", }, "binaryData": { - Type: "map[string]string", + Type: "map[string]", Description: "BinaryData contains the binary data. Each key must consist of alphanumeric characters, '-', '_' or '.'. BinaryData can contain byte sequences that are not in the UTF-8 range. The keys stored in BinaryData must not overlap with the ones in the Data field, this is enforced during validation process. Using this field will require 1.10+ apiserver and kubelet.", }, "data": { - Type: "map[string]string", + Type: "map[string]", Description: "Data contains the configuration data. Each key must consist of alphanumeric characters, '-', '_' or '.'. Values with non-UTF-8 byte sequences must use the BinaryData field. The keys stored in Data must not overlap with the keys in the BinaryData field, this is enforced during validation process.", }, "immutable": { @@ -321,7 +321,7 @@ func Test_byID(t *testing.T) { "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": { ResourceFields: map[string]definitionField{ "annotations": { - Type: "map[string]string", + Type: "map[string]", Description: "annotations of the resource", }, "name": { @@ -390,7 +390,7 @@ func Test_byID(t *testing.T) { "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": { ResourceFields: map[string]definitionField{ "annotations": { - Type: "map[string]string", + Type: "map[string]", Description: "annotations of the resource", }, "name": { @@ -439,7 +439,7 @@ func Test_byID(t *testing.T) { "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": { ResourceFields: map[string]definitionField{ "annotations": { - Type: "map[string]string", + Type: "map[string]", Description: "annotations of the resource", }, "name": { @@ -512,7 +512,7 @@ func Test_byID(t *testing.T) { "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": { ResourceFields: map[string]definitionField{ "annotations": { - Type: "map[string]string", + Type: "map[string]", Description: "annotations of the resource", }, "name": { @@ -560,7 +560,7 @@ func Test_byID(t *testing.T) { "io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta": { ResourceFields: map[string]definitionField{ "annotations": { - Type: "map[string]string", + Type: "map[string]", Description: "annotations of the resource", }, "name": { diff --git a/pkg/schema/definitions/visitor.go b/pkg/schema/definitions/visitor.go index 97642f76..fde60c2e 100644 --- a/pkg/schema/definitions/visitor.go +++ b/pkg/schema/definitions/visitor.go @@ -1,6 +1,7 @@ package definitions import ( + "fmt" "k8s.io/kube-openapi/pkg/util/proto" ) @@ -21,7 +22,7 @@ func (s *schemaFieldVisitor) VisitArray(array *proto.Array) { array.SubType.Accept(subVisitor) subField := subVisitor.field // Represent the map as "array[]" - field.Type = "array[" + subField.Type + "]" + field.Type = fmt.Sprintf("array[%s]", subField.Type) s.field = field } @@ -35,8 +36,8 @@ func (s *schemaFieldVisitor) VisitMap(protoMap *proto.Map) { subVisitor := &schemaFieldVisitor{definitions: s.definitions} protoMap.SubType.Accept(subVisitor) subField := subVisitor.field - // Represent the map as "map[string]" - field.Type = "map[string]" + subField.Type + // Represent the map as "map[]" + field.Type = fmt.Sprintf("map[%s]", subField.Type) s.field = field } diff --git a/pkg/schema/definitions/visitor_test.go b/pkg/schema/definitions/visitor_test.go index 3c05460e..a4bff366 100644 --- a/pkg/schema/definitions/visitor_test.go +++ b/pkg/schema/definitions/visitor_test.go @@ -108,7 +108,7 @@ func TestSchemaFieldVisitor(t *testing.T) { inputSchema: &protoMap, wantDefinitions: map[string]definition{}, wantField: definitionField{ - Type: "map[string]string", + Type: "map[string]", Description: protoMap.Description, }, }, @@ -151,7 +151,7 @@ func TestSchemaFieldVisitor(t *testing.T) { Required: true, }, "protoMap": { - Type: "map[" + protoPrimitive.Type + "]string", + Type: "map[" + protoPrimitive.Type + "]", Description: protoMap.Description, }, "protoPrimitive": { @@ -194,7 +194,7 @@ func TestSchemaFieldVisitor(t *testing.T) { Required: true, }, "protoMap": { - Type: "map[string]string", + Type: "map[string]", Description: protoMap.Description, }, "protoPrimitive": { @@ -237,7 +237,7 @@ func TestSchemaFieldVisitor(t *testing.T) { Required: true, }, "protoMap": { - Type: "map[string]string", + Type: "map[string]", Description: protoMap.Description, }, "protoPrimitive": { @@ -255,7 +255,7 @@ func TestSchemaFieldVisitor(t *testing.T) { }, }, wantField: definitionField{ - Type: "map[string]io.cattle.test", + Type: "map[io.cattle.test]", Description: protoNestedMap.Description, }, }, @@ -279,7 +279,7 @@ func TestSchemaFieldVisitor(t *testing.T) { }, wantDefinitions: map[string]definition{}, wantField: definitionField{ - Type: "map[string]array[map[string]string]", + Type: "map[array[map[string]]]", Description: "multi-level nested structure", }, },