]>
Commit | Line | Data |
---|---|---|
410dc2c9 DM |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use JSON; | |
6 | ||
7 | use PVE::RESTHandler; | |
8 | ||
9 | use PMG::API2; | |
10 | ||
11 | sub cleanup_tree { | |
12 | my ($h) = @_; | |
13 | ||
14 | my $class = ref($h); | |
15 | return $h if !$class; | |
16 | ||
17 | if ($class eq 'ARRAY') { | |
18 | my $res = []; | |
19 | foreach my $el (@$h) { | |
20 | push @$res, cleanup_tree($el); | |
21 | } | |
22 | return $res; | |
23 | } elsif ($class eq 'HASH') { | |
24 | my $res = {}; | |
25 | foreach my $k (keys %$h) { | |
26 | if (my $class = ref($h->{$k})) { | |
27 | if ($class eq 'CODE') { | |
28 | next if $k eq 'completion'; | |
29 | } | |
30 | $res->{$k} = cleanup_tree($h->{$k}); | |
31 | } else { | |
32 | $res->{$k} = $h->{$k}; | |
33 | } | |
34 | } | |
35 | return $res; | |
36 | } elsif ($class eq 'Regexp') { | |
37 | return "$h"; # return string representation | |
38 | } else { | |
39 | die "unknown class '$class'\n"; | |
40 | } | |
41 | } | |
42 | ||
43 | my $tree = cleanup_tree(PVE::RESTHandler::api_dump('PMG::API2')); | |
44 | ||
4413eb71 | 45 | print "var apiSchema = " . to_json($tree, {pretty => 1, canonical => 1}) . ";\n\n"; |
410dc2c9 DM |
46 | |
47 | exit(0); |