5
0
mirror of git://git.proxmox.com/git/pve-docs.git synced 2025-01-10 01:17:51 +03:00
pve-docs/extractapi.pl
Dietmar Maurer 4466070224 update auto-generate docs
Which are now sorted, so that we can detect changes easily.
2016-04-30 12:03:57 +02:00

45 lines
864 B
Perl
Executable File

#!/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, canonical => 1}) . ";\n\n";
exit(0);