[pve-devel] [RFC pve-common 2/4] JSONSchema::generate_typetext: raw typetext support

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Sep 21 12:11:06 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 8725949..650bf18 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1237,7 +1237,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 {
@@ -1245,15 +1246,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