fix(validation-gen): correct typos in comments and documentation

This commit is contained in:
yongruilin
2025-07-21 21:24:45 +00:00
parent 63a958ff34
commit 8b558a1bc3
8 changed files with 11 additions and 11 deletions

View File

@@ -146,7 +146,7 @@ func Unique[T any](_ context.Context, _ operation.Operation, fldPath *field.Path
// the key(s). Unfortunately, the way errors are rendered, it comes out
// as something like "map[string]any{...}" which is not very nice. Once
// that is fixed, we can consider adding a way for this function to
// specify that just the keys should be renderted in the error.
// specify that just the keys should be rendered in the error.
errs = append(errs, field.Duplicate(fldPath.Index(i), val))
}
return errs

View File

@@ -83,7 +83,7 @@ func ForbiddenSlice[T any](_ context.Context, _ operation.Operation, fldPath *fi
return field.ErrorList{field.Forbidden(fldPath, "")}
}
// RequiredMap verifies that the specified map is empty.
// ForbiddenMap verifies that the specified map is empty.
func ForbiddenMap[K comparable, T any](_ context.Context, _ operation.Operation, fldPath *field.Path, value, _ map[K]T) field.ErrorList {
if len(value) == 0 {
return nil

View File

@@ -77,8 +77,8 @@ func Union[T any](_ context.Context, op operation.Operation, fldPath *field.Path
//
// For example:
//
// var UnionMembershipForABC := validate.NewDiscriminatedUnionMembership("type", [2]string{"a", "A"}, [2]string{"b" "B"}, [2]string{"c", "C"})
// func ValidateABC(ctx context.Context, op operation.Operation, fldPath, *field.Path, in *ABC) (errs fields.ErrorList) {
// var UnionMembershipForABC = validate.NewDiscriminatedUnionMembership("type", [2]string{"a", "A"}, [2]string{"b", "B"}, [2]string{"c", "C"})
// func ValidateABC(ctx context.Context, op operation.Operation, fldPath *field.Path, in *ABC) (errs field.ErrorList) {
// errs = append(errs, DiscriminatedUnion(ctx, op, fldPath, in, oldIn, UnionMembershipForABC,
// func(in *ABC) string { return string(in.Type) },
// func(in *ABC) bool { return in.A != nil },

View File

@@ -31,8 +31,8 @@ import (
//
// For example:
//
// var ZeroOrOneOfMembershipFor := validate.NewUnionMembership([2]string{"a", "A"}, [2]string{"b", "B"}, [2]string{"c", "C"})
// func ValidateABC(ctx context.Context, op operation.Operation, fldPath *field.Path, in *ABC) (errs fields.ErrorList) {
// var ZeroOrOneOfMembershipForABC = validate.NewUnionMembership([2]string{"a", "A"}, [2]string{"b", "B"}, [2]string{"c", "C"})
// func ValidateABC(ctx context.Context, op operation.Operation, fldPath *field.Path, in *ABC) (errs field.ErrorList) {
// errs = append(errs, ZeroOrOneOfUnion(ctx, op, fldPath, in, oldIn, UnionMembershipForABC,
// func(in *ABC) bool { return in.A != nil },
// func(in *ABC) bool { return in.B != ""},

View File

@@ -71,7 +71,7 @@ type genValidations struct {
schemeRegistry types.Name
}
// NewGenValidations cretes a new generator for the specified package.
// NewGenValidations creates a new generator for the specified package.
func NewGenValidations(outputFilename, outputPackage string, rootTypes []*types.Type, discovered *typeDiscoverer, inputToPkg map[string]string, schemeRegistry types.Name) generator.Generator {
return &genValidations{
GoGenerator: generator.GoGenerator{
@@ -1126,7 +1126,7 @@ func (g *genValidations) emitCallToOtherTypeFunc(c *generator.Context, node *typ
sw.Do("errs = append(errs, $.funcName|raw$(ctx, op, fldPath, obj, oldObj)...)\n", targs)
}
// emitRachetingCheck emits a equivalence check for default ratcheting.
// emitRatchetingCheck emits an equivalence check for default ratcheting.
func emitRatchetingCheck(c *generator.Context, t *types.Type, sw *generator.SnippetWriter) {
// Emit equivalence check for default ratcheting.
targs := generator.Args{

View File

@@ -69,7 +69,7 @@ func (etv *enumTagValidator) GetValidations(context Context, _ codetags.Tag) (Va
var result Validations
if enum, ok := etv.enumContext.EnumType(context.Type); ok {
// TODO: Avoid the "local" here. This was added to to avoid errors caused when the package is an empty string.
// TODO: Avoid the "local" here. This was added to avoid errors caused when the package is an empty string.
// The correct package would be the output package but is not known here. This does not show up in generated code.
// TODO: Append a consistent hash suffix to avoid generated name conflicts?
supportVarName := PrivateVar{Name: "SymbolsFor" + context.Type.Name.Name, Package: "local"}

View File

@@ -32,7 +32,7 @@ const (
requiredTagName = "k8s:required"
optionalTagName = "k8s:optional"
forbiddenTagName = "k8s:forbidden"
defaultTagName = "default" // TODO: this should evenually be +k8s:default
defaultTagName = "default" // TODO: this should eventually be +k8s:default
)
func init() {

View File

@@ -250,7 +250,7 @@ func processUnionValidations(context Context, unions unions, varPrefix string,
return Validations{}, fmt.Errorf("slice type cannot have field members")
}
// TODO: Avoid the "local" here. This was added to to avoid errors caused when the package is an empty string.
// TODO: Avoid the "local" here. This was added to avoid errors caused when the package is an empty string.
// The correct package would be the output package but is not known here. This does not show up in generated code.
// TODO: Append a consistent hash suffix to avoid generated name conflicts?
varBaseName := sanitizeName(context.Path.String() + "_" + unionName) // unionName can be ""