From 9e76c630469ee4eab3e31a7a35905efd21f17448 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Tue, 9 Feb 2016 04:07:30 +0200 Subject: [PATCH] Bug 15126 - REST API: Use newer version of Swagger2. Swagger2 minifier. Minifies the swagger.json on demand. --- api/v1/minifySwagger.pl | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 api/v1/minifySwagger.pl diff --git a/api/v1/minifySwagger.pl b/api/v1/minifySwagger.pl new file mode 100755 index 0000000..c9de3fe --- /dev/null +++ b/api/v1/minifySwagger.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl + +# Copyright 2016 KohaSuomi +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Getopt::Long qw(:config no_ignore_case); + +use Swagger2; + +my $help = 0; +my $verbose = 0; +my $swaggerFile = "swagger.json"; +my $swaggerMinifiedFile = "swagger.min.json"; + +GetOptions( + 'h|help' => \$help, + 'v|verbose:i' => \$verbose, + 's|source:s' => \$swaggerFile, + 'd|destination:s' => \$swaggerMinifiedFile, +); + +my $usage = <new($swaggerFile); +$swagger = $swagger->expand; #Fetch all JSON-Schema references + +open(SWOUT, ">:encoding(UTF-8)", $swaggerMinifiedFile) or die "$0: Couldn't open the minified Swagger2 output file:\n $!"; +print SWOUT $swagger->to_string(); +close(SWOUT); \ No newline at end of file -- 1.9.1