api_dump: add $raw_dump options

Allow to return the original tree with all refs. We use this
with our new pveclient which needs the full api definition.
Keeping refs makes it possible to store the tree more efficiently.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dietmar Maurer 2018-06-11 11:23:19 +02:00 committed by Thomas Lamprecht
parent 5082a17b81
commit 1e5ecf7bf8

View File

@ -58,7 +58,7 @@ sub api_clone_schema {
} }
sub api_dump_full { sub api_dump_full {
my ($tree, $index, $class, $prefix) = @_; my ($tree, $index, $class, $prefix, $raw_dump) = @_;
$prefix = '' if !$prefix; $prefix = '' if !$prefix;
@ -70,7 +70,7 @@ sub api_dump_full {
$path =~ s/\/+$//; $path =~ s/\/+$//;
if ($info->{subclass}) { if ($info->{subclass}) {
api_dump_full($tree, $index, $info->{subclass}, $path); api_dump_full($tree, $index, $info->{subclass}, $path, $raw_dump);
} else { } else {
next if !$path; next if !$path;
@ -111,11 +111,14 @@ sub api_dump_full {
my $d = $info->{$k}; my $d = $info->{$k};
if ($k eq 'parameters') { if ($raw_dump) {
$data->{$k} = api_clone_schema($d); $data->{$k} = $d;
} else { } else {
if ($k eq 'parameters') {
$data->{$k} = ref($d) ? clone($d) : $d; $data->{$k} = api_clone_schema($d);
} else {
$data->{$k} = ref($d) ? clone($d) : $d;
}
} }
} }
$res->{info}->{$info->{method}} = $data; $res->{info}->{$info->{method}} = $data;
@ -173,12 +176,12 @@ sub api_dump_remove_refs {
} }
sub api_dump { sub api_dump {
my ($class, $prefix) = @_; my ($class, $prefix, $raw_dump) = @_;
my $tree = []; my $tree = [];
my $index = {}; my $index = {};
api_dump_full($tree, $index, $class); api_dump_full($tree, $index, $class, $prefix, $raw_dump);
api_dump_cleanup_tree($tree); api_dump_cleanup_tree($tree);
return $tree; return $tree;
}; };