From 04222b448b9b154d8bc16e7334ef981adbe3db1f Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 18 May 2018 10:56:13 +0200 Subject: [PATCH] use new helper PVE::RESTHandler::api_dump_remove_refs() --- extractapi.pl | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/extractapi.pl b/extractapi.pl index afd2cf1..06d6af4 100755 --- a/extractapi.pl +++ b/extractapi.pl @@ -1,43 +1,14 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use strict; +use warnings; + use PVE::RESTHandler; use PVE::API2; use JSON; -sub cleanup_tree { - my ($h) = @_; - - my $class = ref($h); - return $h if !$class; - - if ($class eq 'ARRAY') { - my $res = []; - foreach my $el (@$h) { - push @$res, cleanup_tree($el); - } - return $res; - } elsif ($class eq 'HASH') { - my $res = {}; - foreach my $k (keys %$h) { - if (my $class = ref($h->{$k})) { - if ($class eq 'CODE') { - next if $k eq 'completion'; - } - $res->{$k} = cleanup_tree($h->{$k}); - } else { - $res->{$k} = $h->{$k}; - } - } - return $res; - } elsif ($class eq 'Regexp') { - return "$h"; # return string representation - } else { - die "unknown class '$class'\n"; - } -} -my $tree = cleanup_tree(PVE::RESTHandler::api_dump('PVE::API2')); +my $tree = PVE::RESTHandler::api_dump_remove_refs(PVE::RESTHandler::api_dump('PVE::API2')); print "var pveapi = " . to_json($tree, {pretty => 1, canonical => 1}) . ";\n\n"; -- 2.39.2