Reenable guard to only validat root and scale subresources until ratcheting merges.

This commit is contained in:
Joe Betz
2025-05-05 21:59:36 -04:00
parent 2e6ec2414c
commit d78b295a84

View File

@@ -832,17 +832,25 @@ func (g *genValidations) emitRegisterFunction(c *generator.Context, schemeRegist
targs["typePfx"] = "*"
}
// TODO: Remove special-casing for `/` and `/scale` resources once ratcheting is introduced.
// This uses a typed nil pointer, rather than a real instance because
// we need the type information, but not an instance of the type.
sw.Do("scheme.AddValidationFunc(", targs)
sw.Do(" ($.typePfx$$.rootType|raw$)(nil), ", targs)
sw.Do(" func(ctx $.context.Context$, op $.operation.Operation|raw$, obj, oldObj interface{}) $.field.ErrorList|raw$ {\n", targs)
sw.Do(" if len(op.Request.Subresources) == 0 {\n", targs)
sw.Do(" return $.rootType|objectvalidationfn$(", targs)
sw.Do(" ctx, ", targs)
sw.Do(" op, ", targs)
sw.Do(" nil /* fldPath */, ", targs)
sw.Do(" obj.($.typePfx$$.rootType|raw$), ", targs)
sw.Do(" $.safe.Cast|raw$[$.typePfx$$.rootType|raw$](oldObj))\n", targs)
sw.Do(" }\n", targs)
sw.Do(" return $.field.ErrorList|raw${", targs)
sw.Do(" $.field.InternalError|raw$(", targs)
sw.Do(" nil, ", targs)
sw.Do(" $.fmt.Errorf|raw$(\"no validation found for %T, subresources: %v\", obj, op.Request.Subresources))", targs)
sw.Do(" }\n", targs)
sw.Do("})\n", targs)
}
sw.Do("return nil\n", nil)