[pve-devel] [PATCH pve-common 1/6] JSONSchema::generate_typetext: raw typetext support
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Sep 22 13:45:39 CEST 2015
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 | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index e94b5fc..f36ee42 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -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,15 +1303,23 @@ 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;
foreach my $key (@optional) {
- my $desc = $schema->{$key}->{format_description};
- $typetext .= "$pre$key=<$desc>$post";
+ &$add($key);
$pre = ' [,';
$post = ']';
}
--
2.1.4
More information about the pve-devel
mailing list