X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2FPVE%2FJSONSchema.pm;h=de2a0bd993957343e4366a2e41fc5be485b98dab;hb=0526cc2d7902555e08b5aea830141e349b27062e;hp=09ed6b1be5b2abb9e031daa22fbb9fcb1e957e9e;hpb=5f3f697dcd95c7b6399188e9c9dea6d3cc1394dd;p=pve-common.git diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 09ed6b1..de2a0bd 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -248,7 +248,7 @@ register_format('CIDRv4', \&pve_verify_cidrv4); sub pve_verify_cidrv4 { my ($cidr, $noerr) = @_; - if ($cidr =~ m!^(?:$IPV4RE)(?:/(\d+))$! && ($1 > 7) && ($1 < 32)) { + if ($cidr =~ m!^(?:$IPV4RE)(?:/(\d+))$! && ($1 > 7) && ($1 <= 32)) { return $cidr; } @@ -500,6 +500,10 @@ sub parse_property_string { my ($k, $v) = ($1, $2); die "duplicate key in comma-separated list property: $k\n" if defined($res->{$k}); my $schema = $format->{$k}; + if (my $alias = $schema->{alias}) { + $k = $alias; + $schema = $format->{$k}; + } die "invalid key in comma-separated list property: $k\n" if !$schema; if ($schema->{type} && $schema->{type} eq 'boolean') { $v = 1 if $v =~ m/^(1|on|yes|true)$/i; @@ -553,7 +557,7 @@ sub print_property_string { my %required; # this is a set, all present keys are required regardless of value foreach my $key (keys %$format) { $allowed{$key} = 1; - if (!$format->{$key}->{optional} && !$skipped{$key}) { + if (!$format->{$key}->{optional} && !$format->{$key}->{alias} && !$skipped{$key}) { $required{$key} = 1; } @@ -810,7 +814,7 @@ sub check_prop { if (!defined ($value)) { return if $schema->{type} && $schema->{type} eq 'null'; - if (!$schema->{optional}) { + if (!$schema->{optional} && !$schema->{alias}) { add_error($errors, $path, "property is missing and it is not optional"); } return; @@ -1048,6 +1052,11 @@ my $default_schema_noref = { optional => 1, description => "Whether this is the default key in a comma separated list property string.", }, + alias => { + type => 'string', + optional => 1, + description => "When a key represents the same property as another it can be an alias to it, causing the parsed datastructure to use the other key to store the current value under.", + }, default => { type => "any", optional => 1,