mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
apiextensions: fix array-without-items structural error
This commit is contained in:
parent
b3981a2f9a
commit
1cd0d9037e
@ -81,7 +81,11 @@ func validateStructuralInvariants(s *Structural, lvl level, fldPath *field.Path)
|
||||
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
if s.Type == "array" && s.Items == nil {
|
||||
allErrs = append(allErrs, field.Required(fldPath.Child("items"), "must be specified"))
|
||||
}
|
||||
allErrs = append(allErrs, validateStructuralInvariants(s.Items, itemLevel, fldPath.Child("items"))...)
|
||||
|
||||
for k, v := range s.Properties {
|
||||
allErrs = append(allErrs, validateStructuralInvariants(&v, fieldLevel, fldPath.Child("properties").Key(k))...)
|
||||
}
|
||||
|
@ -1318,6 +1318,46 @@ not:
|
||||
"spec.validation.openAPIV3Schema.not.properties[metadata]: Forbidden: must not be specified in a nested context",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "missing items for array",
|
||||
globalSchema: `
|
||||
type: object
|
||||
properties:
|
||||
slice:
|
||||
type: array
|
||||
`,
|
||||
expectedViolations: []string{
|
||||
"spec.validation.openAPIV3Schema.properties[slice].items: Required value: must be specified",
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "items slice",
|
||||
globalSchema: `
|
||||
type: object
|
||||
properties:
|
||||
slice:
|
||||
type: array
|
||||
items:
|
||||
- type: string
|
||||
- type: integer
|
||||
`,
|
||||
expectedCreateError: true,
|
||||
},
|
||||
{
|
||||
desc: "items slice in value validation",
|
||||
globalSchema: `
|
||||
type: object
|
||||
properties:
|
||||
slice:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
not:
|
||||
items:
|
||||
- type: string
|
||||
`,
|
||||
expectedCreateError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for i := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user