From 95ff86e7d2093def2c50dcb0d7641e756a94d310 Mon Sep 17 00:00:00 2001 From: Ruben Hakopian Date: Wed, 5 Jun 2024 23:57:01 -0700 Subject: [PATCH] Fixed #20 Kubevious removes required fields containing empty strings #20 --- src/validation/k8s-manifest-validator.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/validation/k8s-manifest-validator.ts b/src/validation/k8s-manifest-validator.ts index 660c09b..b84a888 100644 --- a/src/validation/k8s-manifest-validator.ts +++ b/src/validation/k8s-manifest-validator.ts @@ -200,14 +200,19 @@ export class K8sManifestValidator const propNode = (node as any)[propName]; if (_.isString(propNode) && (propNode.length === 0)) { - if (_.isNullOrUndefined(propSchema.default)) - { - delete (node as any)[propName]; - } - else + if (!_.isNullOrUndefined(propSchema.default)) { (node as any)[propName] = propSchema.default; + } + + // Before we used to delete the node. This behavior causes + // a false possitive when an empty required string fails validation. + // https://github.com/kubevious/cli/issues/20 + // In future should try to set the value of undefined values as default value + // of the schema. That would also help with guard functionality with validation + // that depends on default values. + // Old Code: delete (node as any)[propName]; } } }