Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2016 KohaSuomi |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it under the |
8 |
# terms of the GNU General Public License as published by the Free Software |
9 |
# Foundation; either version 3 of the License, or (at your option) any later |
10 |
# version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
15 |
# |
16 |
# You should have received a copy of the GNU General Public License along |
17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Getopt::Long qw(:config no_ignore_case); |
23 |
|
24 |
use Swagger2; |
25 |
|
26 |
my $help = 0; |
27 |
my $verbose = 0; |
28 |
my $swaggerFile = "swagger.json"; |
29 |
my $swaggerMinifiedFile = "swagger.min.json"; |
30 |
|
31 |
GetOptions( |
32 |
'h|help' => \$help, |
33 |
'v|verbose:i' => \$verbose, |
34 |
's|source:s' => \$swaggerFile, |
35 |
'd|destination:s' => \$swaggerMinifiedFile, |
36 |
); |
37 |
|
38 |
my $usage = <<USAGE; |
39 |
|
40 |
minifySwagger.pl |
41 |
|
42 |
Reads the swagger.json -file and all referenced JSON-Schema -files and merges |
43 |
them into one merged and minified version. This minified swagger-file is |
44 |
intended to be shared to our API consumers. |
45 |
|
46 |
By default you must run this script from the same directory as the 'swagger.json' |
47 |
and the minified specification is written to 'swagger.min.json'. |
48 |
This is a convenience to make the minification process as easy as possible. |
49 |
|
50 |
-h --help This happy helpful help! |
51 |
|
52 |
-v --verbose 0, default, no output. |
53 |
1, turn on internal Swagger debugging flags |
54 |
|
55 |
-s --source Which Swagger2-specification file to minify? |
56 |
Defaults to "swagger.json" |
57 |
|
58 |
-d --destination Where to write the minified Swagger2-spec? |
59 |
Defaults to "swagger.min.json" |
60 |
|
61 |
EXAMPLES: |
62 |
|
63 |
perl minifySwagger.pl -v 1 -s api/v1/swagger/swagger.json -d swag.json |
64 |
cd api/v1/swagger && perl minifySwagger.pl |
65 |
|
66 |
USAGE |
67 |
|
68 |
if ($help) { |
69 |
print $usage; |
70 |
exit 0; |
71 |
} |
72 |
|
73 |
my $swagger = Swagger2->new($swaggerFile); |
74 |
$swagger = $swagger->expand; #Fetch all JSON-Schema references |
75 |
|
76 |
open(SWOUT, ">:encoding(UTF-8)", $swaggerMinifiedFile) or die "$0: Couldn't open the minified Swagger2 output file:\n $!"; |
77 |
print SWOUT $swagger->to_string(); |
78 |
close(SWOUT); |