]> git.proxmox.com Git - pve-docs.git/blobdiff - extractapi.pl
add api doc viewer (moved from package pve2-api-doc)
[pve-docs.git] / extractapi.pl
diff --git a/extractapi.pl b/extractapi.pl
new file mode 100755 (executable)
index 0000000..0488ea9
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/perl -w
+
+use strict;
+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'));
+
+print "var pveapi = " . to_json($tree, {pretty => 1}) . ";\n\n";
+
+exit(0);