|
Line 0
Link Here
|
| 0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
|
| 3 |
use List::MoreUtils qw( uniq duplicates ); |
| 4 |
use YAML; |
| 5 |
use File::Slurp qw( write_file ); |
| 6 |
|
| 7 |
my @files = qx{ls api/v1/**/**/*.yaml}; |
| 8 |
for my $file ( @files ) { |
| 9 |
chomp $file; |
| 10 |
say "Processing $file"; |
| 11 |
my $hash = YAML::LoadFile($file); |
| 12 |
|
| 13 |
ss($hash); |
| 14 |
my $yaml = YAML::Dump($hash); |
| 15 |
$yaml =~ s|-\snull|- "null"|xmsg; |
| 16 |
write_file($file, $yaml); |
| 17 |
} |
| 18 |
|
| 19 |
sub ss { |
| 20 |
my ($hash) = @_; |
| 21 |
return unless ref($hash); |
| 22 |
return if ref($hash) eq "ARRAY"; |
| 23 |
for my $k ( keys %$hash ) { |
| 24 |
ss($hash->{$k}); |
| 25 |
} |
| 26 |
my @sorted_keys = qw( swagger basePath definitions paths info x-mojo-to operationId tags summary produces parameters responses x-koha-authorization); |
| 27 |
push @sorted_keys, qw( description type properties additionalProperties ); |
| 28 |
my @existing_keys = sort keys %$hash; |
| 29 |
my @dup = duplicates( @sorted_keys, @existing_keys ); |
| 30 |
my @uniq = uniq( @dup, @existing_keys ); |
| 31 |
push @dup, @uniq; |
| 32 |
@dup = uniq( @dup ); |
| 33 |
|
| 34 |
YAML::Bless($hash)->keys(\@dup); |
| 35 |
} |