]> git.proxmox.com Git - pve-common.git/commitdiff
schema_get_type_text: do not always expand enums
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 5 Nov 2016 15:44:59 +0000 (16:44 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 5 Nov 2016 15:44:59 +0000 (16:44 +0100)
We try to keep the text short by default.

src/PVE/JSONSchema.pm
src/PVE/RESTHandler.pm

index fe6614ac57b86cae287c5757c169e01558fd73a6..37a6e1fa673451e171844f172894715075faf660 100644 (file)
@@ -1485,7 +1485,7 @@ my $find_schema_default_key = sub {
 };
 
 sub generate_typetext {
-    my ($format) = @_;
+    my ($format, $list_enums) = @_;
 
     my ($default_key, $keyAliasProps) = &$find_schema_default_key($format);
 
@@ -1518,7 +1518,11 @@ sub generate_typetext {
        } elsif (my $text = $phash->{typetext}) {
            $typetext .= $text;
        } elsif (my $enum = $phash->{enum}) {
-           $typetext .= '<' . join('|', @$enum) . '>';
+           if ($list_enums || (scalar(@$enum) <= 3)) {
+               $typetext .= '<' . join('|', @$enum) . '>';
+           } else {
+               $typetext .= '<enum>';
+           }
        } elsif ($phash->{type} eq 'boolean') {
            $typetext .= '<1|0>';
        } elsif ($phash->{type} eq 'integer') {
@@ -1674,7 +1678,7 @@ sub print_property_string {
 }
 
 sub schema_get_type_text {
-    my ($phash) = @_;
+    my ($phash, $style) = @_;
 
     my $type = $phash->{type} || 'string';
 
@@ -1700,7 +1704,9 @@ sub schema_get_type_text {
        if (my $format = $phash->{format}) {
            $format = get_format($format) if ref($format) ne 'HASH';
            if (ref($format) eq 'HASH') {
-               return generate_typetext($format);
+               my $list_enums = 0;
+               $list_enums = 1 if $style && $style eq 'config-sub';
+               return generate_typetext($format, $list_enums);
            }
        }
     }
index 4b67c614f336c1fc52c1a70d0234847163aa6b95..6fc69ad3c3af59567ee8959f5040e2d93e795c04 100644 (file)
@@ -417,7 +417,7 @@ sub handle {
 # $display_name: for example "-$name" of "<$name>", pass undef to use "$name:"
 # $phash: json schema property hash
 # $format: 'asciidoc', 'short', 'long' or 'full'
-# $style: 'config', 'arg' or 'fixed'
+# $style: 'config', 'config-sub', 'arg' or 'fixed'
 my $get_property_description = sub {
     my ($name, $style, $phash, $format, $hidepw, $fileparams) = @_;
 
@@ -434,7 +434,7 @@ my $get_property_description = sub {
 
     chomp $descr;
 
-    my $type = PVE::JSONSchema::schema_get_type_text($phash);
+    my $type = PVE::JSONSchema::schema_get_type_text($phash, $style);
 
     if ($hidepw && $name eq 'password') {
        $type = '';
@@ -458,7 +458,7 @@ my $get_property_description = sub {
        } elsif ($style eq 'arg') {
            $res .= "`-$name` ";
        } elsif ($style eq 'fixed') {
-           $res .= "`<$name>` ";
+           $res .= "`<$name>`: ";
        } else {
            die "unknown style '$style'";
        }