mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-26 03:10:02 +00:00
JSONSchema: format_description + generate_typetext
Helper to generate schema-based typetext properties for comma separated list configuration strings (like -net0 and -ip) using a 'format_description' schema property.
This commit is contained in:
parent
395c18045f
commit
d5d10f8580
@ -797,6 +797,11 @@ my $default_schema_noref = {
|
|||||||
optional => 1,
|
optional => 1,
|
||||||
description => "This provides a description of the purpose the instance property. The value can be a string or it can be an object with properties corresponding to various different instance languages (with an optional default property indicating the default description).",
|
description => "This provides a description of the purpose the instance property. The value can be a string or it can be an object with properties corresponding to various different instance languages (with an optional default property indicating the default description).",
|
||||||
},
|
},
|
||||||
|
format_description => {
|
||||||
|
type => "string",
|
||||||
|
optional => 1,
|
||||||
|
description => "This provides a shorter (usually just one word) description for a property used to generate descriptions for comma separated list property strings.",
|
||||||
|
},
|
||||||
title => {
|
title => {
|
||||||
type => "string",
|
type => "string",
|
||||||
optional => 1,
|
optional => 1,
|
||||||
@ -1227,4 +1232,32 @@ sub dump_config {
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub generate_typetext {
|
||||||
|
my ($schema) = @_;
|
||||||
|
my $typetext = '';
|
||||||
|
my (@optional, @required);
|
||||||
|
foreach my $key (sort keys %$schema) {
|
||||||
|
next if !$schema->{$key}->{format_description};
|
||||||
|
if ($schema->{$key}->{optional}) {
|
||||||
|
push @optional, $key;
|
||||||
|
} else {
|
||||||
|
push @required, $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my ($pre, $post) = ('', '');
|
||||||
|
foreach my $key (@required) {
|
||||||
|
my $desc = $schema->{$key}->{format_description};
|
||||||
|
$typetext .= "$pre$key=<$desc>$post";
|
||||||
|
$pre = ', ';
|
||||||
|
}
|
||||||
|
$pre = ' [,' if $pre;
|
||||||
|
foreach my $key (@optional) {
|
||||||
|
my $desc = $schema->{$key}->{format_description};
|
||||||
|
$typetext .= "$pre$key=<$desc>$post";
|
||||||
|
$pre = ' [,';
|
||||||
|
$post = ']';
|
||||||
|
}
|
||||||
|
return $typetext;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user