Merge pull request #78521 from sttts/sttts-crd-structural-array-items

apiextensions: fix array-without-items structural error
This commit is contained in:
Kubernetes Prow Robot 2019-06-01 08:00:57 -07:00 committed by GitHub
commit b874a0ce9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -83,7 +83,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))...)
}

View File

@ -1331,6 +1331,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 {