You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/analysis/optionalfields/testdata/src/a/a.go
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,20 @@ type A struct {
98
98
// PointerMapAlias is a pointer map alias field.
99
99
// +optional
100
100
PointerMapAlias*MapAlias`json:"pointerMapAlias,omitempty"`// want "field PointerMapAlias is optional but the underlying type does not need to be a pointer. The pointer should be removed."
101
+
102
+
// StringAliasWithEnum is a string alias field with enum validation.
103
+
// With the "Always" pointer preference, optional fields should be pointers regardless of zero value validity.
104
+
// +optional
105
+
StringAliasWithEnumStringAliasWithEnum`json:"stringAliasWithEnum,omitempty"`// want "field StringAliasWithEnum is optional and should be a pointer"
106
+
107
+
// StringAliasWithEnumPointer is a pointer string alias field with enum validation.
108
+
// This is correctly a pointer since the zero value is not valid.
// StringAliasWithEnumNoOmitEmpty is a string alias field with enum validation and no omitempty.
113
+
// +optional
114
+
StringAliasWithEnumNoOmitEmpty*StringAliasWithEnum`json:"stringAliasWithEnumNoOmitEmpty"`// want "field StringAliasWithEnumNoOmitEmpty is optional and should have the omitempty tag"
101
115
}
102
116
103
117
typeBstruct {
@@ -129,3 +143,8 @@ type BoolAlias bool
129
143
typeSliceAlias []string
130
144
131
145
typeMapAliasmap[string]string
146
+
147
+
// StringAliasWithEnum is a string alias with enum validation.
148
+
// The zero value ("") is not in the enum, making it invalid.
Copy file name to clipboardExpand all lines: pkg/analysis/optionalfields/testdata/src/a/a.go.golden
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -98,6 +98,20 @@ type A struct {
98
98
// PointerMapAlias is a pointer map alias field.
99
99
// +optional
100
100
PointerMapAlias MapAlias `json:"pointerMapAlias,omitempty"` // want "field PointerMapAlias is optional but the underlying type does not need to be a pointer. The pointer should be removed."
101
+
102
+
// StringAliasWithEnum is a string alias field with enum validation.
103
+
// With the "Always" pointer preference, optional fields should be pointers regardless of zero value validity.
104
+
// +optional
105
+
StringAliasWithEnum *StringAliasWithEnum `json:"stringAliasWithEnum,omitempty"` // want "field StringAliasWithEnum is optional and should be a pointer"
106
+
107
+
// StringAliasWithEnumPointer is a pointer string alias field with enum validation.
108
+
// This is correctly a pointer since the zero value is not valid.
// StringAliasWithEnumNoOmitEmpty is a string alias field with enum validation and no omitempty.
113
+
// +optional
114
+
StringAliasWithEnumNoOmitEmpty *StringAliasWithEnum `json:"stringAliasWithEnumNoOmitEmpty,omitempty"` // want "field StringAliasWithEnumNoOmitEmpty is optional and should have the omitempty tag"
101
115
}
102
116
103
117
type B struct {
@@ -129,3 +143,8 @@ type BoolAlias bool
129
143
type SliceAlias []string
130
144
131
145
type MapAlias map[string]string
146
+
147
+
// StringAliasWithEnum is a string alias with enum validation.
148
+
// The zero value ("") is not in the enum, making it invalid.
// StringAliasWithEnumPointer is a pointer string alias field with enum validation.
280
+
// This should NOT be a pointer since the zero value is not valid.
281
+
// +optional
282
+
StringAliasWithEnumPointer*StringAliasWithEnum`json:"stringAliasWithEnumPointer,omitempty"`// want "field StringAliasWithEnumPointer is optional and does not allow the zero value. The field does not need to be a pointer."
283
+
284
+
// StringAliasWithEnumNoOmitEmpty is a string alias field with enum validation and no omitempty.
285
+
// +optional
286
+
StringAliasWithEnumNoOmitEmptyStringAliasWithEnum`json:"stringAliasWithEnumNoOmitEmpty"`// want "field StringAliasWithEnumNoOmitEmpty is optional and should have the omitempty tag"
287
+
288
+
// StringAliasWithEnumEmptyValue is a string alias field with enum validation and empty value.
// StringAliasWithEnumPointer is a pointer string alias field with enum validation.
280
+
// This should NOT be a pointer since the zero value is not valid.
281
+
// +optional
282
+
StringAliasWithEnumPointer StringAliasWithEnum `json:"stringAliasWithEnumPointer,omitempty"` // want "field StringAliasWithEnumPointer is optional and does not allow the zero value. The field does not need to be a pointer."
283
+
284
+
// StringAliasWithEnumNoOmitEmpty is a string alias field with enum validation and no omitempty.
285
+
// +optional
286
+
StringAliasWithEnumNoOmitEmpty StringAliasWithEnum `json:"stringAliasWithEnumNoOmitEmpty,omitempty"` // want "field StringAliasWithEnumNoOmitEmpty is optional and should have the omitempty tag"
287
+
288
+
// StringAliasWithEnumEmptyValue is a string alias field with enum validation and empty value.
Copy file name to clipboardExpand all lines: pkg/analysis/optionalfields/testdata/src/c/a.go
+27Lines changed: 27 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -421,6 +421,24 @@ type A struct {
421
421
// PointerPointerString is a double pointer string field.
422
422
// +optional
423
423
DoublePointerString**string`json:"doublePointerString,omitempty"`// want "field DoublePointerString is optional but the underlying type does not need to be a pointer. The pointer should be removed."
424
+
425
+
// StringAliasWithEnum is a string alias field with enum validation.
426
+
// The zero value ("") is not in the enum, so this should NOT be a pointer.
// StringAliasWithEnumPointer is a pointer string alias field with enum validation.
431
+
// This should NOT be a pointer since the zero value is not valid.
432
+
// +optional
433
+
StringAliasWithEnumPointer*StringAliasWithEnum`json:"stringAliasWithEnumPointer,omitempty"`// want "field StringAliasWithEnumPointer is optional and does not allow the zero value. The field does not need to be a pointer."
434
+
435
+
// StringAliasWithEnumNoOmitEmpty is a string alias field with enum validation and no omitempty.
436
+
// +optional
437
+
StringAliasWithEnumNoOmitEmptyStringAliasWithEnum`json:"stringAliasWithEnumNoOmitEmpty"`// want "field StringAliasWithEnumNoOmitEmpty is optional and does not allow the zero value. It must have the omitempty tag."
438
+
439
+
// StringAliasWithEnumEmptyValue is a string alias field with enum validation and empty value.
EnumWithoutOmitEmptystring`json:"enumWithoutOmitEmpty"`// want "field EnumWithoutOmitEmpty is optional and does not allow the zero value. It must have the omitempty tag."
528
546
}
547
+
548
+
// StringAliasWithEnum is a string alias with enum validation.
549
+
// The zero value ("") is not in the enum, making it invalid.
550
+
// +kubebuilder:validation:Enum=value1;value2
551
+
typeStringAliasWithEnumstring
552
+
553
+
// StringAliasWithEnumEmptyValue is a string alias with enum validation and empty value.
Copy file name to clipboardExpand all lines: pkg/analysis/optionalfields/testdata/src/c/a.go.golden
+27Lines changed: 27 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -421,6 +421,24 @@ type A struct {
421
421
// PointerPointerString is a double pointer string field.
422
422
// +optional
423
423
DoublePointerString *string `json:"doublePointerString,omitempty"` // want "field DoublePointerString is optional but the underlying type does not need to be a pointer. The pointer should be removed."
424
+
425
+
// StringAliasWithEnum is a string alias field with enum validation.
426
+
// The zero value ("") is not in the enum, so this should NOT be a pointer.
// StringAliasWithEnumPointer is a pointer string alias field with enum validation.
431
+
// This should NOT be a pointer since the zero value is not valid.
432
+
// +optional
433
+
StringAliasWithEnumPointer StringAliasWithEnum `json:"stringAliasWithEnumPointer,omitempty"` // want "field StringAliasWithEnumPointer is optional and does not allow the zero value. The field does not need to be a pointer."
434
+
435
+
// StringAliasWithEnumNoOmitEmpty is a string alias field with enum validation and no omitempty.
436
+
// +optional
437
+
StringAliasWithEnumNoOmitEmpty StringAliasWithEnum `json:"stringAliasWithEnumNoOmitEmpty,omitempty"` // want "field StringAliasWithEnumNoOmitEmpty is optional and does not allow the zero value. It must have the omitempty tag."
438
+
439
+
// StringAliasWithEnumEmptyValue is a string alias field with enum validation and empty value.
EnumWithoutOmitEmpty string `json:"enumWithoutOmitEmpty,omitempty"` // want "field EnumWithoutOmitEmpty is optional and does not allow the zero value. It must have the omitempty tag."
528
546
}
547
+
548
+
// StringAliasWithEnum is a string alias with enum validation.
549
+
// The zero value ("") is not in the enum, making it invalid.
550
+
// +kubebuilder:validation:Enum=value1;value2
551
+
type StringAliasWithEnum string
552
+
553
+
// StringAliasWithEnumEmptyValue is a string alias with enum validation and empty value.
0 commit comments