forked from pplu/aws-sdk-perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_classes.pl
executable file
·67 lines (51 loc) · 1.6 KB
/
gen_classes.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Printer;
use Data::Dumper;
use JSON::MaybeXS;
use File::Slurper 'read_binary';
use Module::Runtime qw/require_module/;
use lib 'builder-lib', 't/lib';
use Paws::API::Builder::Paws;
use Paws::API::ServiceToClass;
my (@files) = @ARGV;
# If no files specified, get the last version of each json for each service
if (not @files) {
my @dirs = glob('botocore/botocore/data/*');
foreach my $class_dir (@dirs) {
my @class_defs = grep { -f $_ } glob("$class_dir/*/service-2.json");
next if (not @class_defs);
@class_defs = sort @class_defs;
my $class_version = pop @class_defs;
push @files, $class_version;
}
}
my $p = Paws::API::Builder::Paws->new;
$p->process;
my @failures;
foreach my $file (@files) {
print "Processing $file\n";
if (my ($f, $version) = ($file =~ m/data\/(.*?)\/(.*?)\/service-2.json/)){
next if ($f eq '_retry' or $f eq '_regions');
my $ns = Paws::API::ServiceToClass::service_to_class($f);
eval {
process_api("Paws::$ns", $file);
};
if ($@) { warn $@; push @failures, "$file $@\n" }
}
}
print "Summary of fails\n";
print @failures;
sub process_api {
my ($api, $file) = @_;
my $struct = decode_json(read_binary($file));
my $type = $struct->{metadata}->{protocol} or die "Type of API call not found";
my $overrides = { 'Paws::EC2' => 'EC2' };
$type = $overrides->{ $api } if (defined $overrides->{ $api });
$type =~ s/\-//;
my $class_maker = "Paws::API::Builder::${type}";
require_module $class_maker;
my $c = $class_maker->new(api_file => $file, api => $api);
$c->process_api;
}