mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
apiextension: fix go-openapi validation error path at the root
This commit is contained in:
parent
b91640816d
commit
f140ceb1e5
@ -58,10 +58,14 @@ func ValidateCustomResource(fldPath *field.Path, customResource interface{}, val
|
|||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
|
|
||||||
case *openapierrors.Validation:
|
case *openapierrors.Validation:
|
||||||
switch err.Code() {
|
errPath := fldPath
|
||||||
|
if len(err.Name) > 0 && err.Name != "." {
|
||||||
|
errPath = errPath.Child(strings.TrimPrefix(err.Name, "."))
|
||||||
|
}
|
||||||
|
|
||||||
|
switch err.Code() {
|
||||||
case openapierrors.RequiredFailCode:
|
case openapierrors.RequiredFailCode:
|
||||||
allErrs = append(allErrs, field.Required(fldPath.Child(strings.TrimPrefix(err.Name, ".")), ""))
|
allErrs = append(allErrs, field.Required(errPath, ""))
|
||||||
|
|
||||||
case openapierrors.EnumFailCode:
|
case openapierrors.EnumFailCode:
|
||||||
values := []string{}
|
values := []string{}
|
||||||
@ -73,14 +77,14 @@ func ValidateCustomResource(fldPath *field.Path, customResource interface{}, val
|
|||||||
values = append(values, string(allowedJSON))
|
values = append(values, string(allowedJSON))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allErrs = append(allErrs, field.NotSupported(fldPath.Child(strings.TrimPrefix(err.Name, ".")), err.Value, values))
|
allErrs = append(allErrs, field.NotSupported(errPath, err.Value, values))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
value := interface{}("")
|
value := interface{}("")
|
||||||
if err.Value != nil {
|
if err.Value != nil {
|
||||||
value = err.Value
|
value = err.Value
|
||||||
}
|
}
|
||||||
allErrs = append(allErrs, field.Invalid(fldPath.Child(strings.TrimPrefix(err.Name, ".")), value, err.Error()))
|
allErrs = append(allErrs, field.Invalid(errPath, value, err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user