]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/JSONSchema.pm
schema: disable additional properties in property strings
[pve-common.git] / src / PVE / JSONSchema.pm
index de2a0bd993957343e4366a2e41fc5be485b98dab..95529258f19c24535e09dae21dc54471da8b1d37 100644 (file)
@@ -488,7 +488,10 @@ sub format_size {
 };
 
 sub parse_property_string {
-    my ($format, $data, $path) = @_;
+    my ($format, $data, $path, $additional_properties) = @_;
+
+    # In property strings we default to not allowing additional properties
+    $additional_properties = 0 if !defined($additional_properties);
 
     my $default_key;
 
@@ -528,7 +531,7 @@ sub parse_property_string {
     }
 
     my $errors = {};
-    check_object($path, $format, $res, undef, $errors);
+    check_object($path, $format, $res, $additional_properties, $errors);
     if (scalar(%$errors)) {
        raise "format error\n", errors => $errors;
     }
@@ -582,12 +585,13 @@ sub print_property_string {
     }
 
     foreach my $key (sort keys %$data) {
-       die "invalid key: $key" if !$allowed{$key};
        delete $required{$key};
        next if $skipped{$key};
+       die "invalid key: $key" if !$allowed{$key};
 
        my $typeformat = $format->{$key}->{format};
        my $value = $data->{$key};
+       next if !defined($value);
        $text .= $comma;
        $comma = ',';
        if ($typeformat && $typeformat eq 'disk-size') {