mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 18:58:18 +00:00
Prevent usage patterns we don't want to support
* typedefs to pointers * pointers to pointers * pointers to lists * pointers to maps * fixed-size arrays * lists of pointers * lists of lists * lists of maps * maps with non-string keys * maps of pointers * maps of lists * maps of maps
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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[*]"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
@@ -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[*]"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
@@ -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[*]"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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")...)
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
@@ -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[*][*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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[*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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[*]"},
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
@@ -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[*][*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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[*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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[*]"},
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
@@ -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[*][*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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[*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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[*]"},
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
@@ -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[*][*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
@@ -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[*]"},
|
||||
})
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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[*]"},
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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"},
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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[*]"},
|
||||
})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user