From 13b954201b374f97b3859f20d87e88d815eb1ada Mon Sep 17 00:00:00 2001 From: Harikrishna Date: Tue, 5 Jul 2022 22:50:59 +0530 Subject: [PATCH 1/2] fix: required enum value validation --- server/validator/validator.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/validator/validator.go b/server/validator/validator.go index b6c4749d..de2cdd34 100644 --- a/server/validator/validator.go +++ b/server/validator/validator.go @@ -28,8 +28,8 @@ func checkIfFieldRequired(f protoreflect.FieldDescriptor) bool { return false } -func checkValueExists(kind protoreflect.Kind, v protoreflect.Value) bool { - switch kind { +func checkValueExists(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { + switch fd.Kind() { case protoreflect.BytesKind: d := v.Bytes() return len(d) > 0 @@ -38,8 +38,8 @@ func checkValueExists(kind protoreflect.Kind, v protoreflect.Value) bool { return len(d) > 0 case protoreflect.EnumKind: d := v.Enum() - // This relies on the convention that, in enum definition 0 value is UNSPECIFIED - return d != 0 + ed := fd.Enum().Values().ByNumber(d) + return ed != nil default: return true } @@ -65,7 +65,7 @@ func validateMessage(m protoreflect.ProtoMessage) []string { prefixedFields := addPrefix(fd.JSONName(), nestedFields) missingFields = append(missingFields, prefixedFields...) } - if checkIfFieldRequired(fd) && !checkValueExists(fd.Kind(), v) { + if checkIfFieldRequired(fd) && !checkValueExists(fd, v) { missingFields = append(missingFields, fd.JSONName()) } } From 3d48f00539e21f140e0b06b54754546946440f4c Mon Sep 17 00:00:00 2001 From: Harikrishna Date: Fri, 8 Jul 2022 12:31:24 +0530 Subject: [PATCH 2/2] fix: namespace update for compatibility field --- server/api/namespace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/api/namespace.go b/server/api/namespace.go index 3eaa797b..b7a000f7 100644 --- a/server/api/namespace.go +++ b/server/api/namespace.go @@ -36,7 +36,7 @@ func (a *API) CreateNamespace(ctx context.Context, in *stencilv1beta1.CreateName } func (a *API) UpdateNamespace(ctx context.Context, in *stencilv1beta1.UpdateNamespaceRequest) (*stencilv1beta1.UpdateNamespaceResponse, error) { - ns, err := a.namespace.Update(ctx, domain.Namespace{ID: in.GetId(), Format: in.GetFormat().String(), Description: in.GetDescription()}) + ns, err := a.namespace.Update(ctx, domain.Namespace{ID: in.GetId(), Format: in.GetFormat().String(), Compatibility: in.GetCompatibility().String(), Description: in.GetDescription()}) return &stencilv1beta1.UpdateNamespaceResponse{Namespace: namespaceToProto(ns)}, err }