]> git.proxmox.com Git - pve-common.git/commitdiff
JSONSchema::generate_typetext: raw typetext support
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 22 Sep 2015 11:45:39 +0000 (13:45 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 23 Sep 2015 05:59:46 +0000 (07:59 +0200)
Instead of a format_description which ends up in the
documentation as 'key=<$desc>', a typetext can now be used
for an as-is string. (Eg. for when the key isn't required,
like for volumes in mountpoints, typetext can be set to
[volume=]volume)

src/PVE/JSONSchema.pm

index e94b5fc4ccb66089e4b35168e0f771cfebe5e8d7..f36ee427f66f8a4dc1509b5a621395965158e5f8 100644 (file)
@@ -1294,7 +1294,8 @@ sub generate_typetext {
     my $typetext = '';
     my (@optional, @required);
     foreach my $key (sort keys %$schema) {
     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 {
        if ($schema->{$key}->{optional}) {
            push @optional, $key;
        } else {
@@ -1302,15 +1303,23 @@ sub generate_typetext {
        }
     }
     my ($pre, $post) = ('', '');
        }
     }
     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) {
     foreach my $key (@required) {
-       my $desc = $schema->{$key}->{format_description};
-       $typetext .= "$pre$key=<$desc>$post";
+       &$add($key);
        $pre = ', ';
     }
     $pre = ' [,' if $pre;
     foreach my $key (@optional) {
        $pre = ', ';
     }
     $pre = ' [,' if $pre;
     foreach my $key (@optional) {
-       my $desc = $schema->{$key}->{format_description};
-       $typetext .= "$pre$key=<$desc>$post";
+       &$add($key);
        $pre = ' [,';
        $post = ']';
     }
        $pre = ' [,';
        $post = ']';
     }