Skip to content

Commit 581f622

Browse files
authored
Merge pull request #317 from knight42/fix
✨ add support for pointers as map values
2 parents 44656d3 + 71b6e91 commit 581f622

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

pkg/crd/schema.go

+2
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ func mapToSchema(ctx *schemaContext, mapType *ast.MapType) *apiext.JSONSchemaPro
297297
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("map values must be a named type, not %T", mapType.Value), mapType.Value))
298298
return &apiext.JSONSchemaProps{}
299299
}
300+
case *ast.StarExpr:
301+
valSchema = typeToSchema(ctx.ForInfo(&markers.TypeInfo{}), val)
300302
default:
301303
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("map values must be a named type, not %T", mapType.Value), mapType.Value))
302304
return &apiext.JSONSchemaProps{}

pkg/crd/testdata/cronjob_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ type CronJobSpec struct {
9191
// This tests string slices are allowed as map values.
9292
StringSliceData map[string][]string `json:"stringSliceData,omitempty"`
9393

94+
// This tests pointers are allowed as map values.
95+
PtrData map[string]*string `json:"ptrData,omitempty"`
96+
9497
// This tests that markers that are allowed on both fields and types are applied to fields
9598
// +kubebuilder:validation:MinLength=4
9699
TwoOfAKindPart0 string `json:"twoOfAKindPart0"`

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -5038,6 +5038,11 @@ spec:
50385038
description: This tests that pattern validator is properly applied.
50395039
pattern: ^$|^((https):\/\/?)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/?))$
50405040
type: string
5041+
ptrData:
5042+
additionalProperties:
5043+
type: string
5044+
description: This tests pointers are allowed as map values.
5045+
type: object
50415046
schedule:
50425047
description: The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
50435048
type: string

0 commit comments

Comments
 (0)