]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/PodParser.pm
schema_get_type_text: return format_description if available
[pve-common.git] / src / PVE / PodParser.pm
index 8ad05980f71ea63f1a28ca99b703db63d45028c6..4f2868a0f6f3e427cae85bf0a93696298deb4c4b 100644 (file)
@@ -49,8 +49,12 @@ 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} &&
-               !$schema->{$key}->{typetext};
+       my $entry = $schema->{$key};
+       next if $entry->{alias};
+       next if !$entry->{format_description} &&
+               !$entry->{typetext} &&
+               !$entry->{enum} &&
+               $entry->{type} ne 'boolean';
        if ($schema->{$key}->{optional}) {
            push @optional, $key;
        } else {
        if ($schema->{$key}->{optional}) {
            push @optional, $key;
        } else {
@@ -66,11 +70,17 @@ sub generate_typetext {
            $key = $alias;
            $entry = $schema->{$key};
        }
            $key = $alias;
            $entry = $schema->{$key};
        }
-       if (my $desc = $entry->{format_description}) {
+       if (!defined($entry->{typetext})) {
            $typetext .= $entry->{default_key} ? "[$key=]" : "$key=";
            $typetext .= $entry->{default_key} ? "[$key=]" : "$key=";
+       }
+       if (my $desc = $entry->{format_description}) {
            $typetext .= "<$desc>";
        } elsif (my $text = $entry->{typetext}) {
            $typetext .= $text;
            $typetext .= "<$desc>";
        } elsif (my $text = $entry->{typetext}) {
            $typetext .= $text;
+       } elsif (my $enum = $entry->{enum}) {
+           $typetext .= '<' . join('|', @$enum) . '>';
+       } elsif ($entry->{type} eq 'boolean') {
+           $typetext .= '<1|0>';
        } else {
            die "internal error: neither format_description nor typetext found";
        }
        } else {
            die "internal error: neither format_description nor typetext found";
        }
@@ -94,6 +104,8 @@ sub schema_get_type_text {
 
     if ($phash->{typetext}) {
        return $phash->{typetext};
 
     if ($phash->{typetext}) {
        return $phash->{typetext};
+    } elsif ($phash->{format_description}) {
+       return "<$phash->{format_description}>";
     } elsif ($phash->{enum}) {
        return "(" . join(' | ', sort @{$phash->{enum}}) . ")";
     } elsif ($phash->{pattern}) {
     } elsif ($phash->{enum}) {
        return "(" . join(' | ', sort @{$phash->{enum}}) . ")";
     } elsif ($phash->{pattern}) {
@@ -125,6 +137,7 @@ sub generate_property_text {
     my $data = '';
     foreach my $key (sort keys %$schema) {
        my $d = $schema->{$key};
     my $data = '';
     foreach my $key (sort keys %$schema) {
        my $d = $schema->{$key};
+       next if $d->{alias};
        my $desc = $d->{description};
        my $typetext = schema_get_type_text($d);
        $desc = 'No description available' if !$desc;
        my $desc = $d->{description};
        my $typetext = schema_get_type_text($d);
        $desc = 'No description available' if !$desc;
@@ -133,7 +146,7 @@ sub generate_property_text {
     return $data;
 }
 
     return $data;
 }
 
-# generta epop from JSON schema properties
+# generate pod from JSON schema properties
 sub dump_properties {
     my ($properties) = @_;
 
 sub dump_properties {
     my ($properties) = @_;