Bugzilla – Attachment 52982 Details for
Bug 16212
Swagger specification separation and minification
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 16212: Add script minifySwagger.pl
SIGNED-OFF-Bug-16212-Add-script-minifySwaggerpl.patch (text/plain), 4.41 KB, created by
Johanna Räisä
on 2016-06-30 13:50:52 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 16212: Add script minifySwagger.pl
Filename:
MIME Type:
Creator:
Johanna Räisä
Created:
2016-06-30 13:50:52 UTC
Size:
4.41 KB
patch
obsolete
>From ab16f14308f8a3fafb1abe18ecef7c69d46dd783 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 6 Apr 2016 13:16:50 +0200 >Subject: [PATCH] [SIGNED-OFF] Bug 16212: Add script minifySwagger.pl >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Signed-off-by: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> > >My name is Olli-Antti Kivilahti and I approve this commit. >We have been using the Swagger2.0-driven REST API on Mojolicious for 1 year now >in production and I am certain we have a pretty good idea on how to work with >the limitations of Swagger2.0 > >Signed-off-by: Johanna Raisa <johanna.raisa@gmail.com> > >My name is Johanna Räisä and I approve this commit. >We have been using Swagger2.0-driven REST API in production successfully. >--- > misc/devel/minifySwagger.pl | 98 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 98 insertions(+) > create mode 100644 misc/devel/minifySwagger.pl > >diff --git a/misc/devel/minifySwagger.pl b/misc/devel/minifySwagger.pl >new file mode 100644 >index 0000000..bf8ea41 >--- /dev/null >+++ b/misc/devel/minifySwagger.pl >@@ -0,0 +1,98 @@ >+#!/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); >+ >+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 = <<USAGE; >+ >+minifySwagger.pl >+ >+Reads the swagger.json -file and all referenced JSON-Schema -files and merges >+them into one merged and minified version. This minified swagger-file is >+intended to be shared to our API consumers. >+ >+By default you must run this script from the same directory as the 'swagger.json' >+and the minified specification is written to 'swagger.min.json'. >+This is a convenience to make the minification process as easy as possible. >+ >+!DO NOT! set the executable flag on, or this can be ran from the internetz. >+ >+ -h --help This happy helpful help! >+ >+ -v --verbose 0, default, no output. >+ 1, turn on internal Swagger debugging flags >+ 2, more verbose Swagger2 debugging >+ >+ -s --source Which Swagger2-specification file to minify? >+ Defaults to "swagger.json" >+ >+ -d --destination Where to write the minified Swagger2-spec? >+ Defaults to "swagger.min.json" >+ >+EXAMPLES: >+ >+ perl minifySwagger.pl -v 1 -s api/v1/swagger/swagger.json -d swag.json >+ cd api/v1/swagger && perl minifySwagger.pl >+ >+USAGE >+ >+if ($help) { >+ print $usage; >+ exit 0; >+} >+if ($verbose > 0) { >+ $ENV{SWAGGER2_DEBUG} = $verbose; >+} >+ >+ >+require Swagger2; #When you import the Swagger2-libraries, the environment variables are checked and cannot be altered anymore. So set verbosity first, then load libs. >+my $swagger = Swagger2->new($swaggerFile); >+$swagger = $swagger->expand; #Fetch all JSON-Schema references >+ >+my @errors = $swagger->validate; >+print join("\n", "Swagger2: Invalid spec:", @errors)."\n" if @errors; >+exit 1 if @errors; >+ >+removeNonSwagger2Values($swagger); >+ >+open(SWOUT, ">:encoding(UTF-8)", $swaggerMinifiedFile) or die "$0: Couldn't open the minified Swagger2 output file '$swaggerMinifiedFile':\n $!"; >+print SWOUT $swagger->to_string(); >+close(SWOUT); >+ >+##For some reason stringifying the Swagger2-spec adds non-valid parameters, like "/id" >+sub removeNonSwagger2Values { >+ my ($swagger) = @_; >+ >+ my $data = $swagger->api_spec->data; >+ delete($data->{id}); >+} >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16212
:
49949
|
49950
|
52368
|
52369
|
52576
|
52589
|
52590
|
52601
|
52651
|
52952
|
52953
|
52954
|
52955
|
52968
|
52969
|
52970
|
52971
|
52972
|
52973
|
52982
|
52983
|
52984
|
52985
|
54286
|
54287
|
54288
|
54870
|
54871
|
54872
|
54873