apiextensions: fix array-without-items structural error

This commit is contained in:
Dr. Stefan Schimanski 2019-05-30 15:52:48 +02:00
parent b3981a2f9a
commit 1cd0d9037e
2 changed files with 44 additions and 0 deletions

View File

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

View File

@ -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 {