From f011197e0017cb7e49f51dfbbf6897dc7514c207 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 May 2017 15:12:45 +0200 Subject: [PATCH] Update swagger to 2.0.24 --- COPYRIGHT | 137 +----- .../Luracast/Restler/explorer/css/screen.css | 43 +- .../Restler/explorer/images/logo_small.png | Bin 1620 -> 770 bytes .../Restler/explorer/images/pet_store_api.png | Bin 0 -> 824 bytes .../Restler/explorer/images/wordnik_api.png | Bin 0 -> 980 bytes .../Luracast/Restler/explorer/index.html | 34 +- .../Restler/explorer/lib/swagger-oauth.js | 115 +++-- .../Luracast/Restler/explorer/lib/swagger.js | 423 +++++++++++------- .../Luracast/Restler/explorer/swagger-ui.js | 331 ++++++++------ .../Restler/explorer/swagger-ui.min.js | 2 +- 10 files changed, 557 insertions(+), 528 deletions(-) create mode 100644 htdocs/includes/restler/framework/Luracast/Restler/explorer/images/pet_store_api.png create mode 100644 htdocs/includes/restler/framework/Luracast/Restler/explorer/images/wordnik_api.png diff --git a/COPYRIGHT b/COPYRIGHT index 61a0f2de6bd3f..04f0358a6554b 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -21,13 +21,13 @@ GeoIP 1.4 LGPL-2.1+ Yes Mobiledetect 2.8.17 MIT License Yes Detect mobile devices browsers NuSoap 0.9.5 LGPL 2.1+ Yes Library to develop SOAP Web services (not into rpm and deb package) PEAR Mail_MIME 1.8.9 BSD Yes NuSoap dependency -odtPHP 1.0.1 GPL-2+ b Yes Library to build/edit ODT files +odtPHP 1.0.1 GPL-2+ Yes Library to build/edit ODT files ParseDown 1.6 MIT License Yes Markdown parser PHPExcel 1.8.1 LGPL-2.1+ Yes Read/Write XLS files, read ODS files php-iban 1.4.7 LGPL-3+ Yes Parse and validate IBAN (and IIBAN) bank account information in PHP PHPoAuthLib 0.8.2 MIT License Yes Library to provide oauth1 and oauth2 to different service PHPPrintIPP 1.3 GPL-2+ Yes Library to send print IPP requests -Restler 3.0.0RC6 LGPL-3+ Yes Library to develop REST Web services +Restler 3.0.0RC6 LGPL-3+ Yes Library to develop REST Web services (+ swagger-ui js lib into dir explorer) TCPDF 6.2.12 LGPL-3+ Yes PDF generation TCPDI 1.0.0 LGPL-3+ / Apache 2.0 Yes FPDI replacement Swift Mailer 5.4.2-DEV MIT license Yes Comprehensive mailing tools for PHP @@ -52,138 +52,13 @@ jQuery Timepicker 1.1.0 GPL and MIT License Yes jQuery Tiptip 1.3 GPL and MIT License Yes JS library for tooltips jsGanttImproved 1.7.5.2 BSD License Yes JS library (to build Gantt reports) JsTimezoneDetect 1.0.6 MIT License Yes JS library to detect user timezone +SwaggerUI 2.0.24 GPL-2+ Yes JS library to offer the REST API explorer For licenses compatibility informations: http://www.gnu.org/licenses/licenses.en.html -Copyright ---------- - -Copyright (C) 2016 - -Copyright (C) 2015 -- Laurent Destailleur -- Marcos García -- Alexandre Spangaro -- Frederic France -- Regis Houssin - -Copyright (C) 2014 -- Laurent Destailleur -- Raphaël Doursenaud -- Jean-François Ferry -- Marcos García -- Philippe Grand -- Florian Henry -- Regis Houssin -- Maxime Kohlhaas -- Juanjo Menent -- Alexandre Spangaro -- Frederic France - -Copyright (C) 2013 -- Christophe Battarel -- Laurent Destailleur -- Jean-François Ferry -- Marcos García -- Philippe Grand -- Florian Henry -- Regis Houssin -- Maxime Kohlhaas -- Juanjo Menent -- Adolfo Segura -- Alexandre Spangaro - -Copyright (C) 2012 -- Christophe Battarel -- Laurent Destailleur -- Jean-François Ferry -- Marcos García -- Philippe Grand -- Jean Heimburger -- Florian Henry -- Regis Houssin -- Maxime Kohlhaas -- Juanjo Menent -- Nicolas Péré -- Alexandre Spangaro - -Copyright (C) 2011 -- Laurent Destailleur -- Regis Houssin -- Juanjo Menent -- Philippe Grand -- Jean Heimburger - -Copyright (C) 2010 -- Laurent Destailleur -- Regis Houssin -- Juanjo Menent -- r2gnl -- meos - -Copyright (C) 2009 -- Laurent Destailleur -- Regis Houssin -- Juanjo Menent - -Copyright (C) 2008 -- Laurent Destailleur -- Regis Houssin -- Rodolphe Quiedeville -- Jeremie Ollivier - -Copyright (C) 2007 -- Rodolphe Quiedeville -- Laurent Destailleur -- Regis Houssin -- Auguria SARL -- Jean Heimburger -- Jeremie Ollivier - -Copyright (C) 2006 -- Auguria SARL -- Marc Barilley/Ocebo -- Laurent Destailleur -- Rodolphe Quiedeville -- Regis Houssin -- Andre Cianfarani -- Yannick Warnier -- Jean Heimburger - -Copyright (C) 2005 -- Brice Davoleau -- Laurent Destailleur -- Benoit Mortier -- Rodolphe Quiedeville -- Eric Seigne -- Matthieu Valleton -- Regis Houssin - -Copyright (C) 2004 -- Laurent Destailleur -- Rodolphe Quiedeville -- Eric Seigne -- Benoit Mortier -- Christophe Combelles -- Sebastien Di Cintio - -Copyright (C) 2003 -- Jean-Louis Bergamo -- Xavier Dutoit -- Rodolphe Quiedeville -- Emmanuel Raviart -- Eric Seigne - -Copyright (C) 2002 -- Jean-Louis Bergamo -- Rodolphe Quiedeville - -Copyright (C) 2001 -- Rodolphe Quiedeville - - - - +Copyright / Authors +------------------- +See page https://github.com/Dolibarr/dolibarr/graphs/contributors diff --git a/htdocs/includes/restler/framework/Luracast/Restler/explorer/css/screen.css b/htdocs/includes/restler/framework/Luracast/Restler/explorer/css/screen.css index 2ac5625af0601..478b99837d70e 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/explorer/css/screen.css +++ b/htdocs/includes/restler/framework/Luracast/Restler/explorer/css/screen.css @@ -350,7 +350,7 @@ font-size: .85em; line-height: 1.2em; overflow: auto; - max-height: 400px; + max-height: 200px; cursor: pointer; } .swagger-section .swagger-ui-wrap .model-signature ul.signature-nav { @@ -743,17 +743,20 @@ display: inline-block; font-size: 0.9em; } -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header img { - display: block; - clear: none; - float: right; -} .swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header input.submit { display: block; clear: none; float: left; padding: 6px 8px; } +.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber { + background-image: url('../images/throbber.gif'); + width: 128px; + height: 16px; + display: block; + clear: none; + float: right; +} .swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content form input[type='text'].error { outline: 2px solid black; outline-color: #cc0000; @@ -1158,7 +1161,7 @@ cursor: pointer; } .swagger-section #header { - background-color: #646257; + background-color: #89bf04; padding: 14px; } .swagger-section #header a#logo { @@ -1193,7 +1196,7 @@ padding: 6px 8px; font-size: 0.9em; color: white; - background-color: #000000; + background-color: #547f00; -moz-border-radius: 4px; -webkit-border-radius: 4px; -o-border-radius: 4px; @@ -1202,35 +1205,13 @@ border-radius: 4px; } .swagger-section #header form#api_selector .input a#explore:hover { - background-color: #a41e22; + background-color: #547f00; } .swagger-section #header form#api_selector .input input { font-size: 0.9em; padding: 3px; margin: 0; } -.swagger-section #footer-nav { - margin-top: 50px; - color: #bbb; - float: left; - list-style: none; - font-size: 0.8em; -} -.swagger-section #footer-nav li { - display: block; - float: left; -} -.swagger-section #footer-nav a { - margin-right: 4px; - text-decoration: none; - font-weight: none; - padding: 4px 2px; - font-size: 0.9em; - color: #999; -} -.swagger-section #footer-nav a:hover { - color: #555; -} .swagger-section #content_message { margin: 10px 15px; font-style: italic; diff --git a/htdocs/includes/restler/framework/Luracast/Restler/explorer/images/logo_small.png b/htdocs/includes/restler/framework/Luracast/Restler/explorer/images/logo_small.png index 2ed3cf64be72132f93719f8014a6f440b06d818a..5496a65579ae903d4008f9d268fac422ef9d3679 100644 GIT binary patch delta 757 zcmVeSaefwW^{L9a%BKPWN%_+AW3auXJt}l zVPtu6$z?nM00N{*L_t(|+Qe5qY|}s#esPzIE@o)O=n+8&R{|*#L(PIfT{3hiQ=F}c zp~=FUc0*!FJHWzFGqE6%NL1<;XChLEdTG@Sk5yS*2~bDg=YQT+mV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zwriWWb1zVDZtTG?paYc|7T*|z0vmc|>Drcq6j5NpMz|2?cHb`i@?uwOi^ zq83NCbnz;42Pc0dj34#(XLPH(clD@>^Tx(273Y3H^+xZ#{TS}&gSD83m-~j}1AOfv zMVs~g)RU1HH|1RUcD`si?r4G*GZO0OveK+}{)fDYSTMi+hjRZR>cge1S zR@On$u^Zq1me^ji^p@q(E2tfBTvg3>Jq*E-5aaR-qd1lcM;WU z`vf>j9jA6B>rS5l-}&OHq0;I0;+3!cMzi&fqek1LqNjZyefrl8q?U<>9#!evrstg< z9UZRNU`5UKvUD!GPtvYGoKo%T9HASStIj)gc|l1glldggnPy|@c4zEtP{iK5USC1K ziz=MEGQLy=x@c#Hg$F8HUC&hyzUtY|{)^#UHYzzVSzcQ3^7e(a`*rm1RIaV^#o0IS z_w{vkWbY|374IK1=xA3vqFX{vwfG#EEU9>G9xCaaa>Z+G%+t}diAF+FEzVq};smoa zbi)HvbN`b!s}nDrr&Ia{2953Bcl~x&Cvp!-BYU1?)gSHc36Gp-R=&RcbjO;eQEGE& ta!w9m(NDOMo}d5m!&kLnqYQAv9LOHZ7#!&yyal!|q>!SLGf3{ne*t=UPFDZ` diff --git a/htdocs/includes/restler/framework/Luracast/Restler/explorer/images/pet_store_api.png b/htdocs/includes/restler/framework/Luracast/Restler/explorer/images/pet_store_api.png new file mode 100644 index 0000000000000000000000000000000000000000..f9f9cd4aeb35a108c4b2f1dddb59977d56c595d8 GIT binary patch literal 824 zcmV-81IPS{P)n=Rd;8mVwQNY4k4xJQ%YT}s;WA7;r!W@XgqjG_4og} z8w>{OB9REiMa8-B85td+y}bji^~2KA`Md4j-u{zw=H%Da@83%_8qEnl9k1WK;pWX- zb-lg)pQYAreK@>)*5Clqni{IZVYGG+NY67Bp-^bn;L{Nbh44I6CIK+n7p8#U?;fCA zYMFcy%UEjup4fgnli%NyzSe*@419QuU9lJ|T$?f9w?HIQ$RwEJGK7^!y7LhxIgVJp z9c!kB{0aydM1epU1NJ=h(}2X?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aggerUi({ url: "resources.json", + validatorUrl: null, dom_id: "swagger-ui-container", - supportedSubmitMethods: ['get', 'post', 'put', 'patch', 'delete'], + supportedSubmitMethods: ['get', 'post', 'put', 'delete'], onComplete: function(swaggerApi, swaggerUi){ - log("Loaded Api Explorer"); + log("Loaded API Explorer"); if(typeof initOAuth == "function") { /* @@ -45,15 +45,19 @@ hljs.highlightBlock(e) }); }, + defaultModelRendering: 'model', onFailure: function(data) { - log("Unable to Load Api Explorer"); + log("Unable to Load API Explorer"); }, - docExpansion: "none" + docExpansion: "none", + /*showRequestHeaders: true, + jsonEditor: true */ + /*, sorter : "alpha"*/ }); $('#input_apiKey').change(function() { var key = $('#input_apiKey')[0].value; - + log("key: " + key); if(key && key.trim() != "") { /* DOL_CHANGE LDR We set DOLAPIKEY into header */ log("added key " + key); @@ -67,11 +71,15 @@ console.log("header DOLAPIKEY added with value "+key); } }) - window.swaggerUi.load(); }); - + + @@ -79,6 +87,14 @@
+
diff --git a/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger-oauth.js b/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger-oauth.js index 19777eb90f003..8bb17fb076aba 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger-oauth.js +++ b/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger-oauth.js @@ -48,72 +48,65 @@ function handleLogin() { str += ''; popup.append(str); } - - - var $win = $(window), - dw = $win.width(), - dh = $win.height(), - st = $win.scrollTop(), - dlgWd = popupDialog.outerWidth(), - dlgHt = popupDialog.outerHeight(), - top = (dh -dlgHt)/2 + st, - left = (dw - dlgWd)/2; - - popupDialog.css({ - top: (top < 0? 0 : top) + 'px', - left: (left < 0? 0 : left) + 'px' - }); - - popupDialog.find('button.api-popup-cancel').click(function() { - popupMask.hide(); - popupDialog.hide(); - }); - popupDialog.find('button.api-popup-authbtn').click(function() { - popupMask.hide(); - popupDialog.hide(); - - var authSchemes = window.swaggerUi.api.authSchemes; - var location = window.location; - var locationUrl = location.protocol + '//' + location.host + location.pathname; - var redirectUrl = locationUrl.replace("index.html","").concat("/o2c.html").replace("//o2c.html","/o2c.html"); - var url = null; - - var p = window.swaggerUi.api.authSchemes; - for (var key in p) { - if (p.hasOwnProperty(key)) { - var o = p[key].grantTypes; - for(var t in o) { - if(o.hasOwnProperty(t) && t === 'implicit') { - var dets = o[t]; - url = dets.loginEndpoint.url + "?response_type=token"; - window.swaggerUi.tokenName = dets.tokenName; - } + } + + var $win = $(window), + dw = $win.width(), + dh = $win.height(), + st = $win.scrollTop(), + dlgWd = popupDialog.outerWidth(), + dlgHt = popupDialog.outerHeight(), + top = (dh -dlgHt)/2 + st, + left = (dw - dlgWd)/2; + + popupDialog.css({ + top: (top < 0? 0 : top) + 'px', + left: (left < 0? 0 : left) + 'px' + }); + + popupDialog.find('button.api-popup-cancel').click(function() { + popupMask.hide(); + popupDialog.hide(); + }); + popupDialog.find('button.api-popup-authbtn').click(function() { + popupMask.hide(); + popupDialog.hide(); + + var authSchemes = window.swaggerUi.api.authSchemes; + var host = window.location; + var pathname = location.pathname.substring(0, location.pathname.lastIndexOf("/")); + var redirectUrl = host.protocol + '//' + host.host + pathname + "/o2c.html"; + var url = null; + + for (var key in authSchemes) { + if (authSchemes.hasOwnProperty(key)) { + var o = authSchemes[key].grantTypes; + for(var t in o) { + if(o.hasOwnProperty(t) && t === 'implicit') { + var dets = o[t]; + url = dets.loginEndpoint.url + "?response_type=token"; + window.swaggerUi.tokenName = dets.tokenName; } } } - var scopes = []; - var scopeForUrl=''; - var o = $('.api-popup-scopes').find('input:checked'); - - for(var k =0; k < o.length; k++) { - scopes.push($(o[k]).attr("scope")); - if(k > 0){ - scopeForUrl+=' '; - } - scopeForUrl+=$(o[k]).attr("scope"); - } + } + var scopes = [] + var o = $('.api-popup-scopes').find('input:checked'); - window.enabledScopes=scopes; - + for(k =0; k < o.length; k++) { + scopes.push($(o[k]).attr("scope")); + } - url += '&redirect_uri=' + encodeURIComponent(redirectUrl); - url += '&realm=' + encodeURIComponent(realm); - url += '&client_id=' + encodeURIComponent(clientId); - url += '&scope=' + encodeURIComponent(scopeForUrl); + window.enabledScopes=scopes; + + url += '&redirect_uri=' + encodeURIComponent(redirectUrl); + url += '&realm=' + encodeURIComponent(realm); + url += '&client_id=' + encodeURIComponent(clientId); + url += '&scope=' + encodeURIComponent(scopes); + + window.open(url); + }); - window.open(url); - }); - } popupMask.show(); popupDialog.show(); return; @@ -211,7 +204,7 @@ function onOAuthComplete(token) { } }); - window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header")); + window.authorizations.add("oauth2", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header")); } } } diff --git a/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger.js b/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger.js index 2100bb81e83df..9e73a9b33e2ca 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger.js +++ b/htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/swagger.js @@ -1,5 +1,5 @@ // swagger.js -// version 2.0.30 +// version 2.0.39 var __bind = function(fn, me){ return function(){ @@ -11,10 +11,20 @@ log = function(){ log.history = log.history || []; log.history.push(arguments); if(this.console){ - console.log( Array.prototype.slice.call(arguments) ); + console.log( Array.prototype.slice.call(arguments)[0] ); } }; +// if you want to apply conditional formatting of parameter values +parameterMacro = function(value) { + return value; +} + +// if you want to apply conditional formatting of model property values +modelPropertyMacro = function(value) { + return value; +} + if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(obj, start) { for (var i = (start || 0), j = this.length; i < j; i++) { @@ -45,48 +55,50 @@ if (!('map' in Array.prototype)) { } Object.keys = Object.keys || (function () { - var hasOwnProperty = Object.prototype.hasOwnProperty, - hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"), - DontEnums = [ - 'toString', - 'toLocaleString', - 'valueOf', - 'hasOwnProperty', - 'isPrototypeOf', - 'propertyIsEnumerable', - 'constructor' - ], - DontEnumsLength = DontEnums.length; - - return function (o) { - if (typeof o != "object" && typeof o != "function" || o === null) - throw new TypeError("Object.keys called on a non-object"); - - var result = []; - for (var name in o) { - if (hasOwnProperty.call(o, name)) - result.push(name); - } - - if (hasDontEnumBug) { - for (var i = 0; i < DontEnumsLength; i++) { - if (hasOwnProperty.call(o, DontEnums[i])) - result.push(DontEnums[i]); - } - } - - return result; - }; -})(); + var hasOwnProperty = Object.prototype.hasOwnProperty, + hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"), + DontEnums = [ + 'toString', + 'toLocaleString', + 'valueOf', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'constructor' + ], + DontEnumsLength = DontEnums.length; + + return function (o) { + if (typeof o != "object" && typeof o != "function" || o === null) + throw new TypeError("Object.keys called on a non-object"); + + var result = []; + for (var name in o) { + if (hasOwnProperty.call(o, name)) + result.push(name); + } + + if (hasDontEnumBug) { + for (var i = 0; i < DontEnumsLength; i++) { + if (hasOwnProperty.call(o, DontEnums[i])) + result.push(DontEnums[i]); + } + } + return result; + }; +})(); var SwaggerApi = function(url, options) { + this.isBuilt = false; this.url = null; this.debug = false; this.basePath = null; this.authorizations = null; this.authorizationScheme = null; this.info = null; + this.useJQuery = false; + this.modelsArray = []; options = (options||{}); if (url) @@ -103,13 +115,20 @@ var SwaggerApi = function(url, options) { if (options.success != null) this.success = options.success; + if (typeof options.useJQuery === 'boolean') + this.useJQuery = options.useJQuery; + this.failure = options.failure != null ? options.failure : function() {}; this.progress = options.progress != null ? options.progress : function() {}; - if (options.success != null) + if (options.success != null) { this.build(); + this.isBuilt = true; + } } SwaggerApi.prototype.build = function() { + if(this.isBuilt) + return this; var _this = this; this.progress('fetching resource list: ' + this.url); var obj = { @@ -117,7 +136,7 @@ SwaggerApi.prototype.build = function() { url: this.url, method: "get", headers: { - accept: "application/json" + accept: "application/json,application/json;charset=\"utf-8\",*/*" }, on: { error: function(response) { @@ -154,6 +173,7 @@ SwaggerApi.prototype.buildFromSpec = function(response) { } this.apis = {}; this.apisArray = []; + this.consumes = response.consumes; this.produces = response.produces; this.authSchemes = response.authorizations; if (response.info != null) { @@ -171,13 +191,13 @@ SwaggerApi.prototype.buildFromSpec = function(response) { } } } - if (response.basePath) { + if (response.basePath) this.basePath = response.basePath; - } else if (this.url.indexOf('?') > 0) { + else if (this.url.indexOf('?') > 0) this.basePath = this.url.substring(0, this.url.lastIndexOf('?')); - } else { + else this.basePath = this.url; - } + if (isApi) { var newName = response.resourcePath.replace(/\//g, ''); this.resourcePath = response.resourcePath; @@ -272,7 +292,6 @@ SwaggerApi.prototype.fail = function(message) { SwaggerApi.prototype.setConsolidatedModels = function() { var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results; - this.modelsArray = []; this.models = {}; _ref = this.apis; for (resource_name in _ref) { @@ -317,8 +336,8 @@ var SwaggerResource = function(resourceObj, api) { var _this = this; this.api = api; this.api = this.api; - produces = []; - consumes = []; + consumes = (this.consumes | []); + produces = (this.produces | []); this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path; this.description = resourceObj.description; @@ -349,7 +368,7 @@ var SwaggerResource = function(resourceObj, api) { method: "get", useJQuery: this.useJQuery, headers: { - accept: "application/json" + accept: "application/json,application/json;charset=\"utf-8\",*/*" }, on: { response: function(resp) { @@ -368,22 +387,28 @@ var SwaggerResource = function(resourceObj, api) { } } -SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) { - var parts, pos, url; +SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) { + var pos, url; url = this.api.basePath; pos = url.lastIndexOf(relativeBasePath); - if (pos === -1) { - parts = url.split("/"); - url = parts[0] + "//" + parts[2]; - if (relativeBasePath.indexOf("/") === 0) { - return url + relativeBasePath; - } else { - return url + "/" + relativeBasePath; - } - } else if (relativeBasePath === "/") { - return url.substring(0, pos); - } else { - return url.substring(0, pos) + relativeBasePath; + var parts = url.split("/"); + var rootUrl = parts[0] + "//" + parts[2]; + + if(relativeBasePath.indexOf("http") === 0) + return relativeBasePath; + if(relativeBasePath === "/") + return rootUrl; + if(relativeBasePath.substring(0, 1) == "/") { + // use root + relative + return rootUrl + relativeBasePath; + } + else { + var pos = this.basePath.lastIndexOf("/"); + var base = this.basePath.substring(0, pos); + if(base.substring(base.length - 1) == "/") + return base + relativeBasePath; + else + return base + "/" + relativeBasePath; } }; @@ -478,8 +503,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, SwaggerResource.prototype.sanitize = function(nickname) { var op; - op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_'); - //' + op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g, '_'); op = op.replace(/((_){2,})/g, '_'); op = op.replace(/^(_)*/g, ''); op = op.replace(/([_])*$/g, ''); @@ -584,6 +608,7 @@ var SwaggerModelProperty = function(name, obj) { this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set'); this.descr = obj.description; this.required = obj.required; + this.defaultValue = modelPropertyMacro(obj.defaultValue); if (obj.items != null) { if (obj.items.type != null) { this.refDataType = obj.items.type; @@ -629,7 +654,9 @@ SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) { SwaggerModelProperty.prototype.toSampleValue = function(value) { var result; - if (value === "integer") { + if ((typeof this.defaultValue !== 'undefined') && this.defaultValue !== null) { + result = this.defaultValue; + } else if (value === "integer") { result = 0; } else if (value === "boolean") { result = false; @@ -759,6 +786,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not } } } + param.defaultValue = parameterMacro(param.defaultValue); } this.resource[this.nickname] = function(args, callback, error) { return _this["do"](args, callback, error); @@ -812,7 +840,7 @@ SwaggerOperation.prototype.getSampleJSON = function(type, models) { else return JSON.stringify(val, null, 2); } - else + else return val; } }; @@ -1073,7 +1101,7 @@ SwaggerOperation.prototype.formatXml = function(xml) { var SwaggerRequest = function(type, url, params, opts, successCallback, errorCallback, operation, execution) { var _this = this; var errors = []; - this.useJQuery = (typeof operation.useJQuery !== 'undefined' ? operation.useJQuery : null); + this.useJQuery = (typeof operation.resource.useJQuery !== 'undefined' ? operation.resource.useJQuery : null); this.type = (type||errors.push("SwaggerRequest type is required (get/post/put/delete/patch/options).")); this.url = (url||errors.push("SwaggerRequest url is required.")); this.params = params; @@ -1090,96 +1118,59 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal this.type = this.type.toUpperCase(); - var myHeaders = {}; + // set request, response content type headers + var headers = this.setHeaders(params, this.operation); var body = params.body; - var parent = params["parent"]; - var requestContentType = "application/json"; - - var formParams = []; - var fileParams = []; - var params = this.operation.parameters; - - for(var i = 0; i < params.length; i++) { - var param = params[i]; - if(param.paramType === "form") - formParams.push(param); - else if(param.paramType === "file") - fileParams.push(param); - } - - - if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) { - if (this.opts.requestContentType) { - requestContentType = this.opts.requestContentType; - } - } else { - // if any form params, content type must be set - if(formParams.length > 0) { - if(fileParams.length > 0) - requestContentType = "multipart/form-data"; - else - requestContentType = "application/x-www-form-urlencoded"; + // encode the body for form submits + if (headers["Content-Type"]) { + var values = {}; + var i; + var operationParams = this.operation.parameters; + for(i = 0; i < operationParams.length; i++) { + var param = operationParams[i]; + if(param.paramType === "form") + values[param.name] = param; } - else if (this.type != "DELETE") - requestContentType = null; - } - if (requestContentType && this.operation.consumes) { - if (this.operation.consumes[requestContentType] === 'undefined') { - log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes)); - if (this.requestContentType === null) { - requestContentType = this.operation.consumes[0]; + if(headers["Content-Type"].indexOf("application/x-www-form-urlencoded") === 0) { + var encoded = ""; + var key; + for(key in values) { + value = this.params[key]; + if(typeof value !== 'undefined'){ + if(encoded !== "") + encoded += "&"; + encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); + } } + body = encoded; } - } - - var responseContentType = null; - if (this.opts.responseContentType) { - responseContentType = this.opts.responseContentType; - } else { - responseContentType = "application/json"; - } - if (responseContentType && this.operation.produces) { - if (this.operation.produces[responseContentType] === 'undefined') { - log("server can't produce " + responseContentType); - } - } - if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) { - var fields = {}; - var possibleParams = {}; - var values = {}; - var key; - for(key in formParams){ - var param = formParams[key]; - values[param.name] = param; - } - - var encoded = ""; - var key; - for(key in values) { - value = this.params[key]; - if(typeof value !== 'undefined'){ - if(encoded !== "") - encoded += "&"; - encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); + else if (headers["Content-Type"].indexOf("multipart/form-data") === 0) { + // encode the body for form submits + var data = ""; + var boundary = "----SwaggerFormBoundary" + Date.now(); + var key; + for(key in values) { + value = this.params[key]; + if(typeof value !== 'undefined') { + data += '--' + boundary + '\n'; + data += 'Content-Disposition: form-data; name="' + key + '"'; + data += '\n\n'; + data += value + "\n"; + } } + data += "--" + boundary + "--\n"; + headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; + body = data; } - body = encoded; } - var name; - for (name in this.headers) - myHeaders[name] = this.headers[name]; - if ((requestContentType && body !== "") || (requestContentType === "application/x-www-form-urlencoded")) - myHeaders["Content-Type"] = requestContentType; - if (responseContentType) - myHeaders["Accept"] = responseContentType; if (!((this.headers != null) && (this.headers.mock != null))) { obj = { url: this.url, method: this.type, - headers: myHeaders, + headers: headers, body: body, useJQuery: this.useJQuery, on: { @@ -1216,6 +1207,77 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal } }; +SwaggerRequest.prototype.setHeaders = function(params, operation) { + // default type + var accepts = "application/json"; + var consumes = "application/json"; + + var allDefinedParams = this.operation.parameters; + var definedFormParams = []; + var definedFileParams = []; + var body = params.body; + var headers = {}; + + // get params from the operation and set them in definedFileParams, definedFormParams, headers + var i; + for(i = 0; i < allDefinedParams.length; i++) { + var param = allDefinedParams[i]; + if(param.paramType === "form") + definedFormParams.push(param); + else if(param.paramType === "file") + definedFileParams.push(param); + else if(param.paramType === "header" && this.params.headers) { + var key = param.name; + var headerValue = this.params.headers[param.name]; + if(typeof this.params.headers[param.name] !== 'undefined') + headers[key] = headerValue; + } + } + + // if there's a body, need to set the accepts header via requestContentType + if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) { + if (this.opts.requestContentType) + consumes = this.opts.requestContentType; + } else { + // if any form params, content type must be set + if(definedFormParams.length > 0) { + if(definedFileParams.length > 0) + consumes = "multipart/form-data"; + else + consumes = "application/x-www-form-urlencoded"; + } + else if (this.type === "DELETE") + body = "{}"; + else if (this.type != "DELETE") + accepts = null; + } + + if (consumes && this.operation.consumes) { + if (this.operation.consumes.indexOf(consumes) === -1) { + log("server doesn't consume " + consumes + ", try " + JSON.stringify(this.operation.consumes)); + consumes = this.operation.consumes[0]; + } + } + + if (this.opts.responseContentType) { + accepts = this.opts.responseContentType; + } else { + accepts = "application/json"; + } + if (accepts && this.operation.produces) { + if (this.operation.produces.indexOf(accepts) === -1) { + log("server can't produce " + accepts); + accepts = this.operation.produces[0]; + } + } + + if ((consumes && body !== "") || (consumes === "application/x-www-form-urlencoded")) + headers["Content-Type"] = consumes; + if (accepts) + headers["Accept"] = accepts; + return headers; +} + SwaggerRequest.prototype.asCurl = function() { var results = []; if(this.headers) { @@ -1259,9 +1321,16 @@ SwaggerHttp.prototype.isIE8 = function() { }; /* - * JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic + * JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic. + * NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space. + * Since we are using closures here we need to alias it for internal use. */ -var JQueryHttpClient = function(options) {} +var JQueryHttpClient = function(options) { + "use strict"; + if(!jQuery){ + var jQuery = window.jQuery; + } +} JQueryHttpClient.prototype.execute = function(obj) { var cb = obj.on; @@ -1335,8 +1404,8 @@ JQueryHttpClient.prototype.execute = function(obj) { return cb.response(out); }; - $.support.cors = true; - return $.ajax(obj); + jQuery.support.cors = true; + return jQuery.ajax(obj); } /* @@ -1411,11 +1480,36 @@ ShredHttpClient.prototype.execute = function(obj) { return out; }; + // Transform an error into a usable response-like object + var transformError = function(error) { + var out = { + // Default to a status of 0 - The client will treat this as a generic permissions sort of error + status: 0, + data: error.message || error + }; + + if(error.code) { + out.obj = error; + + if(error.code === 'ENOTFOUND' || error.code === 'ECONNREFUSED' ) { + // We can tell the client that this should be treated as a missing resource and not as a permissions thing + out.status = 404; + } + } + + return out; + }; + res = { error: function(response) { if (obj) return cb.error(transform(response)); }, + // Catch the Shred error raised when the request errors as it is made (i.e. No Response is coming) + request_error: function(err) { + if(obj) + return cb.error(transformError(err)); + }, redirect: function(response) { if (obj) return cb.redirect(transform(response)); @@ -1452,26 +1546,42 @@ SwaggerAuthorizations.prototype.remove = function(name) { }; SwaggerAuthorizations.prototype.apply = function(obj, authorizations) { - status = null; + var status = null; var key; - for (key in this.authz) { - value = this.authz[key]; - result = value.apply(obj, authorizations); - if (result === false) - status = false; - if (result === true) - status = true; + + // if the "authorizations" key is undefined, or has an empty array, add all keys + if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) { + for (key in this.authz) { + value = this.authz[key]; + result = value.apply(obj, authorizations); + if (result === true) + status = true; + } } + else { + for(name in authorizations) { + for (key in this.authz) { + if(key == name) { + value = this.authz[key]; + result = value.apply(obj, authorizations); + if (result === true) + status = true; + } + } + } + } + return status; }; /** * ApiKeyAuthorization allows a query param or header to be injected */ -var ApiKeyAuthorization = function(name, value, type) { +var ApiKeyAuthorization = function(name, value, type, delimiter) { this.name = name; this.value = value; this.type = type; + this.delimiter = delimiter; }; ApiKeyAuthorization.prototype.apply = function(obj, authorizations) { @@ -1482,7 +1592,12 @@ ApiKeyAuthorization.prototype.apply = function(obj, authorizations) { obj.url = obj.url + "?" + this.name + "=" + this.value; return true; } else if (this.type === "header") { - obj.headers[this.name] = this.value; + if(typeof obj.headers[this.name] !== 'undefined') { + if(typeof this.delimiter !== 'undefined') + obj.headers[this.name] = obj.headers[this.name] + this.delimiter + this.value; + } + else + obj.headers[this.name] = this.value; return true; } }; diff --git a/htdocs/includes/restler/framework/Luracast/Restler/explorer/swagger-ui.js b/htdocs/includes/restler/framework/Luracast/Restler/explorer/swagger-ui.js index 5c6aad20be67b..c28bf145ab60f 100644 --- a/htdocs/includes/restler/framework/Luracast/Restler/explorer/swagger-ui.js +++ b/htdocs/includes/restler/framework/Luracast/Restler/explorer/swagger-ui.js @@ -1,5 +1,5 @@ // swagger-ui.js -// version 2.0.17 +// version 2.0.23 $(function() { // Helper function for vertically aligning DOM elements @@ -68,7 +68,7 @@ log = function(){ log.history = log.history || []; log.history.push(arguments); if(this.console){ - console.log( Array.prototype.slice.call(arguments) ); + console.log( Array.prototype.slice.call(arguments)[0] ); } }; @@ -240,67 +240,74 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; function program1(depth0,data) { var buffer = "", stack1, stack2; - buffer += "\n "; + buffer += "\n
" + + escapeExpression(((stack1 = ((stack1 = depth0.info),stack1 == null || stack1 === false ? stack1 : stack1.title)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1)) + + "
\n
"; + stack2 = ((stack1 = ((stack1 = depth0.info),stack1 == null || stack1 === false ? stack1 : stack1.description)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1); + if(stack2 || stack2 === 0) { buffer += stack2; } + buffer += "
\n "; stack2 = helpers['if'].call(depth0, ((stack1 = depth0.info),stack1 == null || stack1 === false ? stack1 : stack1.termsOfServiceUrl), {hash:{},inverse:self.noop,fn:self.program(2, program2, data),data:data}); if(stack2 || stack2 === 0) { buffer += stack2; } - buffer += "\n "; + buffer += "\n "; stack2 = helpers['if'].call(depth0, ((stack1 = depth0.info),stack1 == null || stack1 === false ? stack1 : stack1.contact), {hash:{},inverse:self.noop,fn:self.program(4, program4, data),data:data}); if(stack2 || stack2 === 0) { buffer += stack2; } - buffer += "\n "; + buffer += "\n "; stack2 = helpers['if'].call(depth0, ((stack1 = depth0.info),stack1 == null || stack1 === false ? stack1 : stack1.license), {hash:{},inverse:self.noop,fn:self.program(6, program6, data),data:data}); if(stack2 || stack2 === 0) { buffer += stack2; } - buffer += "\n "; + buffer += "\n "; return buffer; } function program2(depth0,data) { var buffer = "", stack1; - buffer += "
  • Terms
  • "; + + "\">Terms of service
    "; return buffer; } function program4(depth0,data) { var buffer = "", stack1; - buffer += "
  • Contact
  • "; + + "\">Contact the developer"; return buffer; } function program6(depth0,data) { var buffer = "", stack1; - buffer += "
  • " + escapeExpression(((stack1 = ((stack1 = depth0.info),stack1 == null || stack1 === false ? stack1 : stack1.license)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1)) - + "\"> License
  • "; + + ""; return buffer; } function program8(depth0,data) { var buffer = "", stack1; - buffer += " v"; + buffer += "\n , api version: "; if (stack1 = helpers.apiVersion) { stack1 = stack1.call(depth0, {hash:{},data:data}); } else { stack1 = depth0.apiVersion; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } - buffer += escapeExpression(stack1); + buffer += escapeExpression(stack1) + + "\n "; return buffer; } - buffer += "
    \n
    \n
    \n
      \n
    \n\n
    \n
      \n "; + buffer += "
      \n "; stack1 = helpers['if'].call(depth0, depth0.info, {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data}); if(stack1 || stack1 === 0) { buffer += stack1; } - buffer += "\n
    • \n "; + buffer += "\n
    • \n
      \n
        \n
      \n\n
      \n
      \n
      \n

      [ base url: "; if (stack1 = helpers.basePath) { stack1 = stack1.call(depth0, {hash:{},data:data}); } else { stack1 = depth0.basePath; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } - buffer += escapeExpression(stack1); + buffer += escapeExpression(stack1) + + "\n "; stack1 = helpers['if'].call(depth0, depth0.apiVersion, {hash:{},inverse:self.noop,fn:self.program(8, program8, data),data:data}); if(stack1 || stack1 === 0) { buffer += stack1; } - buffer += " Powered by Restler & Swagger\n \n

    \n
    \n
    \n"; + buffer += "]\n \n\n"; return buffer; }); })(); @@ -389,7 +396,7 @@ function program18(depth0,data) { function program20(depth0,data) { - return "\n
    \n \n \n \n
    \n "; + return "\n
    \n \n \n \n
    \n "; } buffer += "\n