mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-09 05:15:49 +00:00
schema_get_type_text: do not always expand enums
We try to keep the text short by default.
This commit is contained in:
parent
25d9bda941
commit
abc1afd874
@ -1485,7 +1485,7 @@ my $find_schema_default_key = sub {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sub generate_typetext {
|
sub generate_typetext {
|
||||||
my ($format) = @_;
|
my ($format, $list_enums) = @_;
|
||||||
|
|
||||||
my ($default_key, $keyAliasProps) = &$find_schema_default_key($format);
|
my ($default_key, $keyAliasProps) = &$find_schema_default_key($format);
|
||||||
|
|
||||||
@ -1518,7 +1518,11 @@ sub generate_typetext {
|
|||||||
} elsif (my $text = $phash->{typetext}) {
|
} elsif (my $text = $phash->{typetext}) {
|
||||||
$typetext .= $text;
|
$typetext .= $text;
|
||||||
} elsif (my $enum = $phash->{enum}) {
|
} elsif (my $enum = $phash->{enum}) {
|
||||||
|
if ($list_enums || (scalar(@$enum) <= 3)) {
|
||||||
$typetext .= '<' . join('|', @$enum) . '>';
|
$typetext .= '<' . join('|', @$enum) . '>';
|
||||||
|
} else {
|
||||||
|
$typetext .= '<enum>';
|
||||||
|
}
|
||||||
} elsif ($phash->{type} eq 'boolean') {
|
} elsif ($phash->{type} eq 'boolean') {
|
||||||
$typetext .= '<1|0>';
|
$typetext .= '<1|0>';
|
||||||
} elsif ($phash->{type} eq 'integer') {
|
} elsif ($phash->{type} eq 'integer') {
|
||||||
@ -1674,7 +1678,7 @@ sub print_property_string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub schema_get_type_text {
|
sub schema_get_type_text {
|
||||||
my ($phash) = @_;
|
my ($phash, $style) = @_;
|
||||||
|
|
||||||
my $type = $phash->{type} || 'string';
|
my $type = $phash->{type} || 'string';
|
||||||
|
|
||||||
@ -1700,7 +1704,9 @@ sub schema_get_type_text {
|
|||||||
if (my $format = $phash->{format}) {
|
if (my $format = $phash->{format}) {
|
||||||
$format = get_format($format) if ref($format) ne 'HASH';
|
$format = get_format($format) if ref($format) ne 'HASH';
|
||||||
if (ref($format) eq '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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ sub handle {
|
|||||||
# $display_name: for example "-$name" of "<$name>", pass undef to use "$name:"
|
# $display_name: for example "-$name" of "<$name>", pass undef to use "$name:"
|
||||||
# $phash: json schema property hash
|
# $phash: json schema property hash
|
||||||
# $format: 'asciidoc', 'short', 'long' or 'full'
|
# $format: 'asciidoc', 'short', 'long' or 'full'
|
||||||
# $style: 'config', 'arg' or 'fixed'
|
# $style: 'config', 'config-sub', 'arg' or 'fixed'
|
||||||
my $get_property_description = sub {
|
my $get_property_description = sub {
|
||||||
my ($name, $style, $phash, $format, $hidepw, $fileparams) = @_;
|
my ($name, $style, $phash, $format, $hidepw, $fileparams) = @_;
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ my $get_property_description = sub {
|
|||||||
|
|
||||||
chomp $descr;
|
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') {
|
if ($hidepw && $name eq 'password') {
|
||||||
$type = '';
|
$type = '';
|
||||||
@ -458,7 +458,7 @@ my $get_property_description = sub {
|
|||||||
} elsif ($style eq 'arg') {
|
} elsif ($style eq 'arg') {
|
||||||
$res .= "`-$name` ";
|
$res .= "`-$name` ";
|
||||||
} elsif ($style eq 'fixed') {
|
} elsif ($style eq 'fixed') {
|
||||||
$res .= "`<$name>` ";
|
$res .= "`<$name>`: ";
|
||||||
} else {
|
} else {
|
||||||
die "unknown style '$style'";
|
die "unknown style '$style'";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user