]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/JSONSchema.pm
generate_typetext: better handling of only-optional cases
[pve-common.git] / src / PVE / JSONSchema.pm
index e94b5fc4ccb66089e4b35168e0f771cfebe5e8d7..45ce5ba58c3ad5720bdf727d4615ac2d4b8e34d7 100644 (file)
@@ -1294,7 +1294,8 @@ sub generate_typetext {
     my $typetext = '';
     my (@optional, @required);
     foreach my $key (sort keys %$schema) {
-       next if !$schema->{$key}->{format_description};
+       next if !$schema->{$key}->{format_description} &&
+               !$schema->{$key}->{typetext};
        if ($schema->{$key}->{optional}) {
            push @optional, $key;
        } else {
@@ -1302,17 +1303,25 @@ sub generate_typetext {
        }
     }
     my ($pre, $post) = ('', '');
+    my $add = sub {
+       my ($key) = @_;
+       if (my $desc = $schema->{$key}->{format_description}) {
+           $typetext .= "$pre$key=<$desc>$post";
+       } elsif (my $text = $schema->{$key}->{typetext}) {
+           $typetext .= "$pre$text$post";
+       } else {
+           die "internal error: neither format_description nor typetext found";
+       }
+    };
     foreach my $key (@required) {
-       my $desc = $schema->{$key}->{format_description};
-       $typetext .= "$pre$key=<$desc>$post";
+       &$add($key);
        $pre = ', ';
     }
-    $pre = ' [,' if $pre;
+    $pre = $pre ? ' [,' : '[';
+    $post = ']';
     foreach my $key (@optional) {
-       my $desc = $schema->{$key}->{format_description};
-       $typetext .= "$pre$key=<$desc>$post";
+       &$add($key);
        $pre = ' [,';
-       $post = ']';
     }
     return $typetext;
 }