diff --git a/staging/src/k8s.io/apimachinery/pkg/api/validate/each.go b/staging/src/k8s.io/apimachinery/pkg/api/validate/each.go index ccff8d19b1f..70bc5100fc4 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/validate/each.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/validate/each.go @@ -43,26 +43,6 @@ func EachSliceVal[T any](ctx context.Context, op operation.Operation, fldPath *f return errs } -// EachSliceValNilable validates each element of newSlice with the specified -// validation function. The comparison function is used to find the -// corresponding value in oldSlice. The value-type of the slices is assumed to -// be nilable. -func EachSliceValNilable[T any](ctx context.Context, op operation.Operation, fldPath *field.Path, newSlice, oldSlice []T, - cmp CompareFunc[T], validator ValidateFunc[T]) field.ErrorList { - var errs field.ErrorList - for i, val := range newSlice { - var old T - if cmp != nil && len(oldSlice) > 0 { - p := lookup(oldSlice, val, cmp) - if p != nil { - old = *p - } - } - errs = append(errs, validator(ctx, op, fldPath.Index(i), val, old)...) - } - return errs -} - // lookup returns a pointer to the first element in the list that matches the // target, according to the provided comparison function, or else nil. func lookup[T any](list []T, target T, cmp func(T, T) bool) *T { @@ -90,22 +70,6 @@ func EachMapVal[K ~string, V any](ctx context.Context, op operation.Operation, f return errs } -// EachMapValNilable validates each element of newMap with the specified -// validation function and, if the corresponding key is found in oldMap, the -// old value. The value-type of the slices is assumed to be nilable. -func EachMapValNilable[K ~string, V any](ctx context.Context, op operation.Operation, fldPath *field.Path, newMap, oldMap map[K]V, - validator ValidateFunc[V]) field.ErrorList { - var errs field.ErrorList - for key, val := range newMap { - var old V - if o, found := oldMap[key]; found { - old = o - } - errs = append(errs, validator(ctx, op, fldPath.Key(string(key)), val, old)...) - } - return errs -} - // EachMapKey validates each element of newMap with the specified // validation function. The oldMap argument is not used. func EachMapKey[K ~string, T any](ctx context.Context, op operation.Operation, fldPath *field.Path, newMap, oldMap map[K]T, diff --git a/staging/src/k8s.io/apimachinery/pkg/api/validate/each_test.go b/staging/src/k8s.io/apimachinery/pkg/api/validate/each_test.go index 312d8545839..9023c8a5cd9 100644 --- a/staging/src/k8s.io/apimachinery/pkg/api/validate/each_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/api/validate/each_test.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/api/operation" "k8s.io/apimachinery/pkg/util/validation/field" - "k8s.io/utils/ptr" ) type TestStruct struct { @@ -102,107 +101,6 @@ func testEachSliceValUpdate[T any](t *testing.T, name string, input []T) { }) } -func TestEachSliceValNilablePointer(t *testing.T) { - testEachSliceValNilable(t, "valid", []*int{ptr.To(11), ptr.To(12), ptr.To(13)}) - testEachSliceValNilable(t, "valid", []*string{ptr.To("a"), ptr.To("b"), ptr.To("c")}) - testEachSliceValNilable(t, "valid", []*TestStruct{{11, "a"}, {12, "b"}, {13, "c"}}) - - testEachSliceValNilable(t, "empty", []*int{}) - testEachSliceValNilable(t, "empty", []*string{}) - testEachSliceValNilable(t, "empty", []*TestStruct{}) - - testEachSliceValNilable[int](t, "nil", nil) - testEachSliceValNilable[string](t, "nil", nil) - testEachSliceValNilable[TestStruct](t, "nil", nil) - - testEachSliceValNilableUpdate(t, "valid", []*int{ptr.To(11), ptr.To(12), ptr.To(13)}) - testEachSliceValNilableUpdate(t, "valid", []*string{ptr.To("a"), ptr.To("b"), ptr.To("c")}) - testEachSliceValNilableUpdate(t, "valid", []*TestStruct{{11, "a"}, {12, "b"}, {13, "c"}}) - - testEachSliceValNilableUpdate(t, "empty", []*int{}) - testEachSliceValNilableUpdate(t, "empty", []*string{}) - testEachSliceValNilableUpdate(t, "empty", []*TestStruct{}) - - testEachSliceValNilableUpdate[int](t, "nil", nil) - testEachSliceValNilableUpdate[string](t, "nil", nil) - testEachSliceValNilableUpdate[TestStruct](t, "nil", nil) -} - -func TestEachSliceValNilableSlice(t *testing.T) { - testEachSliceValNilable(t, "valid", [][]int{{11, 12, 13}, {12, 13, 14}, {13, 14, 15}}) - testEachSliceValNilable(t, "valid", [][]string{{"a", "b", "c"}, {"b", "c", "d"}, {"c", "d", "e"}}) - testEachSliceValNilable(t, "valid", [][]TestStruct{ - {{11, "a"}, {12, "b"}, {13, "c"}}, - {{12, "a"}, {13, "b"}, {14, "c"}}, - {{13, "a"}, {14, "b"}, {15, "c"}}}) - - testEachSliceValNilable(t, "empty", [][]int{{}, {}, {}}) - testEachSliceValNilable(t, "empty", [][]string{{}, {}, {}}) - testEachSliceValNilable(t, "empty", [][]TestStruct{{}, {}, {}}) - - testEachSliceValNilable[int](t, "nil", nil) - testEachSliceValNilable[string](t, "nil", nil) - testEachSliceValNilable[TestStruct](t, "nil", nil) - - testEachSliceValNilableUpdate(t, "valid", [][]int{{11, 12, 13}, {12, 13, 14}, {13, 14, 15}}) - testEachSliceValNilableUpdate(t, "valid", [][]string{{"a", "b", "c"}, {"b", "c", "d"}, {"c", "d", "e"}}) - testEachSliceValNilableUpdate(t, "valid", [][]TestStruct{ - {{11, "a"}, {12, "b"}, {13, "c"}}, - {{12, "a"}, {13, "b"}, {14, "c"}}, - {{13, "a"}, {14, "b"}, {15, "c"}}}) - - testEachSliceValNilableUpdate(t, "empty", [][]int{{}, {}, {}}) - testEachSliceValNilableUpdate(t, "empty", [][]string{{}, {}, {}}) - testEachSliceValNilableUpdate(t, "empty", [][]TestStruct{{}, {}, {}}) - - testEachSliceValNilableUpdate[int](t, "nil", nil) - testEachSliceValNilableUpdate[string](t, "nil", nil) - testEachSliceValNilableUpdate[TestStruct](t, "nil", nil) -} - -func testEachSliceValNilable[T any](t *testing.T, name string, input []T) { - var zero T - t.Run(fmt.Sprintf("%s(%T)", name, zero), func(t *testing.T) { - calls := 0 - vfn := func(ctx context.Context, op operation.Operation, fldPath *field.Path, newVal, oldVal T) field.ErrorList { - if !reflect.DeepEqual(oldVal, zero) { - t.Errorf("expected nil oldVal, got %v", oldVal) - } - calls++ - return nil - } - _ = EachSliceValNilable(context.Background(), operation.Operation{}, field.NewPath("test"), input, nil, nil, vfn) - if calls != len(input) { - t.Errorf("expected %d calls, got %d", len(input), calls) - } - }) -} - -func testEachSliceValNilableUpdate[T any](t *testing.T, name string, input []T) { - var zero T - t.Run(fmt.Sprintf("%s(%T)", name, zero), func(t *testing.T) { - calls := 0 - vfn := func(ctx context.Context, op operation.Operation, fldPath *field.Path, newVal, oldVal T) field.ErrorList { - if reflect.DeepEqual(oldVal, zero) { - t.Fatalf("expected non-nil oldVal") - } - if !reflect.DeepEqual(newVal, oldVal) { - t.Errorf("expected oldVal == newVal, got %v, %v", oldVal, newVal) - } - calls++ - return nil - } - old := make([]T, len(input)) - copy(old, input) - slices.Reverse(old) - cmp := func(a, b T) bool { return reflect.DeepEqual(a, b) } - _ = EachSliceValNilable(context.Background(), operation.Operation{}, field.NewPath("test"), input, old, cmp, vfn) - if calls != len(input) { - t.Errorf("expected %d calls, got %d", len(input), calls) - } - }) -} - func TestEachMapVal(t *testing.T) { testEachMapVal(t, "valid", map[string]int{"one": 11, "two": 12, "three": 13}) testEachMapVal(t, "valid", map[string]string{"A": "a", "B": "b", "C": "c"}) @@ -235,61 +133,6 @@ func testEachMapVal[T any](t *testing.T, name string, input map[string]T) { }) } -func TestEachMapValNilablePointer(t *testing.T) { - testEachMapValNilable(t, "valid", map[string]*int{"one": ptr.To(11), "two": ptr.To(12), "three": ptr.To(13)}) - testEachMapValNilable(t, "valid", map[string]*string{"A": ptr.To("a"), "B": ptr.To("b"), "C": ptr.To("c")}) - testEachMapValNilable(t, "valid", map[string]*TestStruct{"one": {11, "a"}, "two": {12, "b"}, "three": {13, "c"}}) - - testEachMapValNilable(t, "empty", map[string]*int{}) - testEachMapValNilable(t, "empty", map[string]*string{}) - testEachMapValNilable(t, "empty", map[string]*TestStruct{}) - - testEachMapValNilable[int](t, "nil", nil) - testEachMapValNilable[string](t, "nil", nil) - testEachMapValNilable[TestStruct](t, "nil", nil) -} - -func TestEachMapValNilableSlice(t *testing.T) { - testEachMapValNilable(t, "valid", map[string][]int{ - "one": {11, 12, 13}, - "two": {12, 13, 14}, - "three": {13, 14, 15}}) - testEachMapValNilable(t, "valid", map[string][]string{ - "A": {"a", "b", "c"}, - "B": {"b", "c", "d"}, - "C": {"c", "d", "e"}}) - testEachMapValNilable(t, "valid", map[string][]TestStruct{ - "one": {{11, "a"}, {12, "b"}, {13, "c"}}, - "two": {{12, "a"}, {13, "b"}, {14, "c"}}, - "three": {{13, "a"}, {14, "b"}, {15, "c"}}}) - - testEachMapValNilable(t, "empty", map[string][]int{"a": {}, "b": {}, "c": {}}) - testEachMapValNilable(t, "empty", map[string][]string{"a": {}, "b": {}, "c": {}}) - testEachMapValNilable(t, "empty", map[string][]TestStruct{"a": {}, "b": {}, "c": {}}) - - testEachMapValNilable[int](t, "nil", nil) - testEachMapValNilable[string](t, "nil", nil) - testEachMapValNilable[TestStruct](t, "nil", nil) -} - -func testEachMapValNilable[T any](t *testing.T, name string, input map[string]T) { - var zero T - t.Run(fmt.Sprintf("%s(%T)", name, zero), func(t *testing.T) { - calls := 0 - vfn := func(ctx context.Context, op operation.Operation, fldPath *field.Path, newVal, oldVal T) field.ErrorList { - if !reflect.DeepEqual(oldVal, zero) { - t.Errorf("expected nil oldVal, got %v", oldVal) - } - calls++ - return nil - } - _ = EachMapValNilable(context.Background(), operation.Operation{}, field.NewPath("test"), input, nil, vfn) - if calls != len(input) { - t.Errorf("expected %d calls, got %d", len(input), calls) - } - }) -} - type StringType string func TestEachMapKey(t *testing.T) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/doc.go index 610bba2be95..5a1a86d9ea9 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/doc.go @@ -90,10 +90,6 @@ type T1 struct { // +k8s:eachVal=+k8s:validateTrue="field T1.SliceOfOtherStruct values" // +k8s:eachVal=+k8s:opaqueType SliceOfOtherStruct []other.StructType `json:"sliceOfOtherStruct"` - // +k8s:validateTrue="field T1.SliceOfOtherStructPtr" - // +k8s:eachVal=+k8s:validateTrue="field T1.SliceOfOtherStructPtr values" - // +k8s:eachVal=+k8s:opaqueType - SliceOfOtherStructPtr []*other.StructType `json:"sliceOfOtherStructPtr"` // +k8s:validateTrue="field T1.ListMapOfOtherStruct" // +k8s:eachVal=+k8s:validateTrue="field T1.SliceOfOtherStruct values" @@ -101,12 +97,6 @@ type T1 struct { // +k8s:listMapKey=stringField // +k8s:eachVal=+k8s:opaqueType ListMapOfOtherStruct []other.StructType `json:"listMapOfOtherStruct"` - // +k8s:validateTrue="field T1.ListMapOfOtherStructPtr" - // +k8s:eachVal=+k8s:validateTrue="field T1.SliceOfOtherStructPtr values" - // +k8s:listType=map - // +k8s:listMapKey=stringField - // +k8s:eachVal=+k8s:opaqueType - ListMapOfOtherStructPtr []*other.StructType `json:"listMapOfOtherStructPtr"` // +k8s:validateTrue="field T1.MapOfOtherStringToOtherStruct" // +k8s:eachKey=+k8s:validateTrue="field T1.MapOfOtherStringToOtherStruct keys" @@ -114,12 +104,6 @@ type T1 struct { // +k8s:eachKey=+k8s:opaqueType // +k8s:eachVal=+k8s:opaqueType MapOfOtherStringToOtherStruct map[other.StringType]other.StructType `json:"mapOfOtherStringToOtherStruct"` - // +k8s:validateTrue="field T1.MapOfOtherStringToOtherStructPtr" - // +k8s:eachKey=+k8s:validateTrue="field T1.MapOfOtherStringToOtherStructPtr keys" - // +k8s:eachVal=+k8s:validateTrue="field T1.MapOfOtherStringToOtherStructPtr values" - // +k8s:eachKey=+k8s:opaqueType - // +k8s:eachVal=+k8s:opaqueType - MapOfOtherStringToOtherStructPtr map[other.StringType]*other.StructType `json:"mapOfOtherStringToOtherStructPtr"` } // TODO: the validateFalse test fixture doesn't handle map and slice types, and diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/zz_generated.validations.go index c0fd7cc92f9..65f59ae2fb0 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/cross_pkg/zz_generated.validations.go @@ -215,16 +215,6 @@ func Validate_T1(ctx context.Context, op operation.Operation, fldPath *field.Pat return }(fldPath.Child("sliceOfOtherStruct"), obj.SliceOfOtherStruct, safe.Field(oldObj, func(oldObj *T1) []other.StructType { return oldObj.SliceOfOtherStruct }))...) - // field T1.SliceOfOtherStructPtr - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*other.StructType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, true, "field T1.SliceOfOtherStructPtr")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *other.StructType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, true, "field T1.SliceOfOtherStructPtr values") - })...) - return - }(fldPath.Child("sliceOfOtherStructPtr"), obj.SliceOfOtherStructPtr, safe.Field(oldObj, func(oldObj *T1) []*other.StructType { return oldObj.SliceOfOtherStructPtr }))...) - // field T1.ListMapOfOtherStruct errs = append(errs, func(fldPath *field.Path, obj, oldObj []other.StructType) (errs field.ErrorList) { @@ -235,16 +225,6 @@ func Validate_T1(ctx context.Context, op operation.Operation, fldPath *field.Pat return }(fldPath.Child("listMapOfOtherStruct"), obj.ListMapOfOtherStruct, safe.Field(oldObj, func(oldObj *T1) []other.StructType { return oldObj.ListMapOfOtherStruct }))...) - // field T1.ListMapOfOtherStructPtr - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*other.StructType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, true, "field T1.ListMapOfOtherStructPtr")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, func(a *other.StructType, b *other.StructType) bool { return a.StringField == b.StringField }, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *other.StructType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, true, "field T1.SliceOfOtherStructPtr values") - })...) - return - }(fldPath.Child("listMapOfOtherStructPtr"), obj.ListMapOfOtherStructPtr, safe.Field(oldObj, func(oldObj *T1) []*other.StructType { return oldObj.ListMapOfOtherStructPtr }))...) - // field T1.MapOfOtherStringToOtherStruct errs = append(errs, func(fldPath *field.Path, obj, oldObj map[other.StringType]other.StructType) (errs field.ErrorList) { @@ -258,20 +238,5 @@ func Validate_T1(ctx context.Context, op operation.Operation, fldPath *field.Pat return }(fldPath.Child("mapOfOtherStringToOtherStruct"), obj.MapOfOtherStringToOtherStruct, safe.Field(oldObj, func(oldObj *T1) map[other.StringType]other.StructType { return oldObj.MapOfOtherStringToOtherStruct }))...) - // field T1.MapOfOtherStringToOtherStructPtr - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[other.StringType]*other.StructType) (errs field.ErrorList) { - errs = append(errs, validate.EachMapKey(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *other.StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, true, "field T1.MapOfOtherStringToOtherStructPtr keys") - })...) - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, true, "field T1.MapOfOtherStringToOtherStructPtr")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *other.StructType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, true, "field T1.MapOfOtherStringToOtherStructPtr values") - })...) - return - }(fldPath.Child("mapOfOtherStringToOtherStructPtr"), obj.MapOfOtherStringToOtherStructPtr, safe.Field(oldObj, func(oldObj *T1) map[other.StringType]*other.StructType { - return oldObj.MapOfOtherStringToOtherStructPtr - }))...) - return errs } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/doc.go deleted file mode 100644 index ab997fea8fd..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/doc.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.MapField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*][*]" - MapField map[string]map[string]string `json:"mapField"` - - // +k8s:validateFalse="field Struct.MapPtrField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*][*]" - MapPtrField map[string]map[string]*string `json:"mapPtrField"` - - // +k8s:validateFalse="field Struct.MapTypedefField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*][*]" - MapTypedefField map[string]MapType `json:"mapTypedefField"` -} - -// +k8s:validateFalse="type MapType" -// +k8s:eachVal=+k8s:validateFalse="type MapType[*]" -type MapType map[string]string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/testdata/validate-false.json deleted file mode 100644 index 140df85e02c..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/testdata/validate-false.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "*deep.Struct": { - "": [ - "type Struct" - ], - "mapField": [ - "field Struct.MapField" - ], - "mapField[岯Ȉ\u0026\u003c沲3][Ō仲牚輠ɟɛ3鎑鎢屃]": [ - "field Struct.MapField[*][*]" - ], - "mapField[岯Ȉ\u0026\u003c沲3][偩j0âȰ轷N巆Åʛ,^籿Ź]": [ - "field Struct.MapField[*][*]" - ], - "mapField[鶭ŁPyÌ祆tkƺƠav][0đ\u003eƯ]ɹȽ東潇澍ȣ1Ȗ]": [ - "field Struct.MapField[*][*]" - ], - "mapField[鶭ŁPyÌ祆tkƺƠav][蛷)讻I]": [ - "field Struct.MapField[*][*]" - ], - "mapPtrField": [ - "field Struct.MapPtrField" - ], - "mapPtrField[ʅȀʙĄĥ腲ʤaLJ趴][瑻霳鸻ȉĔ]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapPtrField[ʅȀʙĄĥ腲ʤaLJ趴][豐Ȭ-ƀh婉Ţ飦tD6ɀk諮]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapPtrField[顼溹*][]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapPtrField[顼溹*][机Ȱ晸ʈ劉j蕓ư銩6ij憏歅%]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapTypedefField": [ - "field Struct.MapTypedefField" - ], - "mapTypedefField[Ɠ晲銩靨能鷸ȳ琍殪\"g踮螧喘夓麑Y·L]": [ - "type MapType" - ], - "mapTypedefField[Ɠ晲銩靨能鷸ȳ琍殪\"g踮螧喘夓麑Y·L][Ɂɯz剩Ʉö宰岮3瓯]": [ - "field Struct.MapTypedefField[*][*]", - "type MapType[*]" - ], - "mapTypedefField[Ɠ晲銩靨能鷸ȳ琍殪\"g踮螧喘夓麑Y·L][黰¢ơđ?ȵɓf*Z迖瓼轊]": [ - "field Struct.MapTypedefField[*][*]", - "type MapType[*]" - ], - "mapTypedefField[滧ǖvq]": [ - "type MapType" - ], - "mapTypedefField[滧ǖvq][;]": [ - "field Struct.MapTypedefField[*][*]", - "type MapType[*]" - ], - "mapTypedefField[滧ǖvq][摒嫸yĵȲ梚鿱o糛趸鸎]": [ - "field Struct.MapTypedefField[*][*]", - "type MapType[*]" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/zz_generated.validations.go deleted file mode 100644 index 8fdb602c9fe..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/zz_generated.validations.go +++ /dev/null @@ -1,103 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_MapType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) (errs field.ErrorList) { - // type MapType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType")...) - errs = append(errs, validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType[*]") - })...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*][*]") - }) - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]MapType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*][*]") - }) - })...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_MapType)...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]MapType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/zz_generated.validations_test.go deleted file mode 100644 index 1073c9c6366..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/deep/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/doc.go deleted file mode 100644 index 098047d7b61..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/doc.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.MapField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" - MapField map[string]map[string]string `json:"mapField"` - - // +k8s:validateFalse="field Struct.MapPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string]map[string]*string `json:"mapPtrField"` - - // +k8s:validateFalse="field Struct.MapTypedefField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" - MapTypedefField map[string]MapType `json:"mapTypedefField"` -} - -// +k8s:validateFalse="type MapType" -// +k8s:validateFalse="field Struct.MapField" -// +k8s:validateFalse="field Struct.MapPtrField" -// +k8s:validateFalse="field Struct.MapTypedefField" -// +k8s:eachVal=+k8s:validateFalse="type MapType[*]" -type MapType map[string]string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/testdata/validate-false.json deleted file mode 100644 index ea7d698a48e..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/testdata/validate-false.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "*shallow.Struct": { - "": [ - "type Struct" - ], - "mapField": [ - "field Struct.MapField" - ], - "mapField[岯Ȉ\u0026\u003c沲3]": [ - "field Struct.MapField[*]" - ], - "mapField[鶭ŁPyÌ祆tkƺƠav]": [ - "field Struct.MapField[*]" - ], - "mapPtrField": [ - "field Struct.MapPtrField" - ], - "mapPtrField[ʅȀʙĄĥ腲ʤaLJ趴]": [ - "field Struct.MapPtrField[*]" - ], - "mapPtrField[顼溹*]": [ - "field Struct.MapPtrField[*]" - ], - "mapTypedefField": [ - "field Struct.MapTypedefField" - ], - "mapTypedefField[Ɠ晲銩靨能鷸ȳ琍殪\"g踮螧喘夓麑Y·L]": [ - "field Struct.MapField", - "field Struct.MapPtrField", - "field Struct.MapTypedefField", - "field Struct.MapTypedefField[*]", - "type MapType" - ], - "mapTypedefField[Ɠ晲銩靨能鷸ȳ琍殪\"g踮螧喘夓麑Y·L][Ɂɯz剩Ʉö宰岮3瓯]": [ - "type MapType[*]" - ], - "mapTypedefField[Ɠ晲銩靨能鷸ȳ琍殪\"g踮螧喘夓麑Y·L][黰¢ơđ?ȵɓf*Z迖瓼轊]": [ - "type MapType[*]" - ], - "mapTypedefField[滧ǖvq]": [ - "field Struct.MapField", - "field Struct.MapPtrField", - "field Struct.MapTypedefField", - "field Struct.MapTypedefField[*]", - "type MapType" - ], - "mapTypedefField[滧ǖvq][;]": [ - "type MapType[*]" - ], - "mapTypedefField[滧ǖvq][摒嫸yĵȲ梚鿱o糛趸鸎]": [ - "type MapType[*]" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/zz_generated.validations.go deleted file mode 100644 index 23f04fe94e2..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/zz_generated.validations.go +++ /dev/null @@ -1,100 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_MapType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) (errs field.ErrorList) { - // type MapType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType")...) - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField")...) - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField")...) - errs = append(errs, validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType[*]") - })...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*]") - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]MapType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*]") - })...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_MapType)...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]MapType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/zz_generated.validations_test.go deleted file mode 100644 index 138bc67084c..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_map/shallow/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/doc.go index a29e0ebcce9..6acab36858e 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/doc.go @@ -33,18 +33,10 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" MapField map[string]string `json:"mapField"` - // +k8s:validateFalse="field Struct.MapPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string]*string `json:"mapPtrField"` - // +k8s:validateFalse="field Struct.MapTypedefField" // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" MapTypedefField map[string]StringType `json:"mapTypedefField"` - // +k8s:validateFalse="field Struct.MapTypedefPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefPtrField[*]" - MapTypedefPtrField map[string]*StringType `json:"mapTypedefPtrField"` - UnvalidatedMapField map[string]string `json:"UnvalidatedMapField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/testdata/validate-false.json index 4cd982eee8a..255ff527486 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/testdata/validate-false.json +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/testdata/validate-false.json @@ -12,36 +12,16 @@ "mapField[岯Ȉ\u0026\u003c沲3]": [ "field Struct.MapField[*]" ], - "mapPtrField": [ - "field Struct.MapPtrField" - ], - "mapPtrField[V噘¢\u003eóDz岋笨Gń條ģ]": [ - "field Struct.MapPtrField[*]" - ], - "mapPtrField[讻IeYF墄[C]": [ - "field Struct.MapPtrField[*]" - ], "mapTypedefField": [ "field Struct.MapTypedefField" ], - "mapTypedefField[\u003eƯ]ɹȽ東潇澍]": [ + "mapTypedefField[V噘¢\u003eóDz岋笨Gń條ģ]": [ "field Struct.MapTypedefField[*]", "type StringType" ], - "mapTypedefField[闌剾溏]": [ + "mapTypedefField[þƿ髈儱Ŀ蒫÷K鬣壈]": [ "field Struct.MapTypedefField[*]", "type StringType" - ], - "mapTypedefPtrField": [ - "field Struct.MapTypedefPtrField" - ], - "mapTypedefPtrField[-ƀh婉Ţ飦]": [ - "field Struct.MapTypedefPtrField[*]", - "type StringType" - ], - "mapTypedefPtrField[x瑻霳鸻ȉĔȹ$Ievɥʈ]": [ - "field Struct.MapTypedefPtrField[*]", - "type StringType" ] } } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/zz_generated.validations.go index 93be246e166..87447e6fedb 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_primitive/zz_generated.validations.go @@ -69,16 +69,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]string { return oldObj.MapField }))...) - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]*string { return oldObj.MapPtrField }))...) - // field Struct.MapTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj map[string]StringType) (errs field.ErrorList) { @@ -90,17 +80,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]StringType { return oldObj.MapTypedefField }))...) - // field Struct.MapTypedefPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]*StringType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefPtrField[*]") - })...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_StringType)...) - return - }(fldPath.Child("mapTypedefPtrField"), obj.MapTypedefPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]*StringType { return oldObj.MapTypedefPtrField }))...) - // field Struct.UnvalidatedMapField has no validation return errs } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/doc.go deleted file mode 100644 index 46c9bfc4a8d..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/doc.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.MapField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*][*]" - MapField map[string][]string `json:"mapField"` - - // +k8s:validateFalse="field Struct.MapPtrField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*][*]" - MapPtrField map[string][]*string `json:"mapPtrField"` - - // +k8s:validateFalse="field Struct.MapTypedefField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*][*]" - MapTypedefField map[string]SliceType `json:"mapTypedefField"` -} - -// +k8s:validateFalse="type SliceType" -// +k8s:eachVal=+k8s:validateFalse="type ListType[*]" -type SliceType []StringType - -// +k8s:validateFalse="type StringType" -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/testdata/validate-false.json deleted file mode 100644 index 20f2806f8e1..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/testdata/validate-false.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "*deep.Struct": { - "": [ - "type Struct" - ], - "mapField": [ - "field Struct.MapField" - ], - "mapField[偩j0âȰ轷N巆Åʛ,^籿Ź][0]": [ - "field Struct.MapField[*][*]" - ], - "mapField[偩j0âȰ轷N巆Åʛ,^籿Ź][1]": [ - "field Struct.MapField[*][*]" - ], - "mapField[岯Ȉ\u0026\u003c沲3][0]": [ - "field Struct.MapField[*][*]" - ], - "mapField[岯Ȉ\u0026\u003c沲3][1]": [ - "field Struct.MapField[*][*]" - ], - "mapPtrField": [ - "field Struct.MapPtrField" - ], - "mapPtrField[:ŽƔA苩xǼ][0]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapPtrField[:ŽƔA苩xǼ][1]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapPtrField[鋩伸~槱¡rŔ綂2][0]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapPtrField[鋩伸~槱¡rŔ綂2][1]": [ - "field Struct.MapPtrField[*][*]" - ], - "mapTypedefField": [ - "field Struct.MapTypedefField" - ], - "mapTypedefField[h婉Ţ飦tD6]": [ - "type SliceType" - ], - "mapTypedefField[h婉Ţ飦tD6][0]": [ - "field Struct.MapTypedefField[*][*]", - "type ListType[*]", - "type StringType" - ], - "mapTypedefField[h婉Ţ飦tD6][1]": [ - "field Struct.MapTypedefField[*][*]", - "type ListType[*]", - "type StringType" - ], - "mapTypedefField[Äf渂]": [ - "type SliceType" - ], - "mapTypedefField[Äf渂][0]": [ - "field Struct.MapTypedefField[*][*]", - "type ListType[*]", - "type StringType" - ], - "mapTypedefField[Äf渂][1]": [ - "field Struct.MapTypedefField[*][*]", - "type ListType[*]", - "type StringType" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/zz_generated.validations.go deleted file mode 100644 index 1090ac0f6a2..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/zz_generated.validations.go +++ /dev/null @@ -1,111 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_SliceType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) (errs field.ErrorList) { - // type SliceType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type SliceType")...) - errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type ListType[*]") - })...) - errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, Validate_StringType)...) - - return errs -} - -func Validate_StringType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) (errs field.ErrorList) { - // type StringType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type StringType")...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*][*]") - }) - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string][]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string][]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]SliceType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*][*]") - }) - })...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_SliceType)...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]SliceType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/zz_generated.validations_test.go deleted file mode 100644 index 1073c9c6366..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/deep/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/doc.go deleted file mode 100644 index 90af952a010..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/doc.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.MapField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" - MapField map[string][]string `json:"mapField"` - - // +k8s:validateFalse="field Struct.MapPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string][]*string `json:"mapPtrField"` - - // +k8s:validateFalse="field Struct.MapTypedefField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" - MapTypedefField map[string]SliceType `json:"mapTypedefField"` -} - -// +k8s:validateFalse="type SliceType" -// +k8s:eachVal=+k8s:validateFalse="type SliceType[*]" -type SliceType []string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/testdata/validate-false.json deleted file mode 100644 index e0abd184da9..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/testdata/validate-false.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "*shallow.Struct": { - "": [ - "type Struct" - ], - "mapField": [ - "field Struct.MapField" - ], - "mapField[偩j0âȰ轷N巆Åʛ,^籿Ź]": [ - "field Struct.MapField[*]" - ], - "mapField[岯Ȉ\u0026\u003c沲3]": [ - "field Struct.MapField[*]" - ], - "mapPtrField": [ - "field Struct.MapPtrField" - ], - "mapPtrField[:ŽƔA苩xǼ]": [ - "field Struct.MapPtrField[*]" - ], - "mapPtrField[鋩伸~槱¡rŔ綂2]": [ - "field Struct.MapPtrField[*]" - ], - "mapTypedefField": [ - "field Struct.MapTypedefField" - ], - "mapTypedefField[h婉Ţ飦tD6]": [ - "field Struct.MapTypedefField[*]", - "type SliceType" - ], - "mapTypedefField[h婉Ţ飦tD6][0]": [ - "type SliceType[*]" - ], - "mapTypedefField[h婉Ţ飦tD6][1]": [ - "type SliceType[*]" - ], - "mapTypedefField[Äf渂]": [ - "field Struct.MapTypedefField[*]", - "type SliceType" - ], - "mapTypedefField[Äf渂][0]": [ - "type SliceType[*]" - ], - "mapTypedefField[Äf渂][1]": [ - "type SliceType[*]" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/zz_generated.validations.go deleted file mode 100644 index 3f72da62013..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/zz_generated.validations.go +++ /dev/null @@ -1,97 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_SliceType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) (errs field.ErrorList) { - // type SliceType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type SliceType")...) - errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type SliceType[*]") - })...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*]") - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string][]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string][]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]SliceType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*]") - })...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_SliceType)...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]SliceType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/zz_generated.validations_test.go deleted file mode 100644 index 138bc67084c..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_slice/shallow/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/doc.go index bcc538b1fe5..6195287bbca 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/doc.go @@ -33,18 +33,10 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" MapField map[string]OtherStruct `json:"mapField"` - // +k8s:validateFalse="field Struct.MapPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string]*OtherStruct `json:"mapPtrField"` - // +k8s:validateFalse="field Struct.MapTypedefField" // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" MapTypedefField map[string]OtherTypedefStruct `json:"mapTypedefField"` - // +k8s:validateFalse="field Struct.MapTypedefPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefPtrField[*]" - MapTypedefPtrField map[string]*OtherTypedefStruct `json:"mapTypedefPtrField"` - UnvalidatedMapField map[string]string `json:"UnvalidatedMapField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/testdata/validate-false.json index 9920d83a341..db82e46f0a0 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/testdata/validate-false.json +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/testdata/validate-false.json @@ -14,38 +14,16 @@ "field Struct.MapField[*]", "type OtherStruct" ], - "mapPtrField": [ - "field Struct.MapPtrField" - ], - "mapPtrField[x飖Ǒp!ǪŰ]": [ - "field Struct.MapPtrField[*]", - "type OtherStruct" - ], - "mapPtrField[旰綷罨袢捺悲ȅ-@烱ęssĂZ稈V]": [ - "field Struct.MapPtrField[*]", - "type OtherStruct" - ], "mapTypedefField": [ "field Struct.MapTypedefField" ], - "mapTypedefField[ģ|2諱4~轱:ŽƔA苩]": [ + "mapTypedefField[]": [ "field Struct.MapTypedefField[*]", "type OtherTypedefStruct" ], - "mapTypedefField[ŁPyÌ祆tkƺ]": [ + "mapTypedefField[x飖Ǒp!ǪŰ]": [ "field Struct.MapTypedefField[*]", "type OtherTypedefStruct" - ], - "mapTypedefPtrField": [ - "field Struct.MapTypedefPtrField" - ], - "mapTypedefPtrField[Ǽe赖{³*Ę鄏þƿ髈儱Ŀ蒫÷]": [ - "field Struct.MapTypedefPtrField[*]", - "type OtherTypedefStruct" - ], - "mapTypedefPtrField[鬣壈gƢ板鋩伸~槱¡rŔ綂2暮斚嬆]": [ - "field Struct.MapTypedefPtrField[*]", - "type OtherTypedefStruct" ] } } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/zz_generated.validations.go index 8d2ac8e6e0a..0005c908aa2 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/map_of_struct/zz_generated.validations.go @@ -77,17 +77,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]OtherStruct { return oldObj.MapField }))...) - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_OtherStruct)...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]*OtherStruct { return oldObj.MapPtrField }))...) - // field Struct.MapTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj map[string]OtherTypedefStruct) (errs field.ErrorList) { @@ -99,17 +88,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]OtherTypedefStruct { return oldObj.MapTypedefField }))...) - // field Struct.MapTypedefPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]*OtherTypedefStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherTypedefStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefPtrField[*]") - })...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_OtherTypedefStruct)...) - return - }(fldPath.Child("mapTypedefPtrField"), obj.MapTypedefPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]*OtherTypedefStruct { return oldObj.MapTypedefPtrField }))...) - // field Struct.UnvalidatedMapField has no validation return errs } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/doc.go index 0e198906c63..aca6e84c8b2 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/doc.go @@ -35,10 +35,6 @@ type MapType map[string]string // Note: no validation here type UnvalidatedPtrType map[string]*string -// +k8s:validateFalse="type MapPtrType" -// +k8s:eachVal=+k8s:validateFalse="type MapPtrType[*]" -type MapPtrType map[string]*string - // +k8s:validateFalse="type StringType" type StringType string @@ -54,10 +50,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" MapField MapType `json:"mapField"` - // +k8s:validateFalse="field Struct.MapPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField MapPtrType `json:"mapPtrField"` - // +k8s:validateFalse="field Struct.MapTypedefField" // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" MapTypedefField MapTypedefType `json:"mapTypedefField"` diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/testdata/validate-false.json index 3f0c577c14d..fc567bc0b90 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/testdata/validate-false.json +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/testdata/validate-false.json @@ -15,28 +15,16 @@ "field Struct.MapField[*]", "type MapType[*]" ], - "mapPtrField": [ - "field Struct.MapPtrField", - "type MapPtrType" - ], - "mapPtrField[V噘¢\u003eóDz岋笨Gń條ģ]": [ - "field Struct.MapPtrField[*]", - "type MapPtrType[*]" - ], - "mapPtrField[讻IeYF墄[C]": [ - "field Struct.MapPtrField[*]", - "type MapPtrType[*]" - ], "mapTypedefField": [ "field Struct.MapTypedefField", "type MapTypedefType" ], - "mapTypedefField[\u003eƯ]ɹȽ東潇澍]": [ + "mapTypedefField[V噘¢\u003eóDz岋笨Gń條ģ]": [ "field Struct.MapTypedefField[*]", "type MapTypedefType[*]", "type StringType" ], - "mapTypedefField[闌剾溏]": [ + "mapTypedefField[þƿ髈儱Ŀ蒫÷K鬣壈]": [ "field Struct.MapTypedefField[*]", "type MapTypedefType[*]", "type StringType" diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/zz_generated.validations.go index 87a580b2391..30ba56890db 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maps/typedef_to_map/zz_generated.validations.go @@ -46,16 +46,6 @@ func RegisterValidations(scheme *testscheme.Scheme) error { return nil } -func Validate_MapPtrType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapPtrType) (errs field.ErrorList) { - // type MapPtrType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapPtrType")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapPtrType[*]") - })...) - - return errs -} - func Validate_MapType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) (errs field.ErrorList) { // type MapType errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType")...) @@ -101,17 +91,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) MapType { return oldObj.MapField }))...) - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj MapPtrType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - errs = append(errs, Validate_MapPtrType(ctx, op, fldPath, obj, oldObj)...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) MapPtrType { return oldObj.MapPtrField }))...) - // field Struct.MapTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj MapTypedefType) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/doc.go index aceef728014..87c547d8eaf 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/doc.go @@ -48,10 +48,6 @@ type T2 struct { PT2 *T2 `json:"pt2"` } -// +k8s:validateFalse="type E1" -// +k8s:eachVal=+k8s:validateFalse="type E1 values" -type E1 []E1 - // NOTE: no validations. type T3 struct { // NOTE: no validations. diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/zz_generated.validations.go index 11960e68b0c..dbb6360f0c5 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/recursive/zz_generated.validations.go @@ -37,12 +37,6 @@ func init() { localSchemeBuilder.Register(RegisterValidations) } // RegisterValidations adds validation functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((E1)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_E1(ctx, op, nil /* fldPath */, obj.(E1), safe.Cast[E1](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) scheme.AddValidationFunc((*T1)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { if len(subresources) == 0 { return Validate_T1(ctx, op, nil /* fldPath */, obj.(*T1), safe.Cast[*T1](oldObj)) @@ -58,17 +52,6 @@ func RegisterValidations(scheme *testscheme.Scheme) error { return nil } -func Validate_E1(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj E1) (errs field.ErrorList) { - // type E1 - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type E1")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj E1) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type E1 values") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_E1)...) - - return errs -} - func Validate_T1(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *T1) (errs field.ErrorList) { // type T1 errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type T1")...) diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/doc.go deleted file mode 100644 index 1c4f0d69ecb..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/doc.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.ListField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*][*]" - ListField []map[string]string `json:"listField"` - - // +k8s:validateFalse="field Struct.ListPtrField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*][*]" - ListPtrField []map[string]*string `json:"listPtrField"` - - // +k8s:validateFalse="field Struct.ListTypedefField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*][*]" - ListTypedefField []MapType `json:"listTypedefField"` - - UnvalidatedListField []MapType `json:"UnvalidatedListField"` -} - -// +k8s:validateFalse="type MapType" -// +k8s:eachVal=+k8s:validateFalse="type MapType[*]" -type MapType map[string]StringType - -// +k8s:validateFalse="type StringType" -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/testdata/validate-false.json deleted file mode 100644 index a84abc044c6..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/testdata/validate-false.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "*deep.Struct": { - "": [ - "type Struct" - ], - "UnvalidatedListField[0]": [ - "type MapType" - ], - "UnvalidatedListField[0][`JT瘮Q8ý]": [ - "type MapType[*]", - "type StringType" - ], - "UnvalidatedListField[0][答Bc黰¢]": [ - "type MapType[*]", - "type StringType" - ], - "UnvalidatedListField[1]": [ - "type MapType" - ], - "UnvalidatedListField[1][ɸ¢\u003c1]": [ - "type MapType[*]", - "type StringType" - ], - "UnvalidatedListField[1][黷Ǭ}J攷Ǥ\u003e]": [ - "type MapType[*]", - "type StringType" - ], - "listField": [ - "field Struct.ListField" - ], - "listField[0][ũ桑I朻 9铃]3g!fȺ苬ĥ]": [ - "field Struct.ListField[*][*]" - ], - "listField[0][袢捺悲ȅ-@烱ęssĂZ稈V噘¢\u003e]": [ - "field Struct.ListField[*][*]" - ], - "listField[1][Ì]": [ - "field Struct.ListField[*][*]" - ], - "listField[1][讻IeYF墄[C]": [ - "field Struct.ListField[*][*]" - ], - "listPtrField": [ - "field Struct.ListPtrField" - ], - "listPtrField[0][ș$0đ\u003eƯ]ɹȽ東]": [ - "field Struct.ListPtrField[*][*]" - ], - "listPtrField[0][伸~槱¡rŔ綂2暮斚嬆ʅ]": [ - "field Struct.ListPtrField[*][*]" - ], - "listPtrField[1][瑻霳鸻ȉĔ]": [ - "field Struct.ListPtrField[*][*]" - ], - "listPtrField[1][豐Ȭ-ƀh婉Ţ飦tD6ɀk諮]": [ - "field Struct.ListPtrField[*][*]" - ], - "listTypedefField": [ - "field Struct.ListTypedefField" - ], - "listTypedefField[0]": [ - "type MapType" - ], - "listTypedefField[0][ƹ棳]": [ - "field Struct.ListTypedefField[*][*]", - "type MapType[*]", - "type StringType" - ], - "listTypedefField[0][溹*x唎蕍冻垰40F7楣ƛ隨Ǩmȷā]": [ - "field Struct.ListTypedefField[*][*]", - "type MapType[*]", - "type StringType" - ], - "listTypedefField[1]": [ - "type MapType" - ], - "listTypedefField[1][G炕炎鷖Ʊ腘]": [ - "field Struct.ListTypedefField[*][*]", - "type MapType[*]", - "type StringType" - ], - "listTypedefField[1][鷸ȳ琍殪\"g踮螧喘夓麑Y·L继Ɂ]": [ - "field Struct.ListTypedefField[*][*]", - "type MapType[*]", - "type StringType" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/zz_generated.validations.go deleted file mode 100644 index aa0adeae7ed..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/zz_generated.validations.go +++ /dev/null @@ -1,118 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_MapType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) (errs field.ErrorList) { - // type MapType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType")...) - errs = append(errs, validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType[*]") - })...) - errs = append(errs, validate.EachMapVal(ctx, op, fldPath, obj, oldObj, Validate_StringType)...) - - return errs -} - -func Validate_StringType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) (errs field.ErrorList) { - // type StringType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type StringType")...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*][*]") - }) - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []map[string]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []map[string]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []MapType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*][*]") - }) - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_MapType)...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []MapType { return oldObj.ListTypedefField }))...) - - // field Struct.UnvalidatedListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []MapType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_MapType)...) - return - }(fldPath.Child("UnvalidatedListField"), obj.UnvalidatedListField, safe.Field(oldObj, func(oldObj *Struct) []MapType { return oldObj.UnvalidatedListField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/zz_generated.validations_test.go deleted file mode 100644 index 1073c9c6366..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/deep/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/doc.go deleted file mode 100644 index 6cabc3110b6..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/doc.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.ListField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" - ListField []map[string]string `json:"listField"` - - // +k8s:validateFalse="field Struct.ListPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField []map[string]*string `json:"listPtrField"` - - // +k8s:validateFalse="field Struct.ListTypedefField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" - ListTypedefField []MapType `json:"listTypedefField"` - - UnvalidatedListField []MapType `json:"UnvalidatedListField"` -} - -// +k8s:validateFalse="type MapType" -// +k8s:eachVal=+k8s:validateFalse="type MapType[*]" -type MapType map[string]StringType - -// +k8s:validateFalse="type StringType" -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/testdata/validate-false.json deleted file mode 100644 index 3d2cbc8eac3..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/testdata/validate-false.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "*shallow.Struct": { - "": [ - "type Struct" - ], - "UnvalidatedListField[0]": [ - "type MapType" - ], - "UnvalidatedListField[0][`JT瘮Q8ý]": [ - "type MapType[*]", - "type StringType" - ], - "UnvalidatedListField[0][答Bc黰¢]": [ - "type MapType[*]", - "type StringType" - ], - "UnvalidatedListField[1]": [ - "type MapType" - ], - "UnvalidatedListField[1][ɸ¢\u003c1]": [ - "type MapType[*]", - "type StringType" - ], - "UnvalidatedListField[1][黷Ǭ}J攷Ǥ\u003e]": [ - "type MapType[*]", - "type StringType" - ], - "listField": [ - "field Struct.ListField" - ], - "listField[0]": [ - "field Struct.ListField[*]" - ], - "listField[1]": [ - "field Struct.ListField[*]" - ], - "listPtrField": [ - "field Struct.ListPtrField" - ], - "listPtrField[0]": [ - "field Struct.ListPtrField[*]" - ], - "listPtrField[1]": [ - "field Struct.ListPtrField[*]" - ], - "listTypedefField": [ - "field Struct.ListTypedefField" - ], - "listTypedefField[0]": [ - "field Struct.ListTypedefField[*]", - "type MapType" - ], - "listTypedefField[0][ƹ棳]": [ - "type MapType[*]", - "type StringType" - ], - "listTypedefField[0][溹*x唎蕍冻垰40F7楣ƛ隨Ǩmȷā]": [ - "type MapType[*]", - "type StringType" - ], - "listTypedefField[1]": [ - "field Struct.ListTypedefField[*]", - "type MapType" - ], - "listTypedefField[1][G炕炎鷖Ʊ腘]": [ - "type MapType[*]", - "type StringType" - ], - "listTypedefField[1][鷸ȳ琍殪\"g踮螧喘夓麑Y·L继Ɂ]": [ - "type MapType[*]", - "type StringType" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/zz_generated.validations.go deleted file mode 100644 index 5aaed6c9de1..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/zz_generated.validations.go +++ /dev/null @@ -1,112 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_MapType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) (errs field.ErrorList) { - // type MapType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType")...) - errs = append(errs, validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapType[*]") - })...) - errs = append(errs, validate.EachMapVal(ctx, op, fldPath, obj, oldObj, Validate_StringType)...) - - return errs -} - -func Validate_StringType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) (errs field.ErrorList) { - // type StringType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type StringType")...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*]") - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []map[string]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []map[string]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []MapType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*]") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_MapType)...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []MapType { return oldObj.ListTypedefField }))...) - - // field Struct.UnvalidatedListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []MapType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_MapType)...) - return - }(fldPath.Child("UnvalidatedListField"), obj.UnvalidatedListField, safe.Field(oldObj, func(oldObj *Struct) []MapType { return oldObj.UnvalidatedListField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/zz_generated.validations_test.go deleted file mode 100644 index 138bc67084c..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_map/shallow/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/doc.go index 136725c6e67..600fd8be153 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/doc.go @@ -33,18 +33,10 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" ListField []string `json:"listField"` - // +k8s:validateFalse="field Struct.ListPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField []*string `json:"listPtrField"` - // +k8s:validateFalse="field Struct.ListTypedefField" // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" ListTypedefField []StringType `json:"listTypedefField"` - // +k8s:validateFalse="field Struct.ListTypedefPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefPtrField[*]" - ListTypedefPtrField []*StringType `json:"listTypedefPtrField"` - UnvalidatedListField []string `json:"UnvalidatedListField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/testdata/validate-false.json index 5621c7728f1..bcfd8a0da59 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/testdata/validate-false.json +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/testdata/validate-false.json @@ -12,15 +12,6 @@ "listField[1]": [ "field Struct.ListField[*]" ], - "listPtrField": [ - "field Struct.ListPtrField" - ], - "listPtrField[0]": [ - "field Struct.ListPtrField[*]" - ], - "listPtrField[1]": [ - "field Struct.ListPtrField[*]" - ], "listTypedefField": [ "field Struct.ListTypedefField" ], @@ -31,17 +22,6 @@ "listTypedefField[1]": [ "field Struct.ListTypedefField[*]", "type StringType" - ], - "listTypedefPtrField": [ - "field Struct.ListTypedefPtrField" - ], - "listTypedefPtrField[0]": [ - "field Struct.ListTypedefPtrField[*]", - "type StringType" - ], - "listTypedefPtrField[1]": [ - "field Struct.ListTypedefPtrField[*]", - "type StringType" ] } } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/zz_generated.validations.go index 95a1d4dc7c4..a368910f023 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_primitive/zz_generated.validations.go @@ -69,16 +69,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []string { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []*string { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj []StringType) (errs field.ErrorList) { @@ -90,17 +80,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []StringType { return oldObj.ListTypedefField }))...) - // field Struct.ListTypedefPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*StringType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefPtrField[*]") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_StringType)...) - return - }(fldPath.Child("listTypedefPtrField"), obj.ListTypedefPtrField, safe.Field(oldObj, func(oldObj *Struct) []*StringType { return oldObj.ListTypedefPtrField }))...) - // field Struct.UnvalidatedListField has no validation return errs } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/doc.go deleted file mode 100644 index d18df596f9a..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/doc.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.ListField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*][*]" - ListField [][]string `json:"listField"` - - // +k8s:validateFalse="field Struct.ListPtrField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*][*]" - ListPtrField [][]*string `json:"listPtrField"` - - // +k8s:validateFalse="field Struct.ListTypedefField" - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*][*]" - ListTypedefField []SliceType `json:"listTypedefField"` - - UnvalidatedListField []SliceType `json:"UnvalidatedListField"` -} - -// +k8s:validateFalse="type SliceType" -// +k8s:eachVal=+k8s:validateFalse="type SliceType[*]" -type SliceType []StringType - -// +k8s:validateFalse="type StringType" -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/testdata/validate-false.json deleted file mode 100644 index 82af436c7f8..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/testdata/validate-false.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "*deep.Struct": { - "": [ - "type Struct" - ], - "UnvalidatedListField[0]": [ - "type SliceType" - ], - "UnvalidatedListField[0][0]": [ - "type SliceType[*]", - "type StringType" - ], - "UnvalidatedListField[0][1]": [ - "type SliceType[*]", - "type StringType" - ], - "UnvalidatedListField[1]": [ - "type SliceType" - ], - "UnvalidatedListField[1][0]": [ - "type SliceType[*]", - "type StringType" - ], - "UnvalidatedListField[1][1]": [ - "type SliceType[*]", - "type StringType" - ], - "listField": [ - "field Struct.ListField" - ], - "listField[0][0]": [ - "field Struct.ListField[*][*]" - ], - "listField[0][1]": [ - "field Struct.ListField[*][*]" - ], - "listField[1][0]": [ - "field Struct.ListField[*][*]" - ], - "listField[1][1]": [ - "field Struct.ListField[*][*]" - ], - "listPtrField": [ - "field Struct.ListPtrField" - ], - "listPtrField[0][0]": [ - "field Struct.ListPtrField[*][*]" - ], - "listPtrField[0][1]": [ - "field Struct.ListPtrField[*][*]" - ], - "listPtrField[1][0]": [ - "field Struct.ListPtrField[*][*]" - ], - "listPtrField[1][1]": [ - "field Struct.ListPtrField[*][*]" - ], - "listTypedefField": [ - "field Struct.ListTypedefField" - ], - "listTypedefField[0]": [ - "type SliceType" - ], - "listTypedefField[0][0]": [ - "field Struct.ListTypedefField[*][*]", - "type SliceType[*]", - "type StringType" - ], - "listTypedefField[0][1]": [ - "field Struct.ListTypedefField[*][*]", - "type SliceType[*]", - "type StringType" - ], - "listTypedefField[1]": [ - "type SliceType" - ], - "listTypedefField[1][0]": [ - "field Struct.ListTypedefField[*][*]", - "type SliceType[*]", - "type StringType" - ], - "listTypedefField[1][1]": [ - "field Struct.ListTypedefField[*][*]", - "type SliceType[*]", - "type StringType" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/zz_generated.validations.go deleted file mode 100644 index 1af62ce352d..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/zz_generated.validations.go +++ /dev/null @@ -1,118 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_SliceType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) (errs field.ErrorList) { - // type SliceType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type SliceType")...) - errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type SliceType[*]") - })...) - errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, Validate_StringType)...) - - return errs -} - -func Validate_StringType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) (errs field.ErrorList) { - // type StringType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type StringType")...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*][*]") - }) - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) [][]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) [][]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []SliceType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*][*]") - }) - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_SliceType)...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []SliceType { return oldObj.ListTypedefField }))...) - - // field Struct.UnvalidatedListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []SliceType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_SliceType)...) - return - }(fldPath.Child("UnvalidatedListField"), obj.UnvalidatedListField, safe.Field(oldObj, func(oldObj *Struct) []SliceType { return oldObj.UnvalidatedListField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/zz_generated.validations_test.go deleted file mode 100644 index 1073c9c6366..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/deep/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/doc.go deleted file mode 100644 index cd4e3bfd7a7..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/doc.go +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme -// +k8s:validation-gen-test-fixture=validateFalse - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -// +k8s:validateFalse="type Struct" -type Struct struct { - TypeMeta int - - // +k8s:validateFalse="field Struct.ListField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" - ListField [][]string `json:"listField"` - - // +k8s:validateFalse="field Struct.ListPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField [][]*string `json:"listPtrField"` - - // +k8s:validateFalse="field Struct.ListTypedefField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" - ListTypedefField []SliceType `json:"listTypedefField"` - - UnvalidatedListField []SliceType `json:"UnvalidatedListField"` -} - -// +k8s:validateFalse="type SliceType" -// +k8s:eachVal=+k8s:validateFalse="type SliceType[*]" -type SliceType []StringType - -// +k8s:validateFalse="type StringType" -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/testdata/validate-false.json deleted file mode 100644 index da53a383321..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/testdata/validate-false.json +++ /dev/null @@ -1,74 +0,0 @@ -{ - "*shallow.Struct": { - "": [ - "type Struct" - ], - "UnvalidatedListField[0]": [ - "type SliceType" - ], - "UnvalidatedListField[0][0]": [ - "type SliceType[*]", - "type StringType" - ], - "UnvalidatedListField[0][1]": [ - "type SliceType[*]", - "type StringType" - ], - "UnvalidatedListField[1]": [ - "type SliceType" - ], - "UnvalidatedListField[1][0]": [ - "type SliceType[*]", - "type StringType" - ], - "UnvalidatedListField[1][1]": [ - "type SliceType[*]", - "type StringType" - ], - "listField": [ - "field Struct.ListField" - ], - "listField[0]": [ - "field Struct.ListField[*]" - ], - "listField[1]": [ - "field Struct.ListField[*]" - ], - "listPtrField": [ - "field Struct.ListPtrField" - ], - "listPtrField[0]": [ - "field Struct.ListPtrField[*]" - ], - "listPtrField[1]": [ - "field Struct.ListPtrField[*]" - ], - "listTypedefField": [ - "field Struct.ListTypedefField" - ], - "listTypedefField[0]": [ - "field Struct.ListTypedefField[*]", - "type SliceType" - ], - "listTypedefField[0][0]": [ - "type SliceType[*]", - "type StringType" - ], - "listTypedefField[0][1]": [ - "type SliceType[*]", - "type StringType" - ], - "listTypedefField[1]": [ - "field Struct.ListTypedefField[*]", - "type SliceType" - ], - "listTypedefField[1][0]": [ - "type SliceType[*]", - "type StringType" - ], - "listTypedefField[1][1]": [ - "type SliceType[*]", - "type StringType" - ] - } - } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/zz_generated.validations.go deleted file mode 100644 index 37b6a42cd10..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/zz_generated.validations.go +++ /dev/null @@ -1,112 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_SliceType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) (errs field.ErrorList) { - // type SliceType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type SliceType")...) - errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type SliceType[*]") - })...) - errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, Validate_StringType)...) - - return errs -} - -func Validate_StringType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) (errs field.ErrorList) { - // type StringType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type StringType")...) - - return errs -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // type Struct - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type Struct")...) - - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*]") - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) [][]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]*string) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) [][]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []SliceType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*]") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_SliceType)...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []SliceType { return oldObj.ListTypedefField }))...) - - // field Struct.UnvalidatedListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []SliceType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_SliceType)...) - return - }(fldPath.Child("UnvalidatedListField"), obj.UnvalidatedListField, safe.Field(oldObj, func(oldObj *Struct) []SliceType { return oldObj.UnvalidatedListField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/zz_generated.validations_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/zz_generated.validations_test.go deleted file mode 100644 index 138bc67084c..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_slice/shallow/zz_generated.validations_test.go +++ /dev/null @@ -1,30 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - "testing" -) - -func TestValidation(t *testing.T) { - localSchemeBuilder.Test(t).ValidateFixtures() -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/doc.go index db10f04fe43..efc4cb1b961 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/doc.go @@ -33,18 +33,10 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" ListField []OtherStruct `json:"listField"` - // +k8s:validateFalse="field Struct.ListPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField []*OtherStruct `json:"listPtrField"` - // +k8s:validateFalse="field Struct.ListTypedefField" // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" ListTypedefField []OtherTypedefStruct `json:"listTypedefField"` - // +k8s:validateFalse="field Struct.ListTypedefPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefPtrField[*]" - ListTypedefPtrField []*OtherTypedefStruct `json:"listTypedefPtrField"` - UnvalidatedListField []OtherStruct `json:"UnvalidatedListField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/testdata/validate-false.json index 83bd4428553..d8d4e1cc49f 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/testdata/validate-false.json +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/testdata/validate-false.json @@ -20,17 +20,6 @@ "field Struct.ListField[*]", "type OtherStruct" ], - "listPtrField": [ - "field Struct.ListPtrField" - ], - "listPtrField[0]": [ - "field Struct.ListPtrField[*]", - "type OtherStruct" - ], - "listPtrField[1]": [ - "field Struct.ListPtrField[*]", - "type OtherStruct" - ], "listTypedefField": [ "field Struct.ListTypedefField" ], @@ -41,17 +30,6 @@ "listTypedefField[1]": [ "field Struct.ListTypedefField[*]", "type OtherTypedefStruct" - ], - "listTypedefPtrField": [ - "field Struct.ListTypedefPtrField" - ], - "listTypedefPtrField[0]": [ - "field Struct.ListTypedefPtrField[*]", - "type OtherTypedefStruct" - ], - "listTypedefPtrField[1]": [ - "field Struct.ListTypedefPtrField[*]", - "type OtherTypedefStruct" ] } } \ No newline at end of file diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/zz_generated.validations.go index 3fbeb896f87..c8edb7ca110 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/slice_of_struct/zz_generated.validations.go @@ -77,17 +77,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_OtherStruct)...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherTypedefStruct) (errs field.ErrorList) { @@ -99,17 +88,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []OtherTypedefStruct { return oldObj.ListTypedefField }))...) - // field Struct.ListTypedefPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherTypedefStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherTypedefStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefPtrField[*]") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_OtherTypedefStruct)...) - return - }(fldPath.Child("listTypedefPtrField"), obj.ListTypedefPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherTypedefStruct { return oldObj.ListTypedefPtrField }))...) - // field Struct.UnvalidatedListField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherStruct) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/doc.go index 34a0a26b984..b1156af06d0 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/doc.go @@ -35,10 +35,6 @@ type ListType []string // Note: no validation here type UnvalidatedPtrType []*string -// +k8s:validateFalse="type ListPtrType" -// +k8s:eachVal=+k8s:validateFalse="type ListPtrType[*]" -type ListPtrType []*string - // +k8s:validateFalse="type StringType" type StringType string @@ -54,10 +50,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" ListField ListType `json:"listField"` - // +k8s:validateFalse="field Struct.ListPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField ListPtrType `json:"listPtrField"` - // +k8s:validateFalse="field Struct.ListTypedefField" // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" ListTypedefField ListTypedefType `json:"listTypedefField"` diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/testdata/validate-false.json b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/testdata/validate-false.json index ee7e19b193e..226e13d4f69 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/testdata/validate-false.json +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/testdata/validate-false.json @@ -15,18 +15,6 @@ "field Struct.ListField[*]", "type ListType[*]" ], - "listPtrField": [ - "field Struct.ListPtrField", - "type ListPtrType" - ], - "listPtrField[0]": [ - "field Struct.ListPtrField[*]", - "type ListPtrType[*]" - ], - "listPtrField[1]": [ - "field Struct.ListPtrField[*]", - "type ListPtrType[*]" - ], "listTypedefField": [ "field Struct.ListTypedefField", "type ListTypedefType" diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/zz_generated.validations.go index dc06f2e2bde..589ed49974b 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/slices/typedef_to_slice/zz_generated.validations.go @@ -46,16 +46,6 @@ func RegisterValidations(scheme *testscheme.Scheme) error { return nil } -func Validate_ListPtrType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj ListPtrType) (errs field.ErrorList) { - // type ListPtrType - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type ListPtrType")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type ListPtrType[*]") - })...) - - return errs -} - func Validate_ListType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj ListType) (errs field.ErrorList) { // type ListType errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type ListType")...) @@ -101,17 +91,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) ListType { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj ListPtrType) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - errs = append(errs, Validate_ListPtrType(ctx, op, fldPath, obj, oldObj)...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) ListPtrType { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj ListTypedefType) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/doc.go deleted file mode 100644 index ae7a225f6b6..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/doc.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*][*]" - MapField map[string]map[string]string `json:"mapField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*][*]" - MapPtrField map[string]map[string]*string `json:"mapPtrField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*][*]" - MapTypedefField map[string]MapType `json:"mapTypedefField"` -} - -type MapType map[string]string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/doc_test.go deleted file mode 100644 index 1ebfbff77a0..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/doc_test.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package deep - -import ( - "testing" - - "k8s.io/utils/ptr" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - MapField: map[string]map[string]string{ - "a": {"x": "X", "y": "Y"}, - "b": {"x": "X", "y": "Y"}, - }, - MapPtrField: map[string]map[string]*string{ - "a": {"x": ptr.To("X"), "y": ptr.To("Y")}, - "b": {"x": ptr.To("X"), "y": ptr.To("Y")}, - }, - MapTypedefField: map[string]MapType{ - "a": {"x": "X", "y": "Y"}, - "b": {"x": "X", "y": "Y"}, - }, - }).ExpectValidateFalseByPath(map[string][]string{ - "mapField[a][x]": {"field Struct.MapField[*][*]"}, - "mapField[a][y]": {"field Struct.MapField[*][*]"}, - "mapField[b][x]": {"field Struct.MapField[*][*]"}, - "mapField[b][y]": {"field Struct.MapField[*][*]"}, - "mapPtrField[a][x]": {"field Struct.MapPtrField[*][*]"}, - "mapPtrField[a][y]": {"field Struct.MapPtrField[*][*]"}, - "mapPtrField[b][x]": {"field Struct.MapPtrField[*][*]"}, - "mapPtrField[b][y]": {"field Struct.MapPtrField[*][*]"}, - "mapTypedefField[a][x]": {"field Struct.MapTypedefField[*][*]"}, - "mapTypedefField[a][y]": {"field Struct.MapTypedefField[*][*]"}, - "mapTypedefField[b][x]": {"field Struct.MapTypedefField[*][*]"}, - "mapTypedefField[b][y]": {"field Struct.MapTypedefField[*][*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/zz_generated.validations.go deleted file mode 100644 index 4801853211d..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/deep/zz_generated.validations.go +++ /dev/null @@ -1,86 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*][*]") - }) - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]MapType) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*][*]") - }) - })...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]MapType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/doc.go deleted file mode 100644 index c66fe155460..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/doc.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" - MapField map[string]map[string]string `json:"mapField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string]map[string]*string `json:"mapPtrField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" - MapTypedefField map[string]MapType `json:"mapTypedefField"` -} - -type MapType map[string]string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/doc_test.go deleted file mode 100644 index 09ca811d36f..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/doc_test.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package shallow - -import ( - "testing" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - MapField: map[string]map[string]string{"a": {}, "b": {}}, - MapPtrField: map[string]map[string]*string{"a": {}, "b": {}}, - MapTypedefField: map[string]MapType{"a": {}, "b": {}}, - }).ExpectValidateFalseByPath(map[string][]string{ - "mapField[a]": {"field Struct.MapField[*]"}, - "mapField[b]": {"field Struct.MapField[*]"}, - "mapPtrField[a]": {"field Struct.MapPtrField[*]"}, - "mapPtrField[b]": {"field Struct.MapPtrField[*]"}, - "mapTypedefField[a]": {"field Struct.MapTypedefField[*]"}, - "mapTypedefField[b]": {"field Struct.MapTypedefField[*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/zz_generated.validations.go deleted file mode 100644 index 59722925ae1..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_map/shallow/zz_generated.validations.go +++ /dev/null @@ -1,80 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*]") - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]map[string]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]MapType) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*]") - })...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]MapType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc.go index c5b8c497b7d..72c41a9c87a 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc.go @@ -30,9 +30,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" MapField map[string]string `json:"mapField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string]*string `json:"mapPtrField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" MapTypedefField map[string]StringType `json:"mapTypedefField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc_test.go index 91ea8828c22..05f4678f70a 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/doc_test.go @@ -18,8 +18,6 @@ package mapofprimitive import ( "testing" - - "k8s.io/utils/ptr" ) func Test(t *testing.T) { @@ -31,13 +29,10 @@ func Test(t *testing.T) { st.Value(&Struct{ MapField: map[string]string{"a": "A", "b": "B"}, - MapPtrField: map[string]*string{"a": ptr.To("A"), "b": ptr.To("B")}, MapTypedefField: map[string]StringType{"a": "A", "b": "B"}, }).ExpectValidateFalseByPath(map[string][]string{ "mapField[a]": {"field Struct.MapField[*]"}, "mapField[b]": {"field Struct.MapField[*]"}, - "mapPtrField[a]": {"field Struct.MapPtrField[*]"}, - "mapPtrField[b]": {"field Struct.MapPtrField[*]"}, "mapTypedefField[a]": {"field Struct.MapTypedefField[*]"}, "mapTypedefField[b]": {"field Struct.MapTypedefField[*]"}, }) diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/zz_generated.validations.go index 4e8ef20f155..18e567a22ed 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_primitive/zz_generated.validations.go @@ -58,15 +58,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]string { return oldObj.MapField }))...) - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]*string { return oldObj.MapPtrField }))...) - // field Struct.MapTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj map[string]StringType) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/doc.go deleted file mode 100644 index 76677cb2f28..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/doc.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*][*]" - MapField map[string][]string `json:"mapField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*][*]" - MapPtrField map[string][]*string `json:"mapPtrField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*][*]" - MapTypedefField map[string]SliceType `json:"mapTypedefField"` -} - -type SliceType []StringType - -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/doc_test.go deleted file mode 100644 index 0e920d8100c..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/doc_test.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package deep - -import ( - "testing" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - MapField: map[string][]string{"a": make([]string, 2), "b": make([]string, 2)}, - MapPtrField: map[string][]*string{"a": make([]*string, 2), "b": make([]*string, 2)}, - MapTypedefField: map[string]SliceType{"a": make(SliceType, 2), "b": make(SliceType, 2)}, - }).ExpectValidateFalseByPath(map[string][]string{ - "mapField[a][0]": {"field Struct.MapField[*][*]"}, - "mapField[a][1]": {"field Struct.MapField[*][*]"}, - "mapField[b][0]": {"field Struct.MapField[*][*]"}, - "mapField[b][1]": {"field Struct.MapField[*][*]"}, - "mapPtrField[a][0]": {"field Struct.MapPtrField[*][*]"}, - "mapPtrField[a][1]": {"field Struct.MapPtrField[*][*]"}, - "mapPtrField[b][0]": {"field Struct.MapPtrField[*][*]"}, - "mapPtrField[b][1]": {"field Struct.MapPtrField[*][*]"}, - "mapTypedefField[a][0]": {"field Struct.MapTypedefField[*][*]"}, - "mapTypedefField[a][1]": {"field Struct.MapTypedefField[*][*]"}, - "mapTypedefField[b][0]": {"field Struct.MapTypedefField[*][*]"}, - "mapTypedefField[b][1]": {"field Struct.MapTypedefField[*][*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/zz_generated.validations.go deleted file mode 100644 index 408e719a568..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/deep/zz_generated.validations.go +++ /dev/null @@ -1,86 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*][*]") - }) - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string][]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string][]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]SliceType) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*][*]") - }) - })...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]SliceType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/doc.go deleted file mode 100644 index 66fcb9703c1..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/doc.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" - MapField map[string][]string `json:"mapField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string][]*string `json:"mapPtrField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" - MapTypedefField map[string]SliceType `json:"mapTypedefField"` -} - -type SliceType []string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/doc_test.go deleted file mode 100644 index 65bc95877a0..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/doc_test.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package shallow - -import ( - "testing" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - MapField: map[string][]string{"a": make([]string, 0), "b": make([]string, 0)}, - MapPtrField: map[string][]*string{"a": make([]*string, 0), "b": make([]*string, 0)}, - MapTypedefField: map[string]SliceType{"a": make(SliceType, 0), "b": make(SliceType, 0)}, - }).ExpectValidateFalseByPath(map[string][]string{ - "mapField[a]": {"field Struct.MapField[*]"}, - "mapField[b]": {"field Struct.MapField[*]"}, - "mapPtrField[a]": {"field Struct.MapPtrField[*]"}, - "mapPtrField[b]": {"field Struct.MapPtrField[*]"}, - "mapTypedefField[a]": {"field Struct.MapTypedefField[*]"}, - "mapTypedefField[b]": {"field Struct.MapTypedefField[*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/zz_generated.validations.go deleted file mode 100644 index 030646963e5..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_slice/shallow/zz_generated.validations.go +++ /dev/null @@ -1,80 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.MapField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapField[*]") - })...) - return - }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string][]string { return oldObj.MapField }))...) - - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string][]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string][]*string { return oldObj.MapPtrField }))...) - - // field Struct.MapTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]SliceType) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapTypedefField[*]") - })...) - return - }(fldPath.Child("mapTypedefField"), obj.MapTypedefField, safe.Field(oldObj, func(oldObj *Struct) map[string]SliceType { return oldObj.MapTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc.go index 9d89282ad2b..67baf8fc195 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc.go @@ -30,9 +30,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" MapField map[string]OtherStruct `json:"mapField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField map[string]*OtherStruct `json:"mapPtrField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" MapTypedefField map[string]OtherTypedefStruct `json:"mapTypedefField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc_test.go index 63e164cbecc..155826edcb6 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/doc_test.go @@ -29,13 +29,10 @@ func Test(t *testing.T) { st.Value(&Struct{ MapField: map[string]OtherStruct{"a": {}, "b": {}}, - MapPtrField: map[string]*OtherStruct{"a": {}, "b": {}}, MapTypedefField: map[string]OtherTypedefStruct{"a": {}, "b": {}}, }).ExpectValidateFalseByPath(map[string][]string{ "mapField[a]": {"field Struct.MapField[*]"}, "mapField[b]": {"field Struct.MapField[*]"}, - "mapPtrField[a]": {"field Struct.MapPtrField[*]"}, - "mapPtrField[b]": {"field Struct.MapPtrField[*]"}, "mapTypedefField[a]": {"field Struct.MapTypedefField[*]"}, "mapTypedefField[b]": {"field Struct.MapTypedefField[*]"}, }) diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/zz_generated.validations.go index 3ace356b5db..e3592fad730 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/map_of_struct/zz_generated.validations.go @@ -58,15 +58,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]OtherStruct { return oldObj.MapField }))...) - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]*OtherStruct { return oldObj.MapPtrField }))...) - // field Struct.MapTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj map[string]OtherTypedefStruct) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/doc.go deleted file mode 100644 index bc8ff4cc982..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/doc.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*][*]" - ListField []map[string]string `json:"listField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*][*]" - ListPtrField []map[string]*string `json:"listPtrField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*][*]" - ListTypedefField []MapType `json:"listTypedefField"` -} - -type MapType map[string]StringType - -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/doc_test.go deleted file mode 100644 index 19aa048a41d..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/doc_test.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package deep - -import ( - "testing" - - "k8s.io/utils/ptr" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - ListField: []map[string]string{ - {"a": "A", "b": "B"}, - {"c": "C", "d": "D"}, - }, - ListPtrField: []map[string]*string{ - {"a": ptr.To("A"), "b": ptr.To("B")}, - {"c": ptr.To("C"), "d": ptr.To("D")}, - }, - ListTypedefField: []MapType{ - {"a": "A", "b": "B"}, - {"c": "C", "d": "D"}, - }, - }).ExpectValidateFalseByPath(map[string][]string{ - "listField[0][a]": {"field Struct.ListField[*][*]"}, - "listField[0][b]": {"field Struct.ListField[*][*]"}, - "listField[1][c]": {"field Struct.ListField[*][*]"}, - "listField[1][d]": {"field Struct.ListField[*][*]"}, - "listPtrField[0][a]": {"field Struct.ListPtrField[*][*]"}, - "listPtrField[0][b]": {"field Struct.ListPtrField[*][*]"}, - "listPtrField[1][c]": {"field Struct.ListPtrField[*][*]"}, - "listPtrField[1][d]": {"field Struct.ListPtrField[*][*]"}, - "listTypedefField[0][a]": {"field Struct.ListTypedefField[*][*]"}, - "listTypedefField[0][b]": {"field Struct.ListTypedefField[*][*]"}, - "listTypedefField[1][c]": {"field Struct.ListTypedefField[*][*]"}, - "listTypedefField[1][d]": {"field Struct.ListTypedefField[*][*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/zz_generated.validations.go deleted file mode 100644 index 462d72bda6c..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/deep/zz_generated.validations.go +++ /dev/null @@ -1,86 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*][*]") - }) - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []map[string]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []map[string]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []MapType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*][*]") - }) - })...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []MapType { return oldObj.ListTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/doc.go deleted file mode 100644 index f3276b67848..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/doc.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" - ListField []map[string]string `json:"listField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField []map[string]*string `json:"listPtrField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" - ListTypedefField []MapType `json:"listTypedefField"` -} - -type MapType map[string]StringType - -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/doc_test.go deleted file mode 100644 index b83c16e778d..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/doc_test.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package shallow - -import ( - "testing" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - ListField: []map[string]string{{}, {}}, - ListPtrField: []map[string]*string{{}, {}}, - ListTypedefField: []MapType{{}, {}}, - }).ExpectValidateFalseByPath(map[string][]string{ - "listField[0]": {"field Struct.ListField[*]"}, - "listField[1]": {"field Struct.ListField[*]"}, - "listPtrField[0]": {"field Struct.ListPtrField[*]"}, - "listPtrField[1]": {"field Struct.ListPtrField[*]"}, - "listTypedefField[0]": {"field Struct.ListTypedefField[*]"}, - "listTypedefField[1]": {"field Struct.ListTypedefField[*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/zz_generated.validations.go deleted file mode 100644 index e08d5009a5b..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_map/shallow/zz_generated.validations.go +++ /dev/null @@ -1,80 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*]") - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []map[string]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj map[string]*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []map[string]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []MapType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*]") - })...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []MapType { return oldObj.ListTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc.go index 8215fa7cdf8..6eb5d95d35d 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc.go @@ -30,9 +30,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" ListField []string `json:"listField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField []*string `json:"listPtrField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" ListTypedefField []StringType `json:"listTypedefField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc_test.go index 610ffd13c50..c6777fea9ef 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/doc_test.go @@ -18,8 +18,6 @@ package sliceofprimitive import ( "testing" - - "k8s.io/utils/ptr" ) func Test(t *testing.T) { @@ -31,13 +29,10 @@ func Test(t *testing.T) { st.Value(&Struct{ ListField: []string{"zero", "one"}, - ListPtrField: []*string{ptr.To("zero"), ptr.To("one")}, ListTypedefField: []StringType{StringType("zero"), StringType("one")}, }).ExpectValidateFalseByPath(map[string][]string{ "listField[0]": {"field Struct.ListField[*]"}, "listField[1]": {"field Struct.ListField[*]"}, - "listPtrField[0]": {"field Struct.ListPtrField[*]"}, - "listPtrField[1]": {"field Struct.ListPtrField[*]"}, "listTypedefField[0]": {"field Struct.ListTypedefField[*]"}, "listTypedefField[1]": {"field Struct.ListTypedefField[*]"}, }) diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/zz_generated.validations.go index e421969a220..d882315f2a6 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_primitive/zz_generated.validations.go @@ -58,15 +58,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []string { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []*string { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj []StringType) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/doc.go deleted file mode 100644 index 2d76a052370..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/doc.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package deep - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*][*]" - ListField [][]string `json:"listField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*][*]" - ListPtrField [][]*string `json:"listPtrField"` - - // +k8s:eachVal=+k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*][*]" - ListTypedefField []SliceType `json:"listTypedefField"` -} - -type SliceType []StringType - -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/doc_test.go deleted file mode 100644 index 212d87f6006..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/doc_test.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package deep - -import ( - "testing" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - ListField: [][]string{make([]string, 2), make([]string, 2)}, - ListPtrField: [][]*string{make([]*string, 2), make([]*string, 2)}, - ListTypedefField: []SliceType{make(SliceType, 2), make(SliceType, 2)}, - }).ExpectValidateFalseByPath(map[string][]string{ - "listField[0][0]": {"field Struct.ListField[*][*]"}, - "listField[0][1]": {"field Struct.ListField[*][*]"}, - "listField[1][0]": {"field Struct.ListField[*][*]"}, - "listField[1][1]": {"field Struct.ListField[*][*]"}, - "listPtrField[0][0]": {"field Struct.ListPtrField[*][*]"}, - "listPtrField[0][1]": {"field Struct.ListPtrField[*][*]"}, - "listPtrField[1][0]": {"field Struct.ListPtrField[*][*]"}, - "listPtrField[1][1]": {"field Struct.ListPtrField[*][*]"}, - "listTypedefField[0][0]": {"field Struct.ListTypedefField[*][*]"}, - "listTypedefField[0][1]": {"field Struct.ListTypedefField[*][*]"}, - "listTypedefField[1][0]": {"field Struct.ListTypedefField[*][*]"}, - "listTypedefField[1][1]": {"field Struct.ListTypedefField[*][*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/zz_generated.validations.go deleted file mode 100644 index 2b2ea1d8eaf..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/deep/zz_generated.validations.go +++ /dev/null @@ -1,86 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package deep - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*][*]") - }) - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) [][]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*][*]") - }) - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) [][]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []SliceType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *StringType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*][*]") - }) - })...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []SliceType { return oldObj.ListTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/doc.go deleted file mode 100644 index 3fdc7b1cecb..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/doc.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:validation-gen=TypeMeta -// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme - -// This is a test package. -package shallow - -import "k8s.io/code-generator/cmd/validation-gen/testscheme" - -var localSchemeBuilder = testscheme.New() - -type Struct struct { - TypeMeta int - - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" - ListField [][]string `json:"listField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField [][]*string `json:"listPtrField"` - - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" - ListTypedefField []SliceType `json:"listTypedefField"` -} - -type SliceType []StringType - -type StringType string diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/doc_test.go deleted file mode 100644 index a0528b931dd..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/doc_test.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package shallow - -import ( - "testing" -) - -func Test(t *testing.T) { - st := localSchemeBuilder.Test(t) - - st.Value(&Struct{ - // All zero values. - }).ExpectValid() - - st.Value(&Struct{ - ListField: [][]string{make([]string, 0), make([]string, 0)}, - ListPtrField: [][]*string{make([]*string, 0), make([]*string, 0)}, - ListTypedefField: []SliceType{make(SliceType, 0), make(SliceType, 0)}, - }).ExpectValidateFalseByPath(map[string][]string{ - "listField[0]": {"field Struct.ListField[*]"}, - "listField[1]": {"field Struct.ListField[*]"}, - "listPtrField[0]": {"field Struct.ListPtrField[*]"}, - "listPtrField[1]": {"field Struct.ListPtrField[*]"}, - "listTypedefField[0]": {"field Struct.ListTypedefField[*]"}, - "listTypedefField[1]": {"field Struct.ListTypedefField[*]"}, - }) -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/zz_generated.validations.go deleted file mode 100644 index 4963d0b0282..00000000000 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_slice/shallow/zz_generated.validations.go +++ /dev/null @@ -1,80 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by validation-gen. DO NOT EDIT. - -package shallow - -import ( - context "context" - fmt "fmt" - - operation "k8s.io/apimachinery/pkg/api/operation" - safe "k8s.io/apimachinery/pkg/api/safe" - validate "k8s.io/apimachinery/pkg/api/validate" - field "k8s.io/apimachinery/pkg/util/validation/field" - testscheme "k8s.io/code-generator/cmd/validation-gen/testscheme" -) - -func init() { localSchemeBuilder.Register(RegisterValidations) } - -// RegisterValidations adds validation functions to the given scheme. -// Public to allow building arbitrary schemes. -func RegisterValidations(scheme *testscheme.Scheme) error { - scheme.AddValidationFunc((*Struct)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}, subresources ...string) field.ErrorList { - if len(subresources) == 0 { - return Validate_Struct(ctx, op, nil /* fldPath */, obj.(*Struct), safe.Cast[*Struct](oldObj)) - } - return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresources: %v", obj, subresources))} - }) - return nil -} - -func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Struct) (errs field.ErrorList) { - // field Struct.TypeMeta has no validation - - // field Struct.ListField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListField[*]") - })...) - return - }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) [][]string { return oldObj.ListField }))...) - - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj [][]*string) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj []*string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) [][]*string { return oldObj.ListPtrField }))...) - - // field Struct.ListTypedefField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []SliceType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj SliceType) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListTypedefField[*]") - })...) - return - }(fldPath.Child("listTypedefField"), obj.ListTypedefField, safe.Field(oldObj, func(oldObj *Struct) []SliceType { return oldObj.ListTypedefField }))...) - - return errs -} diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc.go index 185f6de216d..6b220548240 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc.go @@ -30,9 +30,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" ListField []OtherStruct `json:"listField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField []*OtherStruct `json:"listPtrField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" ListTypedefField []OtherTypedefStruct `json:"listTypedefField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc_test.go index 61d400839cd..8675d08b617 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/doc_test.go @@ -29,13 +29,10 @@ func Test(t *testing.T) { st.Value(&Struct{ ListField: []OtherStruct{{}, {}}, - ListPtrField: []*OtherStruct{{}, {}}, ListTypedefField: []OtherTypedefStruct{{}, {}}, }).ExpectValidateFalseByPath(map[string][]string{ "listField[0]": {"field Struct.ListField[*]"}, "listField[1]": {"field Struct.ListField[*]"}, - "listPtrField[0]": {"field Struct.ListPtrField[*]"}, - "listPtrField[1]": {"field Struct.ListPtrField[*]"}, "listTypedefField[0]": {"field Struct.ListTypedefField[*]"}, "listTypedefField[1]": {"field Struct.ListTypedefField[*]"}, }) diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/zz_generated.validations.go index 37364b6f612..15560f86954 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/slice_of_struct/zz_generated.validations.go @@ -58,15 +58,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherTypedefStruct) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc.go index f8781b84694..97531ab37e8 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc.go @@ -33,9 +33,6 @@ type MapType map[string]string // Note: no validation here type UnvalidatedPtrType map[string]*string -// +k8s:eachVal=+k8s:validateFalse="type MapPtrType[*]" -type MapPtrType map[string]*string - // +k8s:validateFalse="type StringType" type StringType string @@ -49,9 +46,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.MapField[*]" MapField MapType `json:"mapField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapPtrField[*]" - MapPtrField MapPtrType `json:"mapPtrField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapTypedefField[*]" MapTypedefField MapTypedefType `json:"mapTypedefField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc_test.go index 8356531d127..a2dce9633bd 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/doc_test.go @@ -18,8 +18,6 @@ package typedeftomap import ( "testing" - - "k8s.io/utils/ptr" ) func Test(t *testing.T) { @@ -33,14 +31,11 @@ func Test(t *testing.T) { st.Value(&Struct{ MapField: MapType{"a": "A", "b": "B"}, - MapPtrField: MapPtrType{"a": ptr.To("A"), "b": ptr.To("B")}, MapTypedefField: MapTypedefType{"a": StringType("A"), "b": StringType("B")}, }).ExpectValidateFalseByPath(map[string][]string{ "": {"type Struct"}, "mapField[a]": {"type MapType[*]", "field Struct.MapField[*]"}, "mapField[b]": {"type MapType[*]", "field Struct.MapField[*]"}, - "mapPtrField[a]": {"type MapPtrType[*]", "field Struct.MapPtrField[*]"}, - "mapPtrField[b]": {"type MapPtrType[*]", "field Struct.MapPtrField[*]"}, "mapTypedefField[a]": {"type MapTypedefType[*]", "field Struct.MapTypedefField[*]", "type StringType"}, "mapTypedefField[b]": {"type MapTypedefType[*]", "field Struct.MapTypedefField[*]", "type StringType"}, }) diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/zz_generated.validations.go index 266a4fac79e..4e0f96b9a68 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_map/zz_generated.validations.go @@ -46,15 +46,6 @@ func RegisterValidations(scheme *testscheme.Scheme) error { return nil } -func Validate_MapPtrType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapPtrType) (errs field.ErrorList) { - // type MapPtrType - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type MapPtrType[*]") - })...) - - return errs -} - func Validate_MapType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj MapType) (errs field.ErrorList) { // type MapType errs = append(errs, validate.EachMapVal(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { @@ -97,16 +88,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) MapType { return oldObj.MapField }))...) - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj MapPtrType) (errs field.ErrorList) { - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapPtrField[*]") - })...) - errs = append(errs, Validate_MapPtrType(ctx, op, fldPath, obj, oldObj)...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) MapPtrType { return oldObj.MapPtrField }))...) - // field Struct.MapTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj MapTypedefType) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc.go index f256c260e30..bdd75d45e46 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc.go @@ -33,9 +33,6 @@ type ListType []string // Note: no validation here type UnvalidatedPtrType []*string -// +k8s:eachVal=+k8s:validateFalse="type ListPtrType[*]" -type ListPtrType []*string - type StringType string // +k8s:eachVal=+k8s:validateFalse="type ListTypedefType[*]" @@ -47,9 +44,6 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.ListField[*]" ListField ListType `json:"listField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListPtrField[*]" - ListPtrField ListPtrType `json:"listPtrField"` - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListTypedefField[*]" ListTypedefField ListTypedefType `json:"listTypedefField"` } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc_test.go index 2a3748182e1..6978d1155fb 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/doc_test.go @@ -18,8 +18,6 @@ package typedeftoslice import ( "testing" - - "k8s.io/utils/ptr" ) func Test(t *testing.T) { @@ -31,13 +29,10 @@ func Test(t *testing.T) { st.Value(&Struct{ ListField: ListType{"zero", "one"}, - ListPtrField: ListPtrType{ptr.To("zero"), ptr.To("one")}, ListTypedefField: ListTypedefType{StringType("zero"), StringType("one")}, }).ExpectValidateFalseByPath(map[string][]string{ "listField[0]": {"type ListType[*]", "field Struct.ListField[*]"}, "listField[1]": {"type ListType[*]", "field Struct.ListField[*]"}, - "listPtrField[0]": {"type ListPtrType[*]", "field Struct.ListPtrField[*]"}, - "listPtrField[1]": {"type ListPtrType[*]", "field Struct.ListPtrField[*]"}, "listTypedefField[0]": {"type ListTypedefType[*]", "field Struct.ListTypedefField[*]"}, "listTypedefField[1]": {"type ListTypedefType[*]", "field Struct.ListTypedefField[*]"}, }) diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/zz_generated.validations.go index 19df80478da..d005dbf7156 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/eachval/typedef_to_slice/zz_generated.validations.go @@ -46,15 +46,6 @@ func RegisterValidations(scheme *testscheme.Scheme) error { return nil } -func Validate_ListPtrType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj ListPtrType) (errs field.ErrorList) { - // type ListPtrType - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "type ListPtrType[*]") - })...) - - return errs -} - func Validate_ListType(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj ListType) (errs field.ErrorList) { // type ListType errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { @@ -86,16 +77,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) ListType { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj ListPtrType) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *string) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListPtrField[*]") - })...) - errs = append(errs, Validate_ListPtrType(ctx, op, fldPath, obj, oldObj)...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) ListPtrType { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj ListTypedefType) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/doc.go index 85e66098537..ddee7351b84 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/doc.go @@ -48,15 +48,9 @@ type Struct struct { // +k8s:immutable SliceField []string `json:"sliceField"` - // +k8s:immutable - SlicePtrField []*string `json:"slicePtrField"` - // +k8s:immutable MapField map[string]string `json:"mapField"` - // +k8s:immutable - MapPtrField map[string]*string `json:"mapPtrField"` - ImmutableField ImmutableType `json:"immutableField"` ImmutablePtrField *ImmutableType `json:"immutablePtrField"` diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/zz_generated.validations.go index d6fd69fe20e..911f89d01d7 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/immutable/zz_generated.validations.go @@ -105,13 +105,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("sliceField"), obj.SliceField, safe.Field(oldObj, func(oldObj *Struct) []string { return oldObj.SliceField }))...) - // field Struct.SlicePtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*string) (errs field.ErrorList) { - errs = append(errs, validate.ImmutableNonComparable(ctx, op, fldPath, obj, oldObj)...) - return - }(fldPath.Child("slicePtrField"), obj.SlicePtrField, safe.Field(oldObj, func(oldObj *Struct) []*string { return oldObj.SlicePtrField }))...) - // field Struct.MapField errs = append(errs, func(fldPath *field.Path, obj, oldObj map[string]string) (errs field.ErrorList) { @@ -119,13 +112,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapField"), obj.MapField, safe.Field(oldObj, func(oldObj *Struct) map[string]string { return oldObj.MapField }))...) - // field Struct.MapPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[string]*string) (errs field.ErrorList) { - errs = append(errs, validate.ImmutableNonComparable(ctx, op, fldPath, obj, oldObj)...) - return - }(fldPath.Child("mapPtrField"), obj.MapPtrField, safe.Field(oldObj, func(oldObj *Struct) map[string]*string { return oldObj.MapPtrField }))...) - // field Struct.ImmutableField errs = append(errs, func(fldPath *field.Path, obj, oldObj *ImmutableType) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc.go index 07ee005ac65..76ee4f48b84 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc.go @@ -33,12 +33,6 @@ type Struct struct { // +k8s:eachVal=+k8s:immutable ListField []OtherStruct `json:"listField"` - // +k8s:listType=map - // +k8s:listMapKey=key1Field - // +k8s:listMapKey=key2Field - // +k8s:eachVal=+k8s:immutable - ListPtrField []*OtherStruct `json:"listPtrField"` - // +k8s:listType=map // +k8s:listMapKey=key1Field // +k8s:listMapKey=key2Field diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc_test.go index 0a9dac88135..bdd41316292 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/doc_test.go @@ -30,10 +30,6 @@ func Test(t *testing.T) { {"key1", 1, "one"}, {"key2", 2, "two"}, }, - ListPtrField: []*OtherStruct{ - {"key1", 1, "one"}, - {"key2", 2, "two"}, - }, ListTypedefField: []OtherTypedefStruct{ {"key1", 1, "one"}, {"key2", 2, "two"}, @@ -46,10 +42,6 @@ func Test(t *testing.T) { {"key2", 2, "two"}, {"key1", 1, "one"}, }, - ListPtrField: []*OtherStruct{ - {"key2", 2, "two"}, - {"key1", 1, "one"}, - }, ListTypedefField: []OtherTypedefStruct{ {"key2", 2, "two"}, {"key1", 1, "one"}, @@ -63,11 +55,6 @@ func Test(t *testing.T) { {"key1", 1, "ONE"}, {"key2", 2, "TWO"}, }, - ListPtrField: []*OtherStruct{ - {"key3", 3, "THREE"}, - {"key1", 1, "ONE"}, - {"key2", 2, "TWO"}, - }, ListTypedefField: []OtherTypedefStruct{ {"key3", 3, "THREE"}, {"key1", 1, "ONE"}, @@ -82,8 +69,6 @@ func Test(t *testing.T) { st.Value(&structA1).OldValue(&structB).ExpectInvalid( field.Forbidden(field.NewPath("listField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listField").Index(1), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(0), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(1), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(1), "field is immutable"), ) @@ -92,9 +77,6 @@ func Test(t *testing.T) { field.Forbidden(field.NewPath("listField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listField").Index(1), "field is immutable"), field.Forbidden(field.NewPath("listField").Index(2), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(0), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(1), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(2), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(1), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(2), "field is immutable"), diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/zz_generated.validations.go index dbbb27ac708..fcca87c86c6 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/multiple_keys/zz_generated.validations.go @@ -58,15 +58,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, func(a *OtherStruct, b *OtherStruct) bool { - return a.Key1Field == b.Key1Field && a.Key2Field == b.Key2Field - }, validate.Immutable)...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherTypedefStruct) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc.go index 3604d97545e..4a1bd91350e 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc.go @@ -32,11 +32,6 @@ type Struct struct { // +k8s:eachVal=+k8s:immutable ListField []OtherStruct `json:"listField"` - // +k8s:listType=map - // +k8s:listMapKey=keyField - // +k8s:eachVal=+k8s:immutable - ListPtrField []*OtherStruct `json:"listPtrField"` - // +k8s:listType=map // +k8s:listMapKey=keyField // +k8s:eachVal=+k8s:immutable diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc_test.go index 10fc6c28a2f..1611788d209 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/doc_test.go @@ -30,10 +30,6 @@ func Test(t *testing.T) { {"key1", "one"}, {"key2", "two"}, }, - ListPtrField: []*OtherStruct{ - {"key1", "one"}, - {"key2", "two"}, - }, ListTypedefField: []OtherTypedefStruct{ {"key1", "one"}, {"key2", "two"}, @@ -46,10 +42,6 @@ func Test(t *testing.T) { {"key2", "two"}, {"key1", "one"}, }, - ListPtrField: []*OtherStruct{ - {"key2", "two"}, - {"key1", "one"}, - }, ListTypedefField: []OtherTypedefStruct{ {"key2", "two"}, {"key1", "one"}, @@ -63,11 +55,6 @@ func Test(t *testing.T) { {"key1", "ONE"}, {"key2", "TWO"}, }, - ListPtrField: []*OtherStruct{ - {"key3", "THREE"}, - {"key1", "ONE"}, - {"key2", "TWO"}, - }, ListTypedefField: []OtherTypedefStruct{ {"key3", "THREE"}, {"key1", "ONE"}, @@ -82,8 +69,6 @@ func Test(t *testing.T) { st.Value(&structA1).OldValue(&structB).ExpectInvalid( field.Forbidden(field.NewPath("listField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listField").Index(1), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(0), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(1), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(1), "field is immutable"), ) @@ -92,9 +77,6 @@ func Test(t *testing.T) { field.Forbidden(field.NewPath("listField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listField").Index(1), "field is immutable"), field.Forbidden(field.NewPath("listField").Index(2), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(0), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(1), "field is immutable"), - field.Forbidden(field.NewPath("listPtrField").Index(2), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(0), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(1), "field is immutable"), field.Forbidden(field.NewPath("listTypedefField").Index(2), "field is immutable"), diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/zz_generated.validations.go index 90067fa3350..2a97d956c39 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/listmap/single_key/zz_generated.validations.go @@ -56,13 +56,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listField"), obj.ListField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.ListField }))...) - // field Struct.ListPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, func(a *OtherStruct, b *OtherStruct) bool { return a.KeyField == b.KeyField }, validate.Immutable)...) - return - }(fldPath.Child("listPtrField"), obj.ListPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.ListPtrField }))...) - // field Struct.ListTypedefField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherTypedefStruct) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc.go index 1188d8e4a0c..08a5705f609 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc.go @@ -49,32 +49,17 @@ type Struct struct { // +k8s:eachVal=+k8s:validateFalse="field Struct.SliceOfStructField vals" SliceOfStructField []OtherStruct `json:"sliceOfStructField"` - // +k8s:validateFalse="field Struct.SliceOfStructPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.SliceOfStructPtrField vals" - SliceOfStructPtrField []*OtherStruct `json:"sliceOfStructPtrField"` - // +k8s:validateFalse="field Struct.SliceOfOpaqueStructField" // +k8s:eachVal=+k8s:validateFalse="field Struct.SliceOfOpaqueStructField vals" // +k8s:eachVal=+k8s:opaqueType SliceOfOpaqueStructField []OtherStruct `json:"sliceOfOpaqueStructField"` - // +k8s:validateFalse="field Struct.SliceOfOpaqueStructPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.SliceOfOpaqueStructPtrField vals" - // +k8s:eachVal=+k8s:opaqueType - SliceOfOpaqueStructPtrField []*OtherStruct `json:"sliceOfOpaqueStructPtrField"` - // +k8s:validateFalse="field Struct.ListMapOfStructField" // +k8s:eachVal=+k8s:validateFalse="field Struct.ListMapOfStructField vals" // +k8s:listType=map // +k8s:listMapKey=stringField ListMapOfStructField []OtherStruct `json:"listMapOfStructField"` - // +k8s:validateFalse="field Struct.ListMapOfStructPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListMapOfStructPtrField vals" - // +k8s:listType=map - // +k8s:listMapKey=stringField - ListMapOfStructPtrField []*OtherStruct `json:"listMapOfStructPtrField"` - // +k8s:validateFalse="field Struct.ListMapOfOpaqueStructField" // +k8s:eachVal=+k8s:validateFalse="field Struct.ListMapOfOpaqueStructField vals" // +k8s:listType=map @@ -82,36 +67,17 @@ type Struct struct { // +k8s:eachVal=+k8s:opaqueType ListMapOfOpaqueStructField []OtherStruct `json:"listMapOfOpaqueStructField"` - // +k8s:validateFalse="field Struct.ListMapOfOpaqueStructPtrField" - // +k8s:eachVal=+k8s:validateFalse="field Struct.ListMapOfOpaqueStructPtrField vals" - // +k8s:listType=map - // +k8s:listMapKey=stringField - // +k8s:eachVal=+k8s:opaqueType - ListMapOfOpaqueStructPtrField []*OtherStruct `json:"listMapOfOpaqueStructPtrField"` - // +k8s:validateFalse="field Struct.MapOfStringToStructField" // +k8s:eachKey=+k8s:validateFalse="field Struct.MapOfStringToStructField keys" // +k8s:eachVal=+k8s:validateFalse="field Struct.MapOfStringToStructField vals" MapOfStringToStructField map[OtherString]OtherStruct `json:"mapOfStringToStructField"` - // +k8s:validateFalse="field Struct.MapOfStringToStructPtrField" - // +k8s:eachKey=+k8s:validateFalse="field Struct.MapOfStringToStructPtrField keys" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapOfStringToStructPtrField vals" - MapOfStringToStructPtrField map[OtherString]*OtherStruct `json:"mapOfStringToStructPtrField"` - // +k8s:validateFalse="field Struct.MapOfStringToOpaqueStructField" // +k8s:eachKey=+k8s:validateFalse="field Struct.MapOfStringToOpaqueStructField keys" // +k8s:eachVal=+k8s:validateFalse="field Struct.MapOfStringToOpaqueStructField vals" // +k8s:eachKey=+k8s:opaqueType // +k8s:eachVal=+k8s:opaqueType MapOfStringToOpaqueStructField map[OtherString]OtherStruct `json:"mapOfStringToOpaqueStructField"` - - // +k8s:validateFalse="field Struct.MapOfStringToOpaqueStructPtrField" - // +k8s:eachKey=+k8s:validateFalse="field Struct.MapOfStringToOpaqueStructPtrField keys" - // +k8s:eachVal=+k8s:validateFalse="field Struct.MapOfStringToOpaqueStructPtrField vals" - // +k8s:eachKey=+k8s:opaqueType - // +k8s:eachVal=+k8s:opaqueType - MapOfStringToOpaqueStructPtrField map[OtherString]*OtherStruct `json:"mapOfStringToOpaqueStructPtrField"` } // +k8s:validateFalse="type OtherStruct" diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc_test.go index ffa1ce94429..77b58c347b6 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/doc_test.go @@ -24,59 +24,37 @@ func Test(t *testing.T) { st := localSchemeBuilder.Test(t) st.Value(&Struct{ - StructPtrField: &OtherStruct{}, - OpaqueStructPtrField: &OtherStruct{}, - SliceOfStructField: []OtherStruct{{}, {}}, - SliceOfStructPtrField: []*OtherStruct{{}, {}}, - SliceOfOpaqueStructField: []OtherStruct{{}, {}}, - SliceOfOpaqueStructPtrField: []*OtherStruct{{}, {}}, - ListMapOfStructField: []OtherStruct{{"foo"}, {"bar"}}, - ListMapOfStructPtrField: []*OtherStruct{{"foo"}, {"bar"}}, - ListMapOfOpaqueStructField: []OtherStruct{{"foo"}, {"bar"}}, - ListMapOfOpaqueStructPtrField: []*OtherStruct{{"foo"}, {"bar"}}, - MapOfStringToStructField: map[OtherString]OtherStruct{"a": {"foo"}, "b": {"bar"}}, - MapOfStringToStructPtrField: map[OtherString]*OtherStruct{"a": {"foo"}, "b": {"bar"}}, - MapOfStringToOpaqueStructField: map[OtherString]OtherStruct{"a": {"foo"}, "b": {"bar"}}, - MapOfStringToOpaqueStructPtrField: map[OtherString]*OtherStruct{"a": {"foo"}, "b": {"bar"}}, + StructPtrField: &OtherStruct{}, + OpaqueStructPtrField: &OtherStruct{}, + SliceOfStructField: []OtherStruct{{}, {}}, + SliceOfOpaqueStructField: []OtherStruct{{}, {}}, + ListMapOfStructField: []OtherStruct{{"foo"}, {"bar"}}, + ListMapOfOpaqueStructField: []OtherStruct{{"foo"}, {"bar"}}, + MapOfStringToStructField: map[OtherString]OtherStruct{"a": {"foo"}, "b": {"bar"}}, + MapOfStringToOpaqueStructField: map[OtherString]OtherStruct{"a": {"foo"}, "b": {"bar"}}, }).ExpectValidateFalseByPath(map[string][]string{ - "structField": {"field Struct.StructField", "type OtherStruct"}, - "structPtrField": {"field Struct.StructPtrField", "type OtherStruct"}, - "structField.stringField": {"field OtherStruct.StringField"}, - "structPtrField.stringField": {"field OtherStruct.StringField"}, - "opaqueStructField": {"field Struct.OpaqueStructField"}, - "opaqueStructPtrField": {"field Struct.OpaqueStructPtrField"}, - "sliceOfStructField": {"field Struct.SliceOfStructField"}, - "sliceOfStructField[0]": {"field Struct.SliceOfStructField vals", "type OtherStruct"}, - "sliceOfStructField[0].stringField": {"field OtherStruct.StringField"}, - "sliceOfStructField[1]": {"field Struct.SliceOfStructField vals", "type OtherStruct"}, - "sliceOfStructField[1].stringField": {"field OtherStruct.StringField"}, - "sliceOfStructPtrField": {"field Struct.SliceOfStructPtrField"}, - "sliceOfStructPtrField[0]": {"field Struct.SliceOfStructPtrField vals", "type OtherStruct"}, - "sliceOfStructPtrField[0].stringField": {"field OtherStruct.StringField"}, - "sliceOfStructPtrField[1]": {"field Struct.SliceOfStructPtrField vals", "type OtherStruct"}, - "sliceOfStructPtrField[1].stringField": {"field OtherStruct.StringField"}, - "sliceOfOpaqueStructField": {"field Struct.SliceOfOpaqueStructField"}, - "sliceOfOpaqueStructField[0]": {"field Struct.SliceOfOpaqueStructField vals"}, - "sliceOfOpaqueStructField[1]": {"field Struct.SliceOfOpaqueStructField vals"}, - "sliceOfOpaqueStructPtrField": {"field Struct.SliceOfOpaqueStructPtrField"}, - "sliceOfOpaqueStructPtrField[0]": {"field Struct.SliceOfOpaqueStructPtrField vals"}, - "sliceOfOpaqueStructPtrField[1]": {"field Struct.SliceOfOpaqueStructPtrField vals"}, - "listMapOfStructField": {"field Struct.ListMapOfStructField"}, - "listMapOfStructField[0]": {"field Struct.ListMapOfStructField vals", "type OtherStruct"}, - "listMapOfStructField[0].stringField": {"field OtherStruct.StringField"}, - "listMapOfStructField[1]": {"field Struct.ListMapOfStructField vals", "type OtherStruct"}, - "listMapOfStructField[1].stringField": {"field OtherStruct.StringField"}, - "listMapOfStructPtrField": {"field Struct.ListMapOfStructPtrField"}, - "listMapOfStructPtrField[0]": {"field Struct.ListMapOfStructPtrField vals", "type OtherStruct"}, - "listMapOfStructPtrField[0].stringField": {"field OtherStruct.StringField"}, - "listMapOfStructPtrField[1]": {"field Struct.ListMapOfStructPtrField vals", "type OtherStruct"}, - "listMapOfStructPtrField[1].stringField": {"field OtherStruct.StringField"}, - "listMapOfOpaqueStructField": {"field Struct.ListMapOfOpaqueStructField"}, - "listMapOfOpaqueStructField[0]": {"field Struct.ListMapOfOpaqueStructField vals"}, - "listMapOfOpaqueStructField[1]": {"field Struct.ListMapOfOpaqueStructField vals"}, - "listMapOfOpaqueStructPtrField": {"field Struct.ListMapOfOpaqueStructPtrField"}, - "listMapOfOpaqueStructPtrField[0]": {"field Struct.ListMapOfOpaqueStructPtrField vals"}, - "listMapOfOpaqueStructPtrField[1]": {"field Struct.ListMapOfOpaqueStructPtrField vals"}, + "structField": {"field Struct.StructField", "type OtherStruct"}, + "structPtrField": {"field Struct.StructPtrField", "type OtherStruct"}, + "structField.stringField": {"field OtherStruct.StringField"}, + "structPtrField.stringField": {"field OtherStruct.StringField"}, + "opaqueStructField": {"field Struct.OpaqueStructField"}, + "opaqueStructPtrField": {"field Struct.OpaqueStructPtrField"}, + "sliceOfStructField": {"field Struct.SliceOfStructField"}, + "sliceOfStructField[0]": {"field Struct.SliceOfStructField vals", "type OtherStruct"}, + "sliceOfStructField[0].stringField": {"field OtherStruct.StringField"}, + "sliceOfStructField[1]": {"field Struct.SliceOfStructField vals", "type OtherStruct"}, + "sliceOfStructField[1].stringField": {"field OtherStruct.StringField"}, + "sliceOfOpaqueStructField": {"field Struct.SliceOfOpaqueStructField"}, + "sliceOfOpaqueStructField[0]": {"field Struct.SliceOfOpaqueStructField vals"}, + "sliceOfOpaqueStructField[1]": {"field Struct.SliceOfOpaqueStructField vals"}, + "listMapOfStructField": {"field Struct.ListMapOfStructField"}, + "listMapOfStructField[0]": {"field Struct.ListMapOfStructField vals", "type OtherStruct"}, + "listMapOfStructField[0].stringField": {"field OtherStruct.StringField"}, + "listMapOfStructField[1]": {"field Struct.ListMapOfStructField vals", "type OtherStruct"}, + "listMapOfStructField[1].stringField": {"field OtherStruct.StringField"}, + "listMapOfOpaqueStructField": {"field Struct.ListMapOfOpaqueStructField"}, + "listMapOfOpaqueStructField[0]": {"field Struct.ListMapOfOpaqueStructField vals"}, + "listMapOfOpaqueStructField[1]": {"field Struct.ListMapOfOpaqueStructField vals"}, "mapOfStringToStructField": { "field Struct.MapOfStringToStructField", "field Struct.MapOfStringToStructField keys", @@ -88,17 +66,6 @@ func Test(t *testing.T) { "mapOfStringToStructField[a].stringField": {"field OtherStruct.StringField"}, "mapOfStringToStructField[b]": {"field Struct.MapOfStringToStructField vals", "type OtherStruct"}, "mapOfStringToStructField[b].stringField": {"field OtherStruct.StringField"}, - "mapOfStringToStructPtrField": { - "field Struct.MapOfStringToStructPtrField", - "field Struct.MapOfStringToStructPtrField keys", - "field Struct.MapOfStringToStructPtrField keys", - "type OtherString", - "type OtherString", - }, - "mapOfStringToStructPtrField[a]": {"field Struct.MapOfStringToStructPtrField vals", "type OtherStruct"}, - "mapOfStringToStructPtrField[a].stringField": {"field OtherStruct.StringField"}, - "mapOfStringToStructPtrField[b]": {"field Struct.MapOfStringToStructPtrField vals", "type OtherStruct"}, - "mapOfStringToStructPtrField[b].stringField": {"field OtherStruct.StringField"}, "mapOfStringToOpaqueStructField": { "field Struct.MapOfStringToOpaqueStructField", "field Struct.MapOfStringToOpaqueStructField keys", @@ -106,12 +73,5 @@ func Test(t *testing.T) { }, "mapOfStringToOpaqueStructField[a]": {"field Struct.MapOfStringToOpaqueStructField vals"}, "mapOfStringToOpaqueStructField[b]": {"field Struct.MapOfStringToOpaqueStructField vals"}, - "mapOfStringToOpaqueStructPtrField": { - "field Struct.MapOfStringToOpaqueStructPtrField", - "field Struct.MapOfStringToOpaqueStructPtrField keys", - "field Struct.MapOfStringToOpaqueStructPtrField keys", - }, - "mapOfStringToOpaqueStructPtrField[a]": {"field Struct.MapOfStringToOpaqueStructPtrField vals"}, - "mapOfStringToOpaqueStructPtrField[b]": {"field Struct.MapOfStringToOpaqueStructPtrField vals"}, }) } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/zz_generated.validations.go index b13b5c09d41..4ebfba36acc 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/opaque/zz_generated.validations.go @@ -143,17 +143,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("sliceOfStructField"), obj.SliceOfStructField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.SliceOfStructField }))...) - // field Struct.SliceOfStructPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.SliceOfStructPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.SliceOfStructPtrField vals") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, Validate_OtherStruct)...) - return - }(fldPath.Child("sliceOfStructPtrField"), obj.SliceOfStructPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.SliceOfStructPtrField }))...) - // field Struct.SliceOfOpaqueStructField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherStruct) (errs field.ErrorList) { @@ -164,16 +153,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("sliceOfOpaqueStructField"), obj.SliceOfOpaqueStructField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.SliceOfOpaqueStructField }))...) - // field Struct.SliceOfOpaqueStructPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.SliceOfOpaqueStructPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, nil, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.SliceOfOpaqueStructPtrField vals") - })...) - return - }(fldPath.Child("sliceOfOpaqueStructPtrField"), obj.SliceOfOpaqueStructPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.SliceOfOpaqueStructPtrField }))...) - // field Struct.ListMapOfStructField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherStruct) (errs field.ErrorList) { @@ -185,17 +164,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listMapOfStructField"), obj.ListMapOfStructField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.ListMapOfStructField }))...) - // field Struct.ListMapOfStructPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListMapOfStructPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, func(a *OtherStruct, b *OtherStruct) bool { return a.StringField == b.StringField }, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListMapOfStructPtrField vals") - })...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, func(a *OtherStruct, b *OtherStruct) bool { return a.StringField == b.StringField }, Validate_OtherStruct)...) - return - }(fldPath.Child("listMapOfStructPtrField"), obj.ListMapOfStructPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.ListMapOfStructPtrField }))...) - // field Struct.ListMapOfOpaqueStructField errs = append(errs, func(fldPath *field.Path, obj, oldObj []OtherStruct) (errs field.ErrorList) { @@ -206,16 +174,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("listMapOfOpaqueStructField"), obj.ListMapOfOpaqueStructField, safe.Field(oldObj, func(oldObj *Struct) []OtherStruct { return oldObj.ListMapOfOpaqueStructField }))...) - // field Struct.ListMapOfOpaqueStructPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj []*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListMapOfOpaqueStructPtrField")...) - errs = append(errs, validate.EachSliceValNilable(ctx, op, fldPath, obj, oldObj, func(a *OtherStruct, b *OtherStruct) bool { return a.StringField == b.StringField }, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.ListMapOfOpaqueStructPtrField vals") - })...) - return - }(fldPath.Child("listMapOfOpaqueStructPtrField"), obj.ListMapOfOpaqueStructPtrField, safe.Field(oldObj, func(oldObj *Struct) []*OtherStruct { return oldObj.ListMapOfOpaqueStructPtrField }))...) - // field Struct.MapOfStringToStructField errs = append(errs, func(fldPath *field.Path, obj, oldObj map[OtherString]OtherStruct) (errs field.ErrorList) { @@ -231,21 +189,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapOfStringToStructField"), obj.MapOfStringToStructField, safe.Field(oldObj, func(oldObj *Struct) map[OtherString]OtherStruct { return oldObj.MapOfStringToStructField }))...) - // field Struct.MapOfStringToStructPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[OtherString]*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.EachMapKey(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherString) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapOfStringToStructPtrField keys") - })...) - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapOfStringToStructPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapOfStringToStructPtrField vals") - })...) - errs = append(errs, validate.EachMapKey(ctx, op, fldPath, obj, oldObj, Validate_OtherString)...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, Validate_OtherStruct)...) - return - }(fldPath.Child("mapOfStringToStructPtrField"), obj.MapOfStringToStructPtrField, safe.Field(oldObj, func(oldObj *Struct) map[OtherString]*OtherStruct { return oldObj.MapOfStringToStructPtrField }))...) - // field Struct.MapOfStringToOpaqueStructField errs = append(errs, func(fldPath *field.Path, obj, oldObj map[OtherString]OtherStruct) (errs field.ErrorList) { @@ -259,19 +202,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("mapOfStringToOpaqueStructField"), obj.MapOfStringToOpaqueStructField, safe.Field(oldObj, func(oldObj *Struct) map[OtherString]OtherStruct { return oldObj.MapOfStringToOpaqueStructField }))...) - // field Struct.MapOfStringToOpaqueStructPtrField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj map[OtherString]*OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.EachMapKey(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherString) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapOfStringToOpaqueStructPtrField keys") - })...) - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapOfStringToOpaqueStructPtrField")...) - errs = append(errs, validate.EachMapValNilable(ctx, op, fldPath, obj, oldObj, func(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *OtherStruct) field.ErrorList { - return validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.MapOfStringToOpaqueStructPtrField vals") - })...) - return - }(fldPath.Child("mapOfStringToOpaqueStructPtrField"), obj.MapOfStringToOpaqueStructPtrField, safe.Field(oldObj, func(oldObj *Struct) map[OtherString]*OtherStruct { return oldObj.MapOfStringToOpaqueStructPtrField }))...) - return errs } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc.go index 677d6ea21f3..2071dd7a953 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc.go @@ -35,9 +35,7 @@ type Struct struct { // +k8s:validateFalse="field Struct.StringPtrField" StringPtrField *string `json:"stringPtrField"` - // +k8s:optional - // +k8s:validateFalse="field Struct.OtherStructField" - OtherStructField OtherStruct `json:"otherStructField"` + // non-pointer struct fields cannot be optional // +k8s:optional // +k8s:validateFalse="field Struct.OtherStructPtrField" diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc_test.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc_test.go index a7e1b181d7b..f6d296dd4f5 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc_test.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/doc_test.go @@ -27,21 +27,17 @@ func Test(t *testing.T) { st.Value(&Struct{ // All zero-values. - }).ExpectValidateFalseByPath(map[string][]string{ - "otherStructField": {"type OtherStruct", "field Struct.OtherStructField"}, // optional for structs is just documentation - }) + }).ExpectValid() st.Value(&Struct{ StringField: "abc", StringPtrField: ptr.To("xyz"), - OtherStructField: OtherStruct{}, OtherStructPtrField: &OtherStruct{}, SliceField: []string{"a", "b"}, MapField: map[string]string{"a": "b", "c": "d"}, }).ExpectValidateFalseByPath(map[string][]string{ "stringField": {"field Struct.StringField"}, "stringPtrField": {"field Struct.StringPtrField"}, - "otherStructField": {"type OtherStruct", "field Struct.OtherStructField"}, "otherStructPtrField": {"type OtherStruct", "field Struct.OtherStructPtrField"}, "sliceField": {"field Struct.SliceField"}, "mapField": {"field Struct.MapField"}, diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/zz_generated.validations.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/zz_generated.validations.go index e2454664c6b..4f0da3bcb47 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/zz_generated.validations.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/tags/optional/zz_generated.validations.go @@ -76,15 +76,6 @@ func Validate_Struct(ctx context.Context, op operation.Operation, fldPath *field return }(fldPath.Child("stringPtrField"), obj.StringPtrField, safe.Field(oldObj, func(oldObj *Struct) *string { return oldObj.StringPtrField }))...) - // field Struct.OtherStructField - errs = append(errs, - func(fldPath *field.Path, obj, oldObj *OtherStruct) (errs field.ErrorList) { - errs = append(errs, validate.FixedResult(ctx, op, fldPath, obj, oldObj, false, "field Struct.OtherStructField")...) - // optional non-pointer structs are purely documentation - errs = append(errs, Validate_OtherStruct(ctx, op, fldPath, obj, oldObj)...) - return - }(fldPath.Child("otherStructField"), &obj.OtherStructField, safe.Field(oldObj, func(oldObj *Struct) *OtherStruct { return &oldObj.OtherStructField }))...) - // field Struct.OtherStructPtrField errs = append(errs, func(fldPath *field.Path, obj, oldObj *OtherStruct) (errs field.ErrorList) { diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go index 3aeafa89991..54e5c6c9820 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go @@ -277,6 +277,14 @@ func (td *typeDiscoverer) DiscoverType(t *types.Type) error { return nil } +// unalias returns the unaliased type. +func unalias(t *types.Type) *types.Type { + for t.Kind == types.Alias { + t = t.Underlying + } + return t +} + // discover walks the given type recursively and returns a typeNode // representing it. This does not distinguish between discovering a type // definition and discovering a field of a struct. The first time it @@ -292,23 +300,60 @@ func (td *typeDiscoverer) discover(t *types.Type, fldPath *field.Path) (*typeNod } } - // Catch some edge cases that we don't want to handle. - if t.Kind == types.Alias && t.Underlying.Kind == types.Pointer { - return nil, fmt.Errorf("field %s (%s): typedefs to pointers are not supported", fldPath.String(), t) - } - if t.Kind == types.Pointer { - pointee := t.Elem - if pointee.Kind == types.Alias { - pointee = pointee.Underlying + // Catch some edge cases that we don't want to handle (yet?). This happens + // as early as possible to make all the other code simpler. + switch t.Kind { + case types.Builtin, types.Struct: + // Allowed + case types.Interface: + // We can't do much with interfaces, but they pop up in some places + // like RawExtension. + case types.Alias: + if t.Underlying.Kind == types.Pointer { + return nil, fmt.Errorf("field %s (%s): typedefs to pointers are not supported", fldPath.String(), t) } + case types.Pointer: + pointee := unalias(t.Elem) switch pointee.Kind { case types.Pointer: return nil, fmt.Errorf("field %s (%s): pointers to pointers are not supported", fldPath.String(), t) - case types.Slice: - return nil, fmt.Errorf("field %s (%s): pointers to slices are not supported", fldPath.String(), t) + case types.Slice, types.Array: + return nil, fmt.Errorf("field %s (%s): pointers to lists are not supported", fldPath.String(), t) case types.Map: return nil, fmt.Errorf("field %s (%s): pointers to maps are not supported", fldPath.String(), t) } + case types.Array: + return nil, fmt.Errorf("field %s (%s): fixed-size arrays are not supported", fldPath.String(), t) + case types.Slice: + elem := unalias(t.Elem) + switch elem.Kind { + case types.Pointer: + return nil, fmt.Errorf("field %s (%s): lists of pointers are not supported", fldPath.String(), t) + case types.Slice: + if unalias(elem.Elem) != types.Byte { + return nil, fmt.Errorf("field %s (%s): lists of lists are not supported", fldPath.String(), t) + } + case types.Map: + return nil, fmt.Errorf("field %s (%s): lists of maps are not supported", fldPath.String(), t) + } + case types.Map: + key := unalias(t.Key) + if key != types.String { + return nil, fmt.Errorf("field %s (%s): maps with non-string keys are not supported", fldPath.String(), t) + } + elem := unalias(t.Elem) + switch elem.Kind { + case types.Pointer: + return nil, fmt.Errorf("field %s (%s): maps of pointers are not supported", fldPath.String(), t) + case types.Slice: + if unalias(elem.Elem) != types.Byte { + return nil, fmt.Errorf("field %s (%s): maps of lists are not supported", fldPath.String(), t) + } + case types.Map: + return nil, fmt.Errorf("field %s (%s): maps of maps are not supported", fldPath.String(), t) + } + default: + return nil, fmt.Errorf("field %s (%v, kind %v) is not supported", fldPath.String(), t, t.Kind) } // Discovery applies to values, not pointers. @@ -376,7 +421,7 @@ func (td *typeDiscoverer) discover(t *types.Type, fldPath *field.Path) (*typeNod if err := td.discoverStruct(thisNode, fldPath); err != nil { return nil, err } - case types.Slice, types.Array: + case types.Slice: // Discover the element type. if node, err := td.discover(t.Elem, fldPath.Key("vals")); err != nil { return nil, err @@ -406,8 +451,6 @@ func (td *typeDiscoverer) discover(t *types.Type, fldPath *field.Path) (*typeNod node: node, } } - default: - return nil, fmt.Errorf("field %s (%v, kind %v) is not supported", fldPath.String(), t, t.Kind) } // Extract any type-attached validation rules. We do this AFTER descending @@ -446,7 +489,7 @@ func (td *typeDiscoverer) discover(t *types.Type, fldPath *field.Path) (*typeNod underlying := thisNode.underlying switch t.Underlying.Kind { - case types.Slice, types.Array: + case types.Slice: // Validate each value. if elemNode := underlying.node.elem.node; elemNode == nil { if !thisNode.typeValidations.OpaqueValType { @@ -630,7 +673,7 @@ func (td *typeDiscoverer) discoverStruct(thisNode *typeNode, fldPath *field.Path // We do this here, rather than in discover() because we need to know // information about the field, not just the type. switch childType.Kind { - case types.Slice, types.Array: + case types.Slice: // Validate each value of a list field. if elemNode := child.node.elem.node; elemNode == nil { if !child.fieldValidations.OpaqueValType { @@ -936,7 +979,7 @@ func (g *genValidations) emitValidationForChild(c *generator.Context, thisChild switch inType.Kind { case types.Builtin: // Nothing further. - case types.Slice, types.Array: + case types.Slice: // Nothing further case types.Map: // Nothing further @@ -1343,36 +1386,9 @@ func toGolangSourceDataLiteral(sw *generator.SnippetWriter, c *generator.Context } } -// findMemberByFieldName finds the member which matches the specified name. -// The name is expected to be the "JSON name", rather than the Go name. This -// function will descend into embedded types which would appear in JSON to be -// directly in the parent struct. If t is not a struct this does nothing. -// nolint:unused // FIXME: Remove once all validation-gen PRs are merged -func findMemberByFieldName(t *types.Type, name string) (types.Member, bool) { - for _, m := range t.Members { - if jsonTag, found := tags.LookupJSON(m); found { - // If there is a JSON tag of the exact name, use it. - if jsonTag.Name == name { - return m, true - } - // If there is a (non-standard) "inline" tag, look in the type. - if jsonTag.Inline { - return findMemberByFieldName(m.Type, name) - } - } - // If this field was embedded, look in that type. - if m.Embedded { - return findMemberByFieldName(m.Type, name) - } - } - return types.Member{}, false -} - // isNilableType returns true if the argument type can be compared to nil. func isNilableType(t *types.Type) bool { - for t.Kind == types.Alias { - t = t.Underlying - } + t = unalias(t) switch t.Kind { case types.Pointer, types.Map, types.Slice, types.Interface: // Note: Arrays are not nilable return true diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/each.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/each.go index 43aa2c227e1..50a8ae47d9a 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/each.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/each.go @@ -214,10 +214,8 @@ func (eachValTagValidator) ValidScopes() sets.Set[Scope] { func (eachValTagValidator) LateTagValidator() {} var ( - validateEachSliceVal = types.Name{Package: libValidationPkg, Name: "EachSliceVal"} - validateEachSliceValNilable = types.Name{Package: libValidationPkg, Name: "EachSliceValNilable"} - validateEachMapVal = types.Name{Package: libValidationPkg, Name: "EachMapVal"} - validateEachMapValNilable = types.Name{Package: libValidationPkg, Name: "EachMapValNilable"} + validateEachSliceVal = types.Name{Package: libValidationPkg, Name: "EachSliceVal"} + validateEachMapVal = types.Name{Package: libValidationPkg, Name: "EachMapVal"} ) func (evtv eachValTagValidator) GetValidations(context Context, _ []string, payload string) (Validations, error) { @@ -284,16 +282,6 @@ func (evtv eachValTagValidator) getListValidations(fldPath *field.Path, t *types listMap = lm } for _, vfn := range validations.Functions { - // Which function we call depends on whether the value-type is - // already nilable or not. - var validateEach types.Name - - if isNilableType(t.Elem) { - validateEach = validateEachSliceValNilable - } else { - validateEach = validateEachSliceVal - } - var cmpArg any = Literal("nil") if listMap != nil { cmpFn := FunctionLiteral{ @@ -311,7 +299,7 @@ func (evtv eachValTagValidator) getListValidations(fldPath *field.Path, t *types cmpFn.Body = buf.String() cmpArg = cmpFn } - f := Function(eachValTagName, vfn.Flags(), validateEach, cmpArg, WrapperFunction{vfn, t.Elem}) + f := Function(eachValTagName, vfn.Flags(), validateEachSliceVal, cmpArg, WrapperFunction{vfn, t.Elem}) result.Functions = append(result.Functions, f) } @@ -323,17 +311,7 @@ func (evtv eachValTagValidator) getMapValidations(t *types.Type, validations Val result.OpaqueValType = validations.OpaqueType for _, vfn := range validations.Functions { - // Which function we call depends on whether the value-type is - // already nilable or not. - var validateEach types.Name - - if isNilableType(t.Elem) { - validateEach = validateEachMapValNilable - } else { - validateEach = validateEachMapVal - } - - f := Function(eachValTagName, vfn.Flags(), validateEach, WrapperFunction{vfn, t.Elem}) + f := Function(eachValTagName, vfn.Flags(), validateEachMapVal, WrapperFunction{vfn, t.Elem}) result.Functions = append(result.Functions, f) } diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/required.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/required.go index 7b3d42e30ad..866960c0901 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/required.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/validators/required.go @@ -97,10 +97,12 @@ func (requirednessTagValidator) doRequired(context Context) (Validations, error) case types.Pointer: return Validations{Functions: []FunctionGen{Function(requiredTagName, ShortCircuit, requiredPointerValidator)}}, nil case types.Struct: - // The +required tag on a non-pointer struct is only for documentation. - // We don't perform validation here and defer the validation to - // the struct's fields. - return Validations{Comments: []string{"required non-pointer structs are purely documentation"}}, nil + // The +k8s:required tag on a non-pointer struct is not supported. + // If you encounter this error and believe you have a valid use case + // for forbiddening a non-pointer struct, please let us know! We need + // to understand your scenario to determine if we need to adjust + // this behavior or provide alternative validation mechanisms. + return Validations{}, fmt.Errorf("non-pointer structs cannot use the %q tag", requiredTagName) } return Validations{Functions: []FunctionGen{Function(requiredTagName, ShortCircuit, requiredValueValidator)}}, nil } @@ -125,11 +127,12 @@ func (requirednessTagValidator) doOptional(context Context) (Validations, error) case types.Pointer: return Validations{Functions: []FunctionGen{Function(optionalTagName, ShortCircuit|NonError, optionalPointerValidator)}}, nil case types.Struct: - // Specifying that a non-pointer struct is optional doesn't actually - // make sense technically almost ever, and is better described as a - // union inside the struct. It does, however, make sense as - // documentation. - return Validations{Comments: []string{"optional non-pointer structs are purely documentation"}}, nil + // The +k8s:optional tag on a non-pointer struct is not supported. + // If you encounter this error and believe you have a valid use case + // for forbiddening a non-pointer struct, please let us know! We need + // to understand your scenario to determine if we need to adjust + // this behavior or provide alternative validation mechanisms. + return Validations{}, fmt.Errorf("non-pointer structs cannot use the %q tag", optionalTagName) } return Validations{Functions: []FunctionGen{Function(optionalTagName, ShortCircuit|NonError, optionalValueValidator)}}, nil } @@ -174,7 +177,7 @@ func (requirednessTagValidator) doForbidden(context Context) (Validations, error }, }, nil case types.Struct: - // The +forbidden tag on a non-pointer struct is not supported. + // The +k8s:forbidden tag on a non-pointer struct is not supported. // If you encounter this error and believe you have a valid use case // for forbiddening a non-pointer struct, please let us know! We need // to understand your scenario to determine if we need to adjust