api_dump_full: use api_clone_schema() for 'returns' schema

This  convert indexed parameters like -net\d+ to -net[n], so resulting dump
is smaller.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer 2018-09-13 12:53:36 +02:00 committed by Thomas Lamprecht
parent 8b49281929
commit d01452bdce

View File

@ -45,7 +45,7 @@ our $standard_output_options = {
}; };
sub api_clone_schema { sub api_clone_schema {
my ($schema) = @_; my ($schema, $no_typetext) = @_;
my $res = {}; my $res = {};
my $ref = ref($schema); my $ref = ref($schema);
@ -71,7 +71,7 @@ sub api_clone_schema {
my $tmp = ref($pd) ? clone($pd) : $pd; my $tmp = ref($pd) ? clone($pd) : $pd;
# NOTE: add typetext property for more complex types, to # NOTE: add typetext property for more complex types, to
# make the web api viewer code simpler # make the web api viewer code simpler
if (!(defined($tmp->{enum}) || defined($tmp->{pattern}))) { if (!$no_typetext && !(defined($tmp->{enum}) || defined($tmp->{pattern}))) {
my $typetext = PVE::JSONSchema::schema_get_type_text($tmp); my $typetext = PVE::JSONSchema::schema_get_type_text($tmp);
if ($tmp->{type} && ($tmp->{type} ne $typetext)) { if ($tmp->{type} && ($tmp->{type} ne $typetext)) {
$tmp->{typetext} = $typetext; $tmp->{typetext} = $typetext;
@ -143,6 +143,8 @@ sub api_dump_full {
} else { } else {
if ($k eq 'parameters') { if ($k eq 'parameters') {
$data->{$k} = api_clone_schema($d); $data->{$k} = api_clone_schema($d);
} elsif ($k eq 'returns') {
$data->{$k} = api_clone_schema($d, 1);
} else { } else {
$data->{$k} = ref($d) ? clone($d) : $d; $data->{$k} = ref($d) ? clone($d) : $d;
} }