We want to use this with the extractapi.pl helper (pve-docs, pve-api-client).
Signed-off-by: Dietmar Maurer <diet...@proxmox.com> --- src/PVE/RESTHandler.pm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/PVE/RESTHandler.pm b/src/PVE/RESTHandler.pm index 3f5c732..5c64a20 100644 --- a/src/PVE/RESTHandler.pm +++ b/src/PVE/RESTHandler.pm @@ -139,6 +139,39 @@ sub api_dump_cleanup_tree { } +# api_dump_remove_refs: prepare API tree for use with to_json($tree) +sub api_dump_remove_refs { + my ($tree) = @_; + + my $class = ref($tree); + return $tree if !$class; + + if ($class eq 'ARRAY') { + my $res = []; + foreach my $el (@$tree) { + push @$res, api_dump_remove_refs($el); + } + return $res; + } elsif ($class eq 'HASH') { + my $res = {}; + foreach my $k (keys %$tree) { + if (my $class = ref($tree->{$k})) { + if ($class eq 'CODE') { + next if $k eq 'completion'; + } + $res->{$k} = api_dump_remove_refs($tree->{$k}); + } else { + $res->{$k} = $tree->{$k}; + } + } + return $res; + } elsif ($class eq 'Regexp') { + return "$tree"; # return string representation + } else { + die "unknown class '$class'\n"; + } +} + sub api_dump { my ($class, $prefix) = @_; -- 2.11.0 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel