[pve-devel] [RFC pve-common 3/4] JSONSchema::check_object_warn

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Sep 21 12:11:07 CEST 2015


A version of check_object that warns and returns true or
false.
---
 src/PVE/JSONSchema.pm | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 650bf18..216e414 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -563,6 +563,19 @@ sub check_object {
     }
 }
 
+sub check_object_warn {
+    my ($path, $schema, $value, $additional_properties) = @_;
+    my $errors = {};
+    check_object($path, $schema, $value, $additional_properties, $errors);
+    if (scalar(%$errors)) {
+	foreach my $k (keys %$errors) {
+	    warn "parse error: $k: $errors->{$k}\n";
+	}
+	return 0;
+    }
+    return 1;
+}
+
 sub check_prop {
     my ($value, $schema, $path, $errors) = @_;
 
-- 
2.1.4





More information about the pve-devel mailing list