]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/RESTHandler.pm
fix doc generator (do not convert efidisk0 to efidisk[N])
[pve-common.git] / src / PVE / RESTHandler.pm
index 0b8b81c6d740854c72e5b42fc2709de513b786d3..5e46dc3fb85097bb5c24193055a2aecf6aedf219 100644 (file)
@@ -34,13 +34,22 @@ sub api_clone_schema {
            my $pd = $d->{$p};
            if ($p =~ m/^([a-z]+)(\d+)$/) {
                my ($name, $idx) = ($1, $2);
-               if ($idx == 0) {
+               if ($idx == 0 && defined($d->{"${name}1"})) {
                    $p = "${name}[n]";
                } elsif (defined($d->{"${name}0"})) {
                    next; # only handle once for -xx0, but only if -xx0 exists
                }
            }
-           $res->{$k}->{$p} = ref($pd) ? clone($pd) : $pd;
+           my $tmp = ref($pd) ? clone($pd) : $pd;
+           # NOTE: add typetext property for more complex types, to
+           # make the web api viewer code simpler
+           if (!(defined($tmp->{enum}) || defined($tmp->{pattern}))) {
+               my $typetext = PVE::JSONSchema::schema_get_type_text($tmp);
+               if ($tmp->{type} && ($tmp->{type} ne $typetext)) {
+                   $tmp->{typetext} = $typetext;
+               }
+           }
+           $res->{$k}->{$p} = $tmp;
        }
     }
 
@@ -582,7 +591,7 @@ sub usage_str {
        if ($k =~ m/^([a-z]+)(\d+)$/) {
            my ($name, $idx) = ($1, $2);
            next if $idx_param->{$name};
-           if ($idx == 0) {
+           if ($idx == 0 && defined($prop->{"${name}1"})) {
                $idx_param->{$name} = 1;
                $base = "${name}[n]";
            }
@@ -647,7 +656,7 @@ sub dump_properties {
        if ($k =~ m/^([a-z]+)(\d+)$/) {
            my ($name, $idx) = ($1, $2);
            next if $idx_param->{$name};
-           if ($idx == 0) {
+           if ($idx == 0 && defined($prop->{"${name}1"})) {
                $idx_param->{$name} = 1;
                $base = "${name}[n]";
            }