swagger-client 2.1.32 → 2.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -78
- package/browser/swagger-client.js +221 -363
- package/browser/swagger-client.min.js +8 -8
- package/lib/auth.js +1 -1
- package/lib/client.js +17 -65
- package/lib/helpers.js +2 -23
- package/lib/http.js +31 -22
- package/lib/resolver.js +97 -101
- package/lib/schema-markup.js +17 -10
- package/lib/spec-converter.js +1 -3
- package/lib/types/operation.js +42 -125
- package/package.json +1 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* swagger-client - swagger-client is a javascript client for use with swaggering APIs.
|
|
3
|
-
* @version v2.
|
|
3
|
+
* @version v2.2.21
|
|
4
4
|
* @link http://swagger.io
|
|
5
5
|
* @license Apache-2.0
|
|
6
6
|
*/
|
|
@@ -11,31 +11,31 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
},{"./helpers":4,"btoa":13,"cookiejar":18,"lodash-compat/collection/each":52,"lodash-compat/collection/includes":55,"lodash-compat/lang/isArray":140,"lodash-compat/lang/isObject":144}],3:[function(require,module,exports){
|
|
14
|
-
"use strict";var _={bind:require("lodash-compat/function/bind"),cloneDeep:require("lodash-compat/lang/cloneDeep"),find:require("lodash-compat/collection/find"),forEach:require("lodash-compat/collection/forEach"),indexOf:require("lodash-compat/array/indexOf"),isArray:require("lodash-compat/lang/isArray"),isObject:require("lodash-compat/lang/isObject"),isFunction:require("lodash-compat/lang/isFunction"),isPlainObject:require("lodash-compat/lang/isPlainObject"),isUndefined:require("lodash-compat/lang/isUndefined")},auth=require("./auth"),helpers=require("./helpers"),Model=require("./types/model"),Operation=require("./types/operation"),OperationGroup=require("./types/operationGroup"),Resolver=require("./resolver"),SwaggerHttp=require("./http"),SwaggerSpecConverter=require("./spec-converter"),Q=require("q"),reservedClientTags=["apis","authorizationScheme","authorizations","basePath","build","buildFrom1_1Spec","buildFrom1_2Spec","buildFromSpec","clientAuthorizations","convertInfo","debug","defaultErrorCallback","defaultSuccessCallback","enableCookies","fail","failure","finish","help","host","idFromOp","info","initialize","isBuilt","isValid","modelPropertyMacro","models","modelsArray","options","parameterMacro","parseUri","progress","resourceCount","sampleModels","selfReflect","setConsolidatedModels","spec","supportedSubmitMethods","swaggerRequestHeaders","tagFromLabel","title","url","useJQuery","jqueryAjaxCache"],reservedApiTags=["apis","asCurl","description","externalDocs","help","label","name","operation","operations","operationsArray","path","tag"],supportedOperationMethods=["delete","get","head","options","patch","post","put"],SwaggerClient=module.exports=function(e,t){return this.authorizations=null,this.authorizationScheme=null,this.basePath=null,this.debug=!1,this.enableCookies=!1,this.info=null,this.isBuilt=!1,this.isValid=!1,this.modelsArray=[],this.resourceCount=0,this.url=null,this.useJQuery=!1,this.jqueryAjaxCache=!1,this.swaggerObject={},this.deferredClient=void 0,this.clientAuthorizations=new auth.SwaggerAuthorizations,"undefined"!=typeof e?this.initialize(e,t):this};SwaggerClient.prototype.initialize=function(e,t){return this.models={},this.sampleModels={},"string"==typeof e?this.url=e:_.isObject(e)&&(t=e,this.url=t.url),this.url&&-1===this.url.indexOf("http:")&&-1===this.url.indexOf("https:")&&"undefined"!=typeof window&&"undefined"!=typeof window.location&&(this.url=window.location.origin+this.url),t=t||{},this.clientAuthorizations.add(t.authorizations),this.swaggerRequestHeaders=t.swaggerRequestHeaders||"application/json;charset=utf-8,*/*",this.defaultSuccessCallback=t.defaultSuccessCallback||null,this.defaultErrorCallback=t.defaultErrorCallback||null,this.modelPropertyMacro=t.modelPropertyMacro||null,this.connectionAgent=t.connectionAgent||null,this.parameterMacro=t.parameterMacro||null,this.usePromise=t.usePromise||null,this.timeout=t.timeout||null,this.fetchSpecTimeout="undefined"!=typeof t.fetchSpecTimeout?t.fetchSpecTimeout:t.timeout||null,this.usePromise&&(this.deferredClient=Q.defer()),"function"==typeof t.success&&(this.success=t.success),t.useJQuery&&(this.useJQuery=t.useJQuery),t.jqueryAjaxCache&&(this.jqueryAjaxCache=t.jqueryAjaxCache),t.enableCookies&&(this.enableCookies=t.enableCookies),this.options=t||{},this.options.timeout=this.timeout,this.options.fetchSpecTimeout=this.fetchSpecTimeout,this.supportedSubmitMethods=t.supportedSubmitMethods||[],this.failure=t.failure||function(e){throw e},this.progress=t.progress||function(){},this.spec=_.cloneDeep(t.spec),t.scheme&&(this.scheme=t.scheme),this.usePromise||"function"==typeof t.success?(this.ready=!0,this.build()):void 0},SwaggerClient.prototype.build=function(e){if(this.isBuilt)return this;var t=this;this.spec?this.progress("fetching resource list; Please wait."):this.progress("fetching resource list: "+this.url+"; Please wait.");var i={useJQuery:this.useJQuery,jqueryAjaxCache:this.jqueryAjaxCache,connectionAgent:this.connectionAgent,enableCookies:this.enableCookies,url:this.url,method:"get",headers:{accept:this.swaggerRequestHeaders},on:{error:function(e){return t&&t.url&&"http"!==t.url.substring(0,4)?t.fail("Please specify the protocol for "+t.url):!e.errObj||"ECONNABORTED"!==e.errObj.code&&-1===e.errObj.message.indexOf("timeout")?0===e.status?t.fail("Can't read from server. It may not have the appropriate access-control-origin settings."):404===e.status?t.fail("Can't read swagger JSON from "+t.url):t.fail(e.status+" : "+e.statusText+" "+t.url):t.fail("Request timed out after "+t.fetchSpecTimeout+"ms")},response:function(e){var i=e.obj;if(!i)return t.fail("failed to parse JSON/YAML response");if(t.swaggerVersion=i.swaggerVersion,t.swaggerObject=i,i.swagger&&2===parseInt(i.swagger))t.swaggerVersion=i.swagger,(new Resolver).resolve(i,t.url,t.buildFromSpec,t),t.isValid=!0;else{var s=new SwaggerSpecConverter;t.oldSwaggerObject=t.swaggerObject,s.setDocumentationLocation(t.url),s.convert(i,t.clientAuthorizations,t.options,function(e){t.swaggerObject=e,(new Resolver).resolve(e,t.url,t.buildFromSpec,t),t.isValid=!0})}}}};if(this.fetchSpecTimeout&&(i.timeout=this.fetchSpecTimeout),this.spec&&"object"==typeof this.spec)t.swaggerObject=this.spec,setTimeout(function(){(new Resolver).resolve(t.spec,t.url,t.buildFromSpec,t)},10);else{if(this.clientAuthorizations.apply(i),e)return i;(new SwaggerHttp).execute(i,this.options)}return this.usePromise?this.deferredClient.promise:this},SwaggerClient.prototype.buildFromSpec=function(e){if(this.isBuilt)return this;this.apis={},this.apisArray=[],this.basePath=e.basePath||"",this.consumes=e.consumes,this.host=e.host||"",this.info=e.info||{},this.produces=e.produces,this.schemes=e.schemes||[],this.securityDefinitions=_.cloneDeep(e.securityDefinitions),this.security=e.security,this.title=e.title||"";var t,i,s,r,o={},n=this;if(e.externalDocs&&(this.externalDocs=e.externalDocs),this.authSchemes=this.securityDefinitions,this.securityDefinitions)for(t in this.securityDefinitions){var a=this.securityDefinitions[t];a.vendorExtensions={};for(var h in a)if(helpers.extractExtensions(h,a),"scopes"===h){var c=a[h];if("object"==typeof c){c.vendorExtensions={};for(var l in c)helpers.extractExtensions(l,c),0===l.indexOf("x-")&&delete c[l]}}}if(Array.isArray(e.tags))for(o={},i=0;i<e.tags.length;i++){var p=_.cloneDeep(e.tags[i]);o[p.name]=p;for(r in p){if("externalDocs"===r&&"object"==typeof p[r])for(var u in p[r])helpers.extractExtensions(u,p[r]);helpers.extractExtensions(r,p)}}if("string"==typeof this.url){if(s=this.parseUri(this.url),"undefined"==typeof this.scheme&&"undefined"==typeof this.schemes||0===this.schemes.length)"undefined"!=typeof s&&"undefined"!=typeof s.scheme&&(this.scheme=s.scheme),"undefined"!=typeof window&&"undefined"!=typeof window.location?this.scheme=window.location.protocol.replace(":",""):this.scheme=s.scheme||"http";else if("undefined"!=typeof window&&"undefined"!=typeof window.location&&0===window.location.protocol.indexOf("chrome-extension"))this.scheme=s.scheme;else if("undefined"==typeof this.scheme)if("undefined"!=typeof window&&"undefined"!=typeof window.location){var f=window.location.protocol.replace(":","");"https"===f&&-1===this.schemes.indexOf(f)?(helpers.log("Cannot call a http server from https inside a browser!"),this.scheme="http"):-1!==this.schemes.indexOf(f)?this.scheme=f:-1!==this.schemes.indexOf("https")?this.scheme="https":this.scheme="http"}else this.scheme=this.schemes[0]||s.scheme;"undefined"!=typeof this.host&&""!==this.host||(this.host=s.host,s.port&&(this.host=this.host+":"+s.port))}else"undefined"==typeof this.schemes||0===this.schemes.length?this.scheme="http":"undefined"==typeof this.scheme&&(this.scheme=this.schemes[0]);this.definitions=e.definitions;for(t in this.definitions){var d=new Model(t,this.definitions[t],this.models,this.modelPropertyMacro);d&&(this.models[t]=d)}n.apis.help=_.bind(n.help,n),_.forEach(e.paths,function(e,t){_.isPlainObject(e)&&_.forEach(supportedOperationMethods,function(i){var s=e[i];if(!_.isUndefined(s)){if(!_.isPlainObject(s))return void helpers.log("The '"+i+"' operation for '"+t+"' path is not an Operation Object");var a=s.tags;!_.isUndefined(a)&&_.isArray(a)&&0!==a.length||(a=s.tags=["default"]);var h=n.idFromOp(t,i,s),c=new Operation(n,s.scheme,h,i,t,s,n.definitions,n.models,n.clientAuthorizations);c.connectionAgent=n.connectionAgent,c.vendorExtensions={};for(r in s)helpers.extractExtensions(r,c,s[r]);if(c.externalDocs=s.externalDocs,c.externalDocs){c.externalDocs=_.cloneDeep(c.externalDocs),c.externalDocs.vendorExtensions={};for(r in c.externalDocs)helpers.extractExtensions(r,c.externalDocs)}_.forEach(a,function(e){var t=_.indexOf(reservedClientTags,e)>-1?"_"+e:e,i=_.indexOf(reservedApiTags,e)>-1?"_"+e:e,s=n[t];if(t!==e&&helpers.log("The '"+e+"' tag conflicts with a SwaggerClient function/property name. Use 'client."+t+"' or 'client.apis."+e+"' instead of 'client."+e+"'."),i!==e&&helpers.log("The '"+e+"' tag conflicts with a SwaggerClient operation function/property name. Use 'client.apis."+i+"' instead of 'client.apis."+e+"'."),_.indexOf(reservedApiTags,h)>-1&&(helpers.log("The '"+h+"' operationId conflicts with a SwaggerClient operation function/property name. Use 'client.apis."+i+"._"+h+"' instead of 'client.apis."+i+"."+h+"'."),h="_"+h,c.nickname=h),_.isUndefined(s)){s=n[t]=n.apis[i]={},s.operations={},s.label=i,s.apis={};var r=o[e];_.isUndefined(r)||(s.description=r.description,s.externalDocs=r.externalDocs,s.vendorExtensions=r.vendorExtensions),n[t].help=_.bind(n.help,s),n.apisArray.push(new OperationGroup(e,s.description,s.externalDocs,c))}h=n.makeUniqueOperationId(h,n.apis[i]),_.isFunction(s.help)||(s.help=_.bind(n.help,s)),n.apis[i][h]=s[h]=_.bind(c.execute,c),n.apis[i][h].help=s[h].help=_.bind(c.help,c),n.apis[i][h].asCurl=s[h].asCurl=_.bind(c.asCurl,c),s.apis[h]=s.operations[h]=c;var a=_.find(n.apisArray,function(t){return t.tag===e});a&&a.operationsArray.push(c)})}})});var g=[];return _.forEach(Object.keys(o),function(e){var t;for(t in n.apisArray){var i=n.apisArray[t];i&&e===i.name&&(g.push(i),n.apisArray[t]=null)}}),_.forEach(n.apisArray,function(e){e&&g.push(e)}),n.apisArray=g,_.forEach(e.definitions,function(e,t){e.id=t.toLowerCase(),e.name=t,n.modelsArray.push(e)}),this.isBuilt=!0,this.usePromise?(this.isValid=!0,this.isBuilt=!0,this.deferredClient.resolve(this),this.deferredClient.promise):(this.success&&this.success(),this)},SwaggerClient.prototype.makeUniqueOperationId=function(e,t){for(var i=0,s=e;;){var r=!1;if(_.forEach(t.operations,function(e){e.nickname===s&&(r=!0)}),!r)return s;s=e+"_"+i,i++}return e},SwaggerClient.prototype.parseUri=function(e){var t=/^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,i=t.exec(e);return{scheme:i[4]?i[4].replace(":",""):void 0,host:i[11],port:i[12],path:i[15]}},SwaggerClient.prototype.help=function(e){var t="";return this instanceof SwaggerClient?_.forEach(this.apis,function(e,i){_.isPlainObject(e)&&(t+="operations for the '"+i+"' tag\n",_.forEach(e.operations,function(e,i){t+=" * "+i+": "+e.summary+"\n"}))}):(this instanceof OperationGroup||_.isPlainObject(this))&&(t+="operations for the '"+this.label+"' tag\n",_.forEach(this.apis,function(e,i){t+=" * "+i+": "+e.summary+"\n"})),e?t:(helpers.log(t),t)},SwaggerClient.prototype.tagFromLabel=function(e){return e},SwaggerClient.prototype.idFromOp=function(e,t,i){i&&i.operationId||(i=i||{},i.operationId=t+"_"+e);var s=i.operationId.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g,"_")||e.substring(1)+"_"+t;return s=s.replace(/((_){2,})/g,"_"),s=s.replace(/^(_)*/g,""),s=s.replace(/([_])*$/g,"")},SwaggerClient.prototype.setHost=function(e){this.host=e,this.apis&&_.forEach(this.apis,function(t){t.operations&&_.forEach(t.operations,function(t){t.host=e})})},SwaggerClient.prototype.setBasePath=function(e){this.basePath=e,this.apis&&_.forEach(this.apis,function(t){t.operations&&_.forEach(t.operations,function(t){t.basePath=e})})},SwaggerClient.prototype.setSchemes=function(e){this.schemes=e,e&&e.length>0&&this.apis&&_.forEach(this.apis,function(t){t.operations&&_.forEach(t.operations,function(t){t.scheme=e[0]})})},SwaggerClient.prototype.fail=function(e){return this.usePromise?(this.deferredClient.reject(e),this.deferredClient.promise):void(this.failure?this.failure(e):this.failure(e))};
|
|
14
|
+
"use strict";var _={bind:require("lodash-compat/function/bind"),cloneDeep:require("lodash-compat/lang/cloneDeep"),find:require("lodash-compat/collection/find"),forEach:require("lodash-compat/collection/forEach"),indexOf:require("lodash-compat/array/indexOf"),isArray:require("lodash-compat/lang/isArray"),isObject:require("lodash-compat/lang/isObject"),isFunction:require("lodash-compat/lang/isFunction"),isPlainObject:require("lodash-compat/lang/isPlainObject"),isUndefined:require("lodash-compat/lang/isUndefined")},auth=require("./auth"),helpers=require("./helpers"),Model=require("./types/model"),Operation=require("./types/operation"),OperationGroup=require("./types/operationGroup"),Resolver=require("./resolver"),SwaggerHttp=require("./http"),SwaggerSpecConverter=require("./spec-converter"),Q=require("q"),reservedClientTags=["apis","authorizationScheme","authorizations","basePath","build","buildFrom1_1Spec","buildFrom1_2Spec","buildFromSpec","clientAuthorizations","convertInfo","debug","defaultErrorCallback","defaultSuccessCallback","enableCookies","fail","failure","finish","help","host","idFromOp","info","initialize","isBuilt","isValid","modelPropertyMacro","models","modelsArray","options","parameterMacro","parseUri","progress","resourceCount","sampleModels","selfReflect","setConsolidatedModels","spec","supportedSubmitMethods","swaggerRequestHeaders","tagFromLabel","title","url","useJQuery","jqueryAjaxCache"],reservedApiTags=["apis","asCurl","description","externalDocs","help","label","name","operation","operations","operationsArray","path","tag"],supportedOperationMethods=["delete","get","head","options","patch","post","put"],SwaggerClient=module.exports=function(e,t){return this.authorizations=null,this.authorizationScheme=null,this.basePath=null,this.debug=!1,this.enableCookies=!1,this.info=null,this.isBuilt=!1,this.isValid=!1,this.modelsArray=[],this.resourceCount=0,this.url=null,this.useJQuery=!1,this.jqueryAjaxCache=!1,this.swaggerObject={},this.deferredClient=void 0,this.clientAuthorizations=new auth.SwaggerAuthorizations,"undefined"!=typeof e?this.initialize(e,t):this};SwaggerClient.prototype.initialize=function(e,t){return this.models={},this.sampleModels={},"string"==typeof e?this.url=e:_.isObject(e)&&(t=e,this.url=t.url),this.url&&-1===this.url.indexOf("http:")&&-1===this.url.indexOf("https:")&&"undefined"!=typeof window&&window&&window.location&&(this.url=window.location.origin+this.url),t=t||{},this.clientAuthorizations.add(t.authorizations),this.swaggerRequestHeaders=t.swaggerRequestHeaders||"application/json;charset=utf-8,*/*",this.defaultSuccessCallback=t.defaultSuccessCallback||null,this.defaultErrorCallback=t.defaultErrorCallback||null,this.modelPropertyMacro=t.modelPropertyMacro||null,this.parameterMacro=t.parameterMacro||null,this.usePromise=t.usePromise||null,this.timeout=t.timeout||null,this.fetchSpecTimeout="undefined"!=typeof t.fetchSpecTimeout?t.fetchSpecTimeout:t.timeout||null,this.usePromise&&(this.deferredClient=Q.defer()),"function"==typeof t.success&&(this.success=t.success),t.useJQuery&&(this.useJQuery=t.useJQuery),t.jqueryAjaxCache&&(this.jqueryAjaxCache=t.jqueryAjaxCache),t.enableCookies&&(this.enableCookies=t.enableCookies),this.options=t||{},this.options.timeout=this.timeout,this.options.fetchSpecTimeout=this.fetchSpecTimeout,this.supportedSubmitMethods=t.supportedSubmitMethods||[],this.failure=t.failure||function(e){throw e},this.progress=t.progress||function(){},this.spec=_.cloneDeep(t.spec),t.scheme&&(this.scheme=t.scheme),this.usePromise||"function"==typeof t.success?(this.ready=!0,this.build()):void 0},SwaggerClient.prototype.build=function(e){if(this.isBuilt)return this;var t=this;this.spec?this.progress("fetching resource list; Please wait."):this.progress("fetching resource list: "+this.url+"; Please wait.");var i={useJQuery:this.useJQuery,jqueryAjaxCache:this.jqueryAjaxCache,url:this.url,method:"get",headers:{accept:this.swaggerRequestHeaders},on:{error:function(e){return"http"!==t.url.substring(0,4)?t.fail("Please specify the protocol for "+t.url):!e.errObj||"ECONNABORTED"!==e.errObj.code&&-1===e.errObj.message.indexOf("timeout")?0===e.status?t.fail("Can't read from server. It may not have the appropriate access-control-origin settings."):404===e.status?t.fail("Can't read swagger JSON from "+t.url):t.fail(e.status+" : "+e.statusText+" "+t.url):t.fail("Request timed out after "+t.fetchSpecTimeout+"ms")},response:function(e){var i=e.obj;if(!i)return t.fail("failed to parse JSON/YAML response");if(t.swaggerVersion=i.swaggerVersion,t.swaggerObject=i,i.swagger&&2===parseInt(i.swagger))t.swaggerVersion=i.swagger,(new Resolver).resolve(i,t.url,t.buildFromSpec,t),t.isValid=!0;else{var s=new SwaggerSpecConverter;t.oldSwaggerObject=t.swaggerObject,s.setDocumentationLocation(t.url),s.convert(i,t.clientAuthorizations,t.options,function(e){t.swaggerObject=e,(new Resolver).resolve(e,t.url,t.buildFromSpec,t),t.isValid=!0})}}}};if(this.fetchSpecTimeout&&(i.timeout=this.fetchSpecTimeout),this.spec)t.swaggerObject=this.spec,setTimeout(function(){(new Resolver).resolve(t.spec,t.url,t.buildFromSpec,t)},10);else{if(this.clientAuthorizations.apply(i),e)return i;(new SwaggerHttp).execute(i,this.options)}return this.usePromise?this.deferredClient.promise:this},SwaggerClient.prototype.buildFromSpec=function(e){if(this.isBuilt)return this;this.apis={},this.apisArray=[],this.basePath=e.basePath||"",this.consumes=e.consumes,this.host=e.host||"",this.info=e.info||{},this.produces=e.produces,this.schemes=e.schemes||[],this.securityDefinitions=e.securityDefinitions,this.security=e.security,this.title=e.title||"",e.externalDocs&&(this.externalDocs=e.externalDocs),this.authSchemes=e.securityDefinitions;var t,i={};if(Array.isArray(e.tags))for(i={},t=0;t<e.tags.length;t++){var s=e.tags[t];i[s.name]=s}var r;if("string"==typeof this.url){if(r=this.parseUri(this.url),"undefined"==typeof this.scheme&&"undefined"==typeof this.schemes||0===this.schemes.length)"undefined"!=typeof window?this.scheme=window.location.protocol.replace(":",""):this.scheme=r.scheme||"http";else if("undefined"==typeof this.scheme)if("undefined"!=typeof window){var o=window.location.protocol.replace(":","");"https"===o&&-1===this.schemes.indexOf(o)?(helpers.log("Cannot call a http server from https inside a browser!"),this.scheme="http"):-1!==this.schemes.indexOf(o)?this.scheme=o:-1!==this.schemes.indexOf("https")?this.scheme="https":this.scheme="http"}else this.scheme=this.schemes[0]||r.scheme;"undefined"!=typeof this.host&&""!==this.host||(this.host=r.host,r.port&&(this.host=this.host+":"+r.port))}else"undefined"==typeof this.schemes||0===this.schemes.length?this.scheme="http":"undefined"==typeof this.scheme&&(this.scheme=this.schemes[0]);this.definitions=e.definitions;var a;for(a in this.definitions){var n=new Model(a,this.definitions[a],this.models,this.modelPropertyMacro);n&&(this.models[a]=n)}var h=this;h.apis.help=_.bind(h.help,h),_.forEach(e.paths,function(e,t){_.isPlainObject(e)&&_.forEach(supportedOperationMethods,function(s){var r=e[s];if(!_.isUndefined(r)){if(!_.isPlainObject(r))return void helpers.log("The '"+s+"' operation for '"+t+"' path is not an Operation Object");var o=r.tags;!_.isUndefined(o)&&_.isArray(o)&&0!==o.length||(o=r.tags=["default"]);var a=h.idFromOp(t,s,r),n=new Operation(h,r.scheme,a,s,t,r,h.definitions,h.models,h.clientAuthorizations);_.forEach(o,function(e){var t=_.indexOf(reservedClientTags,e)>-1?"_"+e:e,s=_.indexOf(reservedApiTags,e)>-1?"_"+e:e,r=h[t];if(t!==e&&helpers.log("The '"+e+"' tag conflicts with a SwaggerClient function/property name. Use 'client."+t+"' or 'client.apis."+e+"' instead of 'client."+e+"'."),s!==e&&helpers.log("The '"+e+"' tag conflicts with a SwaggerClient operation function/property name. Use 'client.apis."+s+"' instead of 'client.apis."+e+"'."),_.indexOf(reservedApiTags,a)>-1&&(helpers.log("The '"+a+"' operationId conflicts with a SwaggerClient operation function/property name. Use 'client.apis."+s+"._"+a+"' instead of 'client.apis."+s+"."+a+"'."),a="_"+a,n.nickname=a),_.isUndefined(r)){r=h[t]=h.apis[s]={},r.operations={},r.label=s,r.apis={};var o=i[e];_.isUndefined(o)||(r.description=o.description,r.externalDocs=o.externalDocs),h[t].help=_.bind(h.help,r),h.apisArray.push(new OperationGroup(e,r.description,r.externalDocs,n))}a=h.makeUniqueOperationId(a,h.apis[s]),_.isFunction(r.help)||(r.help=_.bind(h.help,r)),h.apis[s][a]=r[a]=_.bind(n.execute,n),h.apis[s][a].help=r[a].help=_.bind(n.help,n),h.apis[s][a].asCurl=r[a].asCurl=_.bind(n.asCurl,n),r.apis[a]=r.operations[a]=n;var l=_.find(h.apisArray,function(t){return t.tag===e});l&&l.operationsArray.push(n)})}})});var l=[];return _.forEach(Object.keys(i),function(e){var t;for(t in h.apisArray){var i=h.apisArray[t];i&&e===i.name&&(l.push(i),h.apisArray[t]=null)}}),_.forEach(h.apisArray,function(e){e&&l.push(e)}),h.apisArray=l,_.forEach(e.definitions,function(e,t){e.id=t.toLowerCase(),e.name=t,h.modelsArray.push(e)}),this.isBuilt=!0,this.usePromise?(this.isValid=!0,this.isBuilt=!0,this.deferredClient.resolve(this),this.deferredClient.promise):(this.success&&this.success(),this)},SwaggerClient.prototype.makeUniqueOperationId=function(e,t){for(var i=0,s=e;;){var r=!1;if(_.forEach(t.operations,function(e){e.nickname===s&&(r=!0)}),!r)return s;s=e+"_"+i,i++}return e},SwaggerClient.prototype.parseUri=function(e){var t=/^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,i=t.exec(e);return{scheme:i[4]?i[4].replace(":",""):void 0,host:i[11],port:i[12],path:i[15]}},SwaggerClient.prototype.help=function(e){var t="";return this instanceof SwaggerClient?_.forEach(this.apis,function(e,i){_.isPlainObject(e)&&(t+="operations for the '"+i+"' tag\n",_.forEach(e.operations,function(e,i){t+=" * "+i+": "+e.summary+"\n"}))}):(this instanceof OperationGroup||_.isPlainObject(this))&&(t+="operations for the '"+this.label+"' tag\n",_.forEach(this.apis,function(e,i){t+=" * "+i+": "+e.summary+"\n"})),e?t:(helpers.log(t),t)},SwaggerClient.prototype.tagFromLabel=function(e){return e},SwaggerClient.prototype.idFromOp=function(e,t,i){i&&i.operationId||(i=i||{},i.operationId=t+"_"+e);var s=i.operationId.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g,"_")||e.substring(1)+"_"+t;return s=s.replace(/((_){2,})/g,"_"),s=s.replace(/^(_)*/g,""),s=s.replace(/([_])*$/g,"")},SwaggerClient.prototype.setHost=function(e){this.host=e,this.apis&&_.forEach(this.apis,function(t){t.operations&&_.forEach(t.operations,function(t){t.host=e})})},SwaggerClient.prototype.setBasePath=function(e){this.basePath=e,this.apis&&_.forEach(this.apis,function(t){t.operations&&_.forEach(t.operations,function(t){t.basePath=e})})},SwaggerClient.prototype.setSchemes=function(e){this.schemes=e,e&&e.length>0&&this.apis&&_.forEach(this.apis,function(t){t.operations&&_.forEach(t.operations,function(t){t.scheme=e[0]})})},SwaggerClient.prototype.fail=function(e){return this.usePromise?(this.deferredClient.reject(e),this.deferredClient.promise):void(this.failure?this.failure(e):this.failure(e))};
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
},{"./auth":2,"./helpers":4,"./http":5,"./resolver":6,"./spec-converter":8,"./types/model":9,"./types/operation":10,"./types/operationGroup":11,"lodash-compat/array/indexOf":49,"lodash-compat/collection/find":53,"lodash-compat/collection/forEach":54,"lodash-compat/function/bind":58,"lodash-compat/lang/cloneDeep":138,"lodash-compat/lang/isArray":140,"lodash-compat/lang/isFunction":142,"lodash-compat/lang/isObject":144,"lodash-compat/lang/isPlainObject":145,"lodash-compat/lang/isUndefined":148,"q":157}],4:[function(require,module,exports){
|
|
18
18
|
(function (process){
|
|
19
|
-
"use strict";var _={isPlainObject:require("lodash-compat/lang/isPlainObject"),indexOf:require("lodash-compat/array/indexOf")};module.exports.__bind=function(e,
|
|
19
|
+
"use strict";var _={isPlainObject:require("lodash-compat/lang/isPlainObject"),indexOf:require("lodash-compat/array/indexOf")};module.exports.__bind=function(e,o){return function(){return e.apply(o,arguments)}};var log=module.exports.log=function(){console&&"test"!==process.env.NODE_ENV&&console.log(Array.prototype.slice.call(arguments)[0])};module.exports.fail=function(e){log(e)};var optionHtml=module.exports.optionHtml=function(e,o){return'<tr><td class="optionName">'+e+":</td><td>"+o+"</td></tr>"},resolveSchema=module.exports.resolveSchema=function(e){return _.isPlainObject(e.schema)&&(e=resolveSchema(e.schema)),e},simpleRef=module.exports.simpleRef=function(e){return"undefined"==typeof e?null:0===e.indexOf("#/definitions/")?e.substring("#/definitions/".length):e};
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
}).call(this,require('_process'))
|
|
23
23
|
},{"_process":12,"lodash-compat/array/indexOf":49,"lodash-compat/lang/isPlainObject":145}],5:[function(require,module,exports){
|
|
24
24
|
(function (Buffer){
|
|
25
|
-
"use strict";var helpers=require("./helpers"),request=require("superagent"),jsyaml=require("js-yaml"),_={isObject:require("lodash-compat/lang/isObject"),keys:require("lodash-compat/object/keys")},JQueryHttpClient=function(){this.type="JQueryHttpClient"},SuperagentHttpClient=function(){this.type="SuperagentHttpClient"},SwaggerHttp=module.exports=function(){};SwaggerHttp.prototype.execute=function(e,t){var r;r=t&&t.client?t.client:new SuperagentHttpClient(t),r.opts=t||{}
|
|
25
|
+
"use strict";var helpers=require("./helpers"),request=require("superagent"),jsyaml=require("js-yaml"),_={isObject:require("lodash-compat/lang/isObject"),keys:require("lodash-compat/object/keys")},JQueryHttpClient=function(){this.type="JQueryHttpClient"},SuperagentHttpClient=function(){this.type="SuperagentHttpClient"},SwaggerHttp=module.exports=function(){};SwaggerHttp.prototype.execute=function(e,t){var r;r=t&&t.client?t.client:new SuperagentHttpClient(t),r.opts=t||{};var o=!1;if("undefined"!=typeof window&&"undefined"!=typeof window.jQuery&&(o=!0),"options"===e.method.toLowerCase()&&"SuperagentHttpClient"===r.type&&(log("forcing jQuery as OPTIONS are not supported by SuperAgent"),e.useJQuery=!0),this.isInternetExplorer()&&(e.useJQuery===!1||!o))throw new Error("Unsupported configuration! JQuery is required but not available");(e&&e.useJQuery===!0||this.isInternetExplorer()&&o)&&(r=new JQueryHttpClient(t));var n=e.on.response,s=e.on.error,a=function(e){return t&&t.requestInterceptor&&(e=t.requestInterceptor.apply(e)),e},i=function(e){return t&&t.responseInterceptor&&(e=t.responseInterceptor.apply(e)),n(e)},u=function(e){t&&t.responseInterceptor&&(e=t.responseInterceptor.apply(e)),s(e)};return e.on.error=function(e){u(e)},e.on.response=function(e){i(e)},_.isObject(e)&&_.isObject(e.body)&&e.body.type&&"formData"===e.body.type&&t.useJQuery&&(e.contentType=!1,e.processData=!1,delete e.headers["Content-Type"]),e=a(e)||e,e.beforeSend?e.beforeSend(function(t){r.execute(t||e)}):r.execute(e),e.deferred?e.deferred.promise:e},SwaggerHttp.prototype.isInternetExplorer=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent){var t=navigator.userAgent.toLowerCase();if(-1!==t.indexOf("msie")){var r=parseInt(t.split("msie")[1]);8>=r&&(e=!0)}}return e},JQueryHttpClient.prototype.execute=function(e){var t=this.jQuery||"undefined"!=typeof window&&window.jQuery,r=e.on,o=e;if("undefined"==typeof t||t===!1)throw new Error("Unsupported configuration! JQuery is required but not available");return e.type=e.method,e.cache=e.jqueryAjaxCache,e.data=e.body,delete e.jqueryAjaxCache,delete e.useJQuery,delete e.body,e.complete=function(e){for(var t={},n=e.getAllResponseHeaders().split("\n"),s=0;s<n.length;s++){var a=n[s].trim();if(0!==a.length){var i=a.indexOf(":");if(-1!==i){var u=a.substring(0,i).trim(),p=a.substring(i+1).trim();t[u]=p}else t[a]=null}}var d={url:o.url,method:o.method,status:e.status,statusText:e.statusText,data:e.responseText,headers:t};try{var f=e.responseJSON||jsyaml.safeLoad(e.responseText);d.obj="string"==typeof f?{}:f}catch(l){helpers.log("unable to parse JSON/YAML content")}if(d.obj=d.obj||null,e.status>=200&&e.status<300)r.response(d);else{if(!(0===e.status||e.status>=400&&e.status<599))return r.response(d);r.error(d)}},t.support.cors=!0,t.ajax(e)},SuperagentHttpClient.prototype.execute=function(e){var t=e.method.toLowerCase(),r=e.timeout;"delete"===t&&(t="del");var o=e.headers||{},n=request[t](e.url);r&&n.timeout(r),e.enableCookies&&n.withCredentials();var s=e.headers.Accept;if(this.binaryRequest(s)&&n.on("request",function(){this.xhr&&(this.xhr.responseType="blob")}),e.body)if(_.isObject(e.body)){var a=e.headers["Content-Type"]||"";if(0===a.indexOf("multipart/form-data"))if(delete o["Content-Type"],"[object FormData]"==={}.toString.apply(e.body))for(var i=e.body.keys(),u=[];;){var p=i.next();if(p.done)break;var d=p.value;if(-1===u.indexOf(d)){u.push(d);var f=e.body.getAll(d);if("[object File]"==={}.toString.apply(f))n.attach(d,f);else if(Array.isArray(f))for(var l in f)n.field(d,f[l]);else n.field(d,f)}}else{var y,f,p;for(y in e.body)if(f=e.body[y],Array.isArray(f))for(p in f)n.field(y,p);else n.field(y,f)}else _.isObject(e.body)&&(e.body=JSON.stringify(e.body),n.send(e.body))}else n.send(e.body);var c;for(c in o)n.set(c,o[c]);"function"==typeof n.buffer&&n.buffer(),n.end(function(t,r){r=r||{status:0,headers:{error:"no response from server"}};var o,n={url:e.url,method:e.method,headers:r.headers};if(!t&&r.error&&(t=r.error),t&&e.on&&e.on.error){if(n.errObj=t,n.status=r?r.status:500,n.statusText=r?r.text:t.message,r.headers&&r.headers["content-type"]&&r.headers["content-type"].indexOf("application/json")>=0)try{n.obj=JSON.parse(n.statusText)}catch(s){n.obj=null}o=e.on.error}else if(r&&e.on&&e.on.response){var a;if(r.body&&_.keys(r.body).length>0)a=r.body;else try{a=jsyaml.safeLoad(r.text),a="string"==typeof a?null:a}catch(s){helpers.log("cannot parse JSON/YAML content")}"function"==typeof Buffer&&Buffer.isBuffer(a)?n.data=a:n.obj="object"==typeof a?a:null,n.status=r.status,n.statusText=r.text,o=e.on.response}r.xhr&&r.xhr.response?n.data=r.xhr.response:n.data||(n.data=n.statusText),o&&o(n)})},SuperagentHttpClient.prototype.binaryRequest=function(e){return e?/^image/i.test(e)||/^application\/pdf/.test(e):!1};
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
}).call(this,require("buffer").Buffer)
|
|
29
29
|
},{"./helpers":4,"buffer":14,"js-yaml":19,"lodash-compat/lang/isObject":144,"lodash-compat/object/keys":149,"superagent":158}],6:[function(require,module,exports){
|
|
30
|
-
"use strict";function splitUrl(e){var i={},t=/[a-z]+:\/\//i.exec(e);t&&(i.proto=t[0].slice(0,-3),e=e.slice(i.proto.length+1)),"//"===e.slice(0,2)&&(i.domain=e.slice(2).split("/")[0],e=e.slice(2+i.domain.length));var r=e.split("#");return r[0].length&&(i.path=r[0]),r.length>1&&(i.fragment=r.slice(1).join("#")),i}function unsplitUrl(e){var i=e.path;return void 0===i&&(i=""),void 0!==e.fragment&&(i+="#"+e.fragment),void 0!==e.domain&&("/"===i.slice(0,1)&&(i=i.slice(1)),i="//"+e.domain+"/"+i,void 0!==e.proto&&(i=e.proto+":"+i)),i}function joinUrl(e,i){var t=splitUrl(i);if(void 0!==t.domain)return i;var r=splitUrl(e);if(void 0===t.path)r.fragment=t.fragment;else if("/"===t.path.slice(0,1))r.path=t.path,r.fragment=t.fragment;else{var o=void 0===r.path?[]:r.path.split("/"),s=t.path.split("/");for(o.length&&o.pop();".."===s[0]||"."===s[0];)".."===s[0]&&o.pop(),s.shift();r.path=o.concat(s).join("/"),r.fragment=t.fragment}return unsplitUrl(r)}var SwaggerHttp=require("./http"),_={isObject:require("lodash-compat/lang/isObject"),cloneDeep:require("lodash-compat/lang/cloneDeep"),isArray:require("lodash-compat/lang/isArray"),isString:require("lodash-compat/lang/isString")},Resolver=module.exports=function(){this.failedUrls=[],this.resolverCache={},this.pendingUrls={}};Resolver.prototype.processAllOf=function(e,i,t,r,o,s){var n,l,f;t["x-resolved-from"]=["#/definitions/"+i];var a=t.allOf;for(a.sort(function(e,i){return e.$ref&&i.$ref?0:e.$ref?-1:1}),n=0;n<a.length;n++)f=a[n],l="/definitions/"+i+"/allOf",this.resolveInline(e,s,f,r,o,l)},Resolver.prototype.resolve=function(e,i,t,r){this.spec=e;var o,s,n=i,l=t,f=r,a={};"function"==typeof i&&(n=null,l=i,f=t);var p,h=n;this.scope=f||this,this.iteration=this.iteration||0,this.scope.options&&this.scope.options.requestInterceptor&&(a.requestInterceptor=this.scope.options.requestInterceptor),this.scope.options&&this.scope.options.responseInterceptor&&(a.responseInterceptor=this.scope.options.responseInterceptor);var c,d,v,u,m,g,y,O=0,b={},x={},j=[];e.definitions=e.definitions||{};for(c in e.definitions){var A=e.definitions[c];if(A.$ref)this.resolveInline(n,e,A,j,x,A);else{for(u in A.properties)v=A.properties[u],_.isArray(v.allOf)?this.processAllOf(n,c,v,j,x,e):this.resolveTo(n,v,j,"/definitions");A.allOf&&this.processAllOf(n,c,A,j,x,e)}}e.parameters=e.parameters||{};for(c in e.parameters){if(m=e.parameters[c],"body"===m["in"]&&m.schema)if(_.isArray(m.schema.allOf)){p="inline_model";var k=p;for(g=!1,y=0;!g;){if("undefined"==typeof e.definitions[k]){g=!0;break}k=p+"_"+y,y++}e.definitions[k]={allOf:m.schema.allOf},delete m.schema.allOf,m.schema.$ref="#/definitions/"+k,this.processAllOf(n,k,e.definitions[k],j,x,e)}else this.resolveTo(n,m.schema,j,o);m.$ref&&this.resolveInline(n,e,m,j,x,m.$ref)}for(c in e.paths){var $,R,I;if(d=e.paths[c],"object"==typeof d){for($ in d)if("$ref"===$)o="/paths"+c,this.resolveInline(n,e,d,j,x,o);else{R=d[$];var q=d.parameters||[],U=R.parameters||[];q.forEach(function(e){U.unshift(e)}),"parameters"!==$&&_.isObject(R)&&(R.parameters=R.parameters||U);for(s in U){if(m=U[s],o="/paths"+c+"/"+$+"/parameters","body"===m["in"]&&m.schema)if(_.isArray(m.schema.allOf)){for(p="inline_model",c=p,g=!1,y=0;!g;){if("undefined"==typeof e.definitions[c]){g=!0;break}c=p+"_"+y,y++}e.definitions[c]={allOf:m.schema.allOf},delete m.schema.allOf,m.schema.$ref="#/definitions/"+c,this.processAllOf(n,c,e.definitions[c],j,x,e)}else this.resolveTo(n,m.schema,j,o);m.$ref&&this.resolveInline(n,e,m,j,x,m.$ref)}for(I in R.responses){var w=R.responses[I];if(o="/paths"+c+"/"+$+"/responses/"+I,_.isObject(w)&&(w.$ref&&this.resolveInline(n,e,w,j,x,o),w.schema)){var T=w;if(_.isArray(T.schema.allOf)){for(p="inline_model",c=p,g=!1,y=0;!g;){if("undefined"==typeof e.definitions[c]){g=!0;break}c=p+"_"+y,y++}e.definitions[c]={allOf:T.schema.allOf},delete T.schema.allOf,delete T.schema.type,T.schema.$ref="#/definitions/"+c,this.processAllOf(n,c,e.definitions[c],j,x,e)}else"array"===T.schema.type?T.schema.items&&T.schema.items.$ref&&this.resolveInline(n,e,T.schema.items,j,x,o):this.resolveTo(n,w.schema,j,o)}}}d.parameters=[]}}var S,D=0,C=[],P=j;for(s=0;s<P.length;s++){var z=P[s];if(n===z.root){if("ref"===z.resolveAs){var H,N=((z.root||"")+"/"+z.key).split("/"),E=[],J="";if(z.key.indexOf("../")>=0){for(var Q=0;Q<N.length;Q++)".."===N[Q]?E=E.slice(0,E.length-1):E.push(N[Q]);for(H=0;H<E.length;H++)H>0&&(J+="/"),J+=E[H];z.root=J,C.push(z)}else if(S=z.key.split("#"),2===S.length){0!==S[0].indexOf("http:")&&0!==S[0].indexOf("https:")||(z.root=S[0]),o=S[1].split("/");var B,F=e;for(H=0;H<o.length;H++){var G=o[H];if(""!==G){if(F=F[G],"undefined"==typeof F){B=null;break}B=F}}null===B&&C.push(z)}}else if("inline"===z.resolveAs){if(z.key&&-1===z.key.indexOf("#")&&"/"!==z.key.charAt(0)){for(S=z.root.split("/"),o="",s=0;s<S.length-1;s++)o+=S[s]+"/";o+=z.key,z.root=o,z.location=""}C.push(z)}}else C.push(z)}D=C.length;for(var K={},L=0;L<C.length;L++)!function(e,i,t,r,o){if(e.root&&e.root!==n)if(-1===t.failedUrls.indexOf(e.root)){var s={useJQuery:!1,url:e.root,method:"get",headers:{accept:t.scope.swaggerRequestHeaders||"application/json"},on:{error:function(o){O+=1,console.log("failed url: "+s.url),t.failedUrls.push(s.url),r&&delete r[e.root],x[e.key]={root:e.root,location:e.location},O===D&&t.finish(i,h,j,b,x,l)},response:function(o){var s=o.obj;r&&delete r[e.root],t.resolverCache&&(t.resolverCache[e.root]=s),t.resolveItem(s,e.root,j,b,x,e),O+=1,O===D&&t.finish(i,h,j,b,x,l)}}};f&&f.fetchSpecTimeout&&(s.timeout=f.fetchSpecTimeout),f&&f.clientAuthorizations&&f.clientAuthorizations.apply(s),function p(){setTimeout(function(){if(r[s.url])p();else{var e=t.resolverCache[s.url];_.isObject(e)?s.on.response({obj:e}):(r[s.url]=!0,(new SwaggerHttp).execute(s,a))}},0)}()}else O+=1,x[e.key]={root:e.root,location:e.location},O===D&&t.finish(i,h,j,b,x,l);else t.resolveItem(i,h,j,b,x,e),O+=1,O===D&&t.finish(i,n,j,b,x,l,!0)}(C[L],e,this,K,L);0===Object.keys(C).length&&this.finish(e,h,j,b,x,l)},Resolver.prototype.resolveItem=function(e,i,t,r,o,s){var n=s.location,l=e,f=n.split("/");if(""!==n)for(var a=0;a<f.length;a++){var p=f[a];if(-1!==p.indexOf("~1")&&(p=f[a].replace(/~0/g,"~").replace(/~1/g,"/"),"/"!==p.charAt(0)&&(p="/"+p)),"undefined"==typeof l||null===l)break;if(""===p&&a===f.length-1&&f.length>1){l=null;break}p.length>0&&(l=l[p])}var h=s.key;f=s.key.split("/");var c=f[f.length-1];c.indexOf("#")>=0&&(c=c.split("#")[1]),null!==l&&"undefined"!=typeof l?r[h]={name:c,obj:l,key:s.key,root:s.root}:o[h]={root:s.root,location:s.location}},Resolver.prototype.finish=function(e,i,t,r,o,s,n){var l,f;for(l in t){var a=t[l],p=a.key,h=r[p];if(h)if(e.definitions=e.definitions||{},"ref"===a.resolveAs){if(n!==!0)for(p in h.obj)f=this.retainRoot(p,h.obj[p],a.root),h.obj[p]=f;e.definitions[h.name]=h.obj,a.obj.$ref="#/definitions/"+h.name}else if("inline"===a.resolveAs){var c=a.obj;c["x-resolved-from"]=[a.key],delete c.$ref;for(p in h.obj)f=h.obj[p],n!==!0&&(f=this.retainRoot(p,h.obj[p],a.root)),c[p]=f}}var d=this.countUnresolvedRefs(e);0===d||this.iteration>5?(this.resolveAllOf(e.definitions),this.resolverCache=null,s.call(this.scope,e,o)):(this.iteration+=1,this.resolve(e,i,s,this.scope))},Resolver.prototype.countUnresolvedRefs=function(e){var i,t=this.getRefs(e),r=[],o=[];for(i in t)0===i.indexOf("#")?r.push(i.substring(1)):o.push(i);for(i=0;i<r.length;i++)for(var s=r[i],n=s.split("/"),l=e,f=0;f<n.length;f++){var a=n[f];if(""!==a&&(l=l[a],"undefined"==typeof l)){o.push(s);break}}return o.length},Resolver.prototype.getRefs=function(e,i){i=i||e;var t={};for(var r in i)if(i.hasOwnProperty(r)){var o=i[r];if("$ref"===r&&"string"==typeof o)t[o]=null;else if(_.isObject(o)){var s=this.getRefs(o);for(var n in s)t[n]=null}}return t},Resolver.prototype.retainRoot=function(e,i,t){if(_.isObject(i))for(var r in i){var o=i[r];"$ref"===r&&"string"==typeof o?i[r]=joinUrl(t,o):_.isObject(o)&&this.retainRoot(r,o,t)}else _.isString(i)&&"$ref"===e&&(i=joinUrl(t,i));return i},Resolver.prototype.resolveInline=function(e,i,t,r,o,s){var n,l,f,a,p=t.$ref,h=t.$ref,c=!1;if(e=e||"",h){if(0===h.indexOf("../")){for(l=h.split("../"),f=e.split("/"),h="",n=0;n<l.length;n++)""===l[n]?f=f.slice(0,f.length-1):h+=l[n];for(e="",n=0;n<f.length-1;n++)n>0&&(e+="/"),e+=f[n];c=!0}if(h.indexOf("#")>=0)if(0===h.indexOf("/"))a=h.split("#"),l=e.split("//"),f=l[1].split("/"),e=l[0]+"//"+f[0]+a[0],s=a[1];else{if(a=h.split("#"),""!==a[0]){if(f=e.split("/"),f=f.slice(0,f.length-1),!c){e="";for(var d=0;d<f.length;d++)d>0&&(e+="/"),e+=f[d]}e+="/"+h.split("#")[0]}s=a[1]}if(0===h.indexOf("http:")||0===h.indexOf("https:"))h.indexOf("#")>=0?(e=h.split("#")[0],s=h.split("#")[1]):(e=h,s=""),r.push({obj:t,resolveAs:"inline",root:e,key:p,location:s});else if(0===h.indexOf("#"))s=h.split("#")[1],r.push({obj:t,resolveAs:"inline",root:e,key:p,location:s});else if(0===h.indexOf("/")&&-1===h.indexOf("#")){s=h;var v=e.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);v&&(e=v[0]+h.substring(1),s=""),r.push({obj:t,resolveAs:"inline",root:e,key:p,location:s})}else r.push({obj:t,resolveAs:"inline",root:e,key:p,location:s})}else"array"===t.type&&this.resolveTo(e,t.items,r,s)},Resolver.prototype.resolveTo=function(e,i,t,r){var o,s,n=i.$ref,l=e;if("undefined"!=typeof n&&null!==n){if(n.indexOf("#")>=0){var f=n.split("#");if(f[0]&&0===n.indexOf("/"));else if(!f[0]||0!==f[0].indexOf("http:")&&0!==f[0].indexOf("https:")){if(f[0]&&f[0].length>0){for(o=e.split("/"),l="",s=0;s<o.length-1;s++)l+=o[s]+"/";l+=f[0]}}else l=f[0],n=f[1];r=f[1]}else if(0===n.indexOf("http:")||0===n.indexOf("https:"))l=n,r="";else{for(o=e.split("/"),l="",s=0;s<o.length-1;s++)l+=o[s]+"/";l+=n,r=""}t.push({obj:i,resolveAs:"ref",root:l,key:n,location:r})}else if("array"===i.type){var a=i.items;this.resolveTo(e,a,t,r)}else if(i&&(i.properties||i.additionalProperties)){var p=this.uniqueName("inline_model");i.title&&(p=this.uniqueName(i.title)),delete i.title,this.spec.definitions[p]=_.cloneDeep(i),i.$ref="#/definitions/"+p,delete i.type,delete i.properties}},Resolver.prototype.uniqueName=function(e){for(var i=e,t=0;;){if(!_.isObject(this.spec.definitions[i]))return i;i=e+"_"+t,t++}},Resolver.prototype.resolveAllOf=function(e,i,t){t=t||0,i=i||e;var r;for(var o in i)if(i.hasOwnProperty(o)){var s=i[o];if(null===s)throw new TypeError("Swagger 2.0 does not support null types ("+i+"). See https://github.com/swagger-api/swagger-spec/issues/229.");if("object"==typeof s&&this.resolveAllOf(e,s,t+1),s&&"undefined"!=typeof s.allOf){var n=s.allOf;if(_.isArray(n)){var l=_.cloneDeep(s);delete l.allOf,l["x-composed"]=!0,"undefined"!=typeof s["x-resolved-from"]&&(l["x-resolved-from"]=s["x-resolved-from"]);for(var f=0;f<n.length;f++){var a=n[f],p="self";"undefined"!=typeof a["x-resolved-from"]&&(p=a["x-resolved-from"][0]);for(var h in a)if(l.hasOwnProperty(h))if("properties"===h){var c=a[h];for(r in c){l.properties[r]=_.cloneDeep(c[r]);var d=c[r]["x-resolved-from"];"undefined"!=typeof d&&"self"!==d||(d=p),l.properties[r]["x-resolved-from"]=d}}else if("required"===h){for(var v=l.required.concat(a[h]),u=0;u<v.length;++u)for(var m=u+1;m<v.length;++m)v[u]===v[m]&&v.splice(m--,1);l.required=v}else"x-resolved-from"===h&&l["x-resolved-from"].push(p);else if(l[h]=_.cloneDeep(a[h]),"properties"===h)for(r in l[h])l[h][r]["x-resolved-from"]=p}i[o]=l}}}};
|
|
30
|
+
"use strict";function splitUrl(e){var i={},r=/[a-z]+:\/\//i.exec(e);r&&(i.proto=r[0].slice(0,-3),e=e.slice(i.proto.length+1)),"//"===e.slice(0,2)&&(i.domain=e.slice(2).split("/")[0],e=e.slice(2+i.domain.length));var t=e.split("#");return t[0].length&&(i.path=t[0]),t.length>1&&(i.fragment=t.slice(1).join("#")),i}function unsplitUrl(e){var i=e.path;return void 0===i&&(i=""),void 0!==e.fragment&&(i+="#"+e.fragment),void 0!==e.domain&&("/"===i.slice(0,1)&&(i=i.slice(1)),i="//"+e.domain+"/"+i,void 0!==e.proto&&(i=e.proto+":"+i)),i}function joinUrl(e,i){var r=splitUrl(i);if(void 0!==r.domain)return i;var t=splitUrl(e);if(void 0===r.path)t.fragment=r.fragment;else if("/"===r.path.slice(0,1))t.path=r.path,t.fragment=r.fragment;else{var o=void 0===t.path?[]:t.path.split("/"),s=r.path.split("/");for(o.length&&o.pop();".."===s[0]||"."===s[0];)".."===s[0]&&o.pop(),s.shift();t.path=o.concat(s).join("/"),t.fragment=r.fragment}return unsplitUrl(t)}var SwaggerHttp=require("./http"),_={isObject:require("lodash-compat/lang/isObject"),cloneDeep:require("lodash-compat/lang/cloneDeep"),isArray:require("lodash-compat/lang/isArray"),isString:require("lodash-compat/lang/isString")},Resolver=module.exports=function(){this.failedUrls=[],this.resolverCache={},this.pendingUrls={}};Resolver.prototype.processAllOf=function(e,i,r,t,o,s){var n,l,f;r["x-resolved-from"]=["#/definitions/"+i];var a=r.allOf;for(a.sort(function(e,i){return e.$ref&&i.$ref?0:e.$ref?-1:1}),n=0;n<a.length;n++)f=a[n],l="/definitions/"+i+"/allOf",this.resolveInline(e,s,f,t,o,l)},Resolver.prototype.resolve=function(e,i,r,t){this.spec=e;var o,s,n=i,l=r,f=t,a={};"function"==typeof i&&(n=null,l=i,f=r);var p=n;this.scope=f||this,this.iteration=this.iteration||0,this.scope.options&&this.scope.options.requestInterceptor&&(a.requestInterceptor=this.scope.options.requestInterceptor),this.scope.options&&this.scope.options.responseInterceptor&&(a.responseInterceptor=this.scope.options.responseInterceptor);var h,c,v,d,u=0,m={},g={},y=[];e.definitions=e.definitions||{};for(h in e.definitions){var O=e.definitions[h];if(O.$ref)this.resolveInline(n,e,O,y,g,O);else{for(d in O.properties)v=O.properties[d],_.isArray(v.allOf)?this.processAllOf(n,h,v,y,g,e):this.resolveTo(n,v,y,"/definitions");O.allOf&&this.processAllOf(n,h,O,y,g,e)}}e.parameters=e.parameters||{};for(h in e.parameters){var b=e.parameters[h];if("body"===b["in"]&&b.schema)if(_.isArray(b.schema.allOf)){for(var x="inline_model",h=x,j=!1,A=0;!j;){if("undefined"==typeof e.definitions[h]){j=!0;break}h=x+"_"+A,A++}e.definitions[h]={allOf:b.schema.allOf},delete b.schema.allOf,b.schema.$ref="#/definitions/"+h,this.processAllOf(n,h,e.definitions[h],y,g,e)}else this.resolveTo(n,b.schema,y,o);b.$ref&&this.resolveInline(n,e,b,y,g,b.$ref)}for(h in e.paths){var k,$,R;c=e.paths[h];for(k in c)if("$ref"===k)o="/paths"+h,this.resolveInline(n,e,c,y,g,o);else{$=c[k];var I=c.parameters||[],q=$.parameters||[];for(s in I){var b=I[s];q.unshift(b)}"parameters"!==k&&_.isObject($)&&($.parameters=$.parameters||q);for(s in q){var b=q[s];if(o="/paths"+h+"/"+k+"/parameters","body"===b["in"]&&b.schema)if(_.isArray(b.schema.allOf)){for(var x="inline_model",h=x,j=!1,A=0;!j;){if("undefined"==typeof e.definitions[h]){j=!0;break}h=x+"_"+A,A++}e.definitions[h]={allOf:b.schema.allOf},delete b.schema.allOf,b.schema.$ref="#/definitions/"+h,this.processAllOf(n,h,e.definitions[h],y,g,e)}else this.resolveTo(n,b.schema,y,o);b.$ref&&this.resolveInline(n,e,b,y,g,b.$ref)}for(R in $.responses){var U=$.responses[R];if(o="/paths"+h+"/"+k+"/responses/"+R,_.isObject(U)&&(U.$ref&&this.resolveInline(n,e,U,y,g,o),U.schema)){var w=U;if(_.isArray(w.schema.allOf)){for(var x="inline_model",h=x,j=!1,A=0;!j;){if("undefined"==typeof e.definitions[h]){j=!0;break}h=x+"_"+A,A++}e.definitions[h]={allOf:w.schema.allOf},delete w.schema.allOf,delete w.schema.type,w.schema.$ref="#/definitions/"+h,this.processAllOf(n,h,e.definitions[h],y,g,e)}else"array"===w.schema.type?w.schema.items&&w.schema.items.$ref&&this.resolveInline(n,e,w.schema.items,y,g,o):this.resolveTo(n,U.schema,y,o)}}}c.parameters=[]}var T,S=0,D=[],C=y;for(s=0;s<C.length;s++){var P=C[s];if(n===P.root){if("ref"===P.resolveAs){var z,H=((P.root||"")+"/"+P.key).split("/"),N=[],E="";if(P.key.indexOf("../")>=0){for(var J=0;J<H.length;J++)".."===H[J]?N=N.slice(0,N.length-1):N.push(H[J]);for(z=0;z<N.length;z++)z>0&&(E+="/"),E+=N[z];P.root=E,D.push(P)}else if(T=P.key.split("#"),2===T.length){0!==T[0].indexOf("http:")&&0!==T[0].indexOf("https:")||(P.root=T[0]),o=T[1].split("/");var Q,B=e;for(z=0;z<o.length;z++){var F=o[z];if(""!==F){if(B=B[F],"undefined"==typeof B){Q=null;break}Q=B}}null===Q&&D.push(P)}}else if("inline"===P.resolveAs){if(P.key&&-1===P.key.indexOf("#")&&"/"!==P.key.charAt(0)){for(T=P.root.split("/"),o="",s=0;s<T.length-1;s++)o+=T[s]+"/";o+=P.key,P.root=o,P.location=""}D.push(P)}}else D.push(P)}S=D.length;for(var G={},K=0;K<D.length;K++)!function(e,i,r,t,o){if(e.root&&e.root!==n)if(-1===r.failedUrls.indexOf(e.root)){var s={useJQuery:!1,url:e.root,method:"get",headers:{accept:r.scope.swaggerRequestHeaders||"application/json"},on:{error:function(o){u+=1,console.log("failed url: "+s.url),r.failedUrls.push(s.url),t&&delete t[e.root],g[e.key]={root:e.root,location:e.location},u===S&&r.finish(i,p,y,m,g,l)},response:function(o){var s=o.obj;t&&delete t[e.root],r.resolverCache&&(r.resolverCache[e.root]=s),r.resolveItem(s,e.root,y,m,g,e),u+=1,u===S&&r.finish(i,p,y,m,g,l)}}};f&&f.fetchSpecTimeout&&(s.timeout=f.fetchSpecTimeout),f&&f.clientAuthorizations&&f.clientAuthorizations.apply(s),function h(){setTimeout(function(){if(t[s.url])h();else{var e=r.resolverCache[s.url];_.isObject(e)?(s.on.response({obj:e}),1):(t[s.url]=!0,(new SwaggerHttp).execute(s,a))}},0)}()}else u+=1,g[e.key]={root:e.root,location:e.location},u===S&&r.finish(i,p,y,m,g,l);else r.resolveItem(i,p,y,m,g,e),u+=1,u===S&&r.finish(i,n,y,m,g,l,!0)}(D[K],e,this,G,K);0===Object.keys(D).length&&this.finish(e,p,y,m,g,l)},Resolver.prototype.resolveItem=function(e,i,r,t,o,s){var n=s.location,l=e,f=n.split("/");if(""!==n)for(var a=0;a<f.length;a++){var p=f[a];if(-1!==p.indexOf("~1")&&(p=f[a].replace(/~0/g,"~").replace(/~1/g,"/"),"/"!==p.charAt(0)&&(p="/"+p)),"undefined"==typeof l||null===l)break;if(""===p&&a===f.length-1&&f.length>1){l=null;break}p.length>0&&(l=l[p])}var h=s.key;f=s.key.split("/");var c=f[f.length-1];c.indexOf("#")>=0&&(c=c.split("#")[1]),null!==l&&"undefined"!=typeof l?t[h]={name:c,obj:l,key:s.key,root:s.root}:o[h]={root:s.root,location:s.location}},Resolver.prototype.finish=function(e,i,r,t,o,s,n){var l;for(l in r){var f=r[l],a=f.key,p=t[a];if(p)if(e.definitions=e.definitions||{},"ref"===f.resolveAs){if(n!==!0)for(a in p.obj){var h=this.retainRoot(a,p.obj[a],f.root);p.obj[a]=h}e.definitions[p.name]=p.obj,f.obj.$ref="#/definitions/"+p.name}else if("inline"===f.resolveAs){var c=f.obj;c["x-resolved-from"]=[f.key],delete c.$ref;for(a in p.obj){var h=p.obj[a];n!==!0&&(h=this.retainRoot(a,p.obj[a],f.root)),c[a]=h}}}var v=this.countUnresolvedRefs(e);0===v||this.iteration>5?(this.resolveAllOf(e.definitions),this.resolverCache=null,s.call(this.scope,e,o)):(this.iteration+=1,this.resolve(e,i,s,this.scope))},Resolver.prototype.countUnresolvedRefs=function(e){var i,r=this.getRefs(e),t=[],o=[];for(i in r)0===i.indexOf("#")?t.push(i.substring(1)):o.push(i);for(i=0;i<t.length;i++)for(var s=t[i],n=s.split("/"),l=e,f=0;f<n.length;f++){var a=n[f];if(""!==a&&(l=l[a],"undefined"==typeof l)){o.push(s);break}}return o.length},Resolver.prototype.getRefs=function(e,i){i=i||e;var r={};for(var t in i)if(i.hasOwnProperty(t)){var o=i[t];if("$ref"===t&&"string"==typeof o)r[o]=null;else if(_.isObject(o)){var s=this.getRefs(o);for(var n in s)r[n]=null}}return r},Resolver.prototype.retainRoot=function(e,i,r){if(_.isObject(i))for(var t in i){var o=i[t];"$ref"===t&&"string"==typeof o?i[t]=joinUrl(r,o):_.isObject(o)&&this.retainRoot(t,o,r)}else _.isString(i)&&"$ref"===e&&(i=joinUrl(r,i));return i},Resolver.prototype.resolveInline=function(e,i,r,t,o,s){var n,l,f,a,p=r.$ref,h=r.$ref,c=!1;if(e=e||"",h){if(0===h.indexOf("../")){for(l=h.split("../"),f=e.split("/"),h="",n=0;n<l.length;n++)""===l[n]?f=f.slice(0,f.length-1):h+=l[n];for(e="",n=0;n<f.length-1;n++)n>0&&(e+="/"),e+=f[n];c=!0}if(h.indexOf("#")>=0)if(0===h.indexOf("/"))a=h.split("#"),l=e.split("//"),f=l[1].split("/"),e=l[0]+"//"+f[0]+a[0],s=a[1];else{if(a=h.split("#"),""!==a[0]){if(f=e.split("/"),f=f.slice(0,f.length-1),!c){e="";for(var v=0;v<f.length;v++)v>0&&(e+="/"),e+=f[v]}e+="/"+h.split("#")[0]}s=a[1]}if(0===h.indexOf("http:")||0===h.indexOf("https:"))h.indexOf("#")>=0?(e=h.split("#")[0],s=h.split("#")[1]):(e=h,s=""),t.push({obj:r,resolveAs:"inline",root:e,key:p,location:s});else if(0===h.indexOf("#"))s=h.split("#")[1],t.push({obj:r,resolveAs:"inline",root:e,key:p,location:s});else if(0===h.indexOf("/")&&-1===h.indexOf("#")){s=h;var d=e.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);d&&(e=d[0]+h.substring(1),s=""),t.push({obj:r,resolveAs:"inline",root:e,key:p,location:s})}else t.push({obj:r,resolveAs:"inline",root:e,key:p,location:s})}else"array"===r.type&&this.resolveTo(e,r.items,t,s)},Resolver.prototype.resolveTo=function(e,i,r,t){var o,s,n=i.$ref,l=e;if("undefined"!=typeof n&&null!==n){if(n.indexOf("#")>=0){var f=n.split("#");if(f[0]&&0===n.indexOf("/"));else if(!f[0]||0!==f[0].indexOf("http:")&&0!==f[0].indexOf("https:")){if(f[0]&&f[0].length>0){for(o=e.split("/"),l="",s=0;s<o.length-1;s++)l+=o[s]+"/";l+=f[0]}}else l=f[0],n=f[1];t=f[1]}else if(0===n.indexOf("http:")||0===n.indexOf("https:"))l=n,t="";else{for(o=e.split("/"),l="",s=0;s<o.length-1;s++)l+=o[s]+"/";l+=n,t=""}r.push({obj:i,resolveAs:"ref",root:l,key:n,location:t})}else if("array"===i.type){var a=i.items;this.resolveTo(e,a,r,t)}else if(i&&(i.properties||i.additionalProperties)){var p=this.uniqueName("inline_model");i.title&&(p=this.uniqueName(i.title)),delete i.title,this.spec.definitions[p]=_.cloneDeep(i),i.$ref="#/definitions/"+p,delete i.type,delete i.properties}},Resolver.prototype.uniqueName=function(e){for(var i=e,r=0;;){if(!_.isObject(this.spec.definitions[i]))return i;i=e+"_"+r,r++}},Resolver.prototype.resolveAllOf=function(e,i,r){r=r||0,i=i||e;var t;for(var o in i)if(i.hasOwnProperty(o)){var s=i[o];if(null===s)throw new TypeError("Swagger 2.0 does not support null types ("+i+"). See https://github.com/swagger-api/swagger-spec/issues/229.");if("object"==typeof s&&this.resolveAllOf(e,s,r+1),s&&"undefined"!=typeof s.allOf){var n=s.allOf;if(_.isArray(n)){var l=_.cloneDeep(s);delete l.allOf,l["x-composed"]=!0,"undefined"!=typeof s["x-resolved-from"]&&(l["x-resolved-from"]=s["x-resolved-from"]);for(var f=0;f<n.length;f++){var a=n[f],p="self";"undefined"!=typeof a["x-resolved-from"]&&(p=a["x-resolved-from"][0]);for(var h in a)if(l.hasOwnProperty(h))if("properties"===h){var c=a[h];for(t in c){l.properties[t]=_.cloneDeep(c[t]);var v=c[t]["x-resolved-from"];"undefined"!=typeof v&&"self"!==v||(v=p),l.properties[t]["x-resolved-from"]=v}}else if("required"===h){for(var d=l.required.concat(a[h]),u=0;u<d.length;++u)for(var m=u+1;m<d.length;++m)d[u]===d[m]&&d.splice(m--,1);l.required=d}else"x-resolved-from"===h&&l["x-resolved-from"].push(p);else if(l[h]=_.cloneDeep(a[h]),"properties"===h)for(t in l[h])l[h][t]["x-resolved-from"]=p}i[o]=l}}}};
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
},{"./http":5,"lodash-compat/lang/cloneDeep":138,"lodash-compat/lang/isArray":140,"lodash-compat/lang/isObject":144,"lodash-compat/lang/isString":146}],7:[function(require,module,exports){
|
|
34
|
-
"use strict";
|
|
34
|
+
"use strict";function optionHtml(e,t){return'<tr><td class="optionName">'+e+":</td><td>"+t+"</td></tr>"}function typeFromJsonSchema(e,t){var i;return"integer"===e&&"int32"===t?i="integer":"integer"===e&&"int64"===t?i="long":"integer"===e&&"undefined"==typeof t?i="long":"string"===e&&"date-time"===t?i="date-time":"string"===e&&"date"===t?i="date":"number"===e&&"float"===t?i="float":"number"===e&&"double"===t?i="double":"number"===e&&"undefined"==typeof t?i="double":"boolean"===e?i="boolean":"string"===e&&(i="string"),i}function getStringSignature(e,t){var i="";return"undefined"!=typeof e.$ref?i+=Helpers.simpleRef(e.$ref):"undefined"==typeof e.type?i+="object":"array"===e.type?t?i+=getStringSignature(e.items||e.$ref||{}):(i+="Array[",i+=getStringSignature(e.items||e.$ref||{}),i+="]"):i+="integer"===e.type&&"int32"===e.format?"integer":"integer"===e.type&&"int64"===e.format?"long":"integer"===e.type&&"undefined"==typeof e.format?"long":"string"===e.type&&"date-time"===e.format?"date-time":"string"===e.type&&"date"===e.format?"date":"string"===e.type&&"undefined"==typeof e.format?"string":"number"===e.type&&"float"===e.format?"float":"number"===e.type&&"double"===e.format?"double":"number"===e.type&&"undefined"==typeof e.format?"double":"boolean"===e.type?"boolean":e.$ref?Helpers.simpleRef(e.$ref):e.type,i}function schemaToJSON(e,t,i,n){e=Helpers.resolveSchema(e),"function"!=typeof n&&(n=function(e){return(e||{})["default"]}),i=i||{};var r,o,s=e.type||"object",a=e.format;return _.isUndefined(e.example)?_.isUndefined(e.items)&&_.isArray(e["enum"])&&(o=e["enum"][0]):o=e.example,_.isUndefined(o)&&(e.$ref?(r=t[Helpers.simpleRef(e.$ref)],_.isUndefined(r)||(_.isUndefined(i[r.name])?(i[r.name]=r,o=schemaToJSON(r.definition,t,i,n),delete i[r.name]):o="array"===r.type?[]:{})):_.isUndefined(e["default"])?"string"===s?o="date-time"===a?(new Date).toISOString():"date"===a?(new Date).toISOString().split("T")[0]:"string":"integer"===s?o=0:"number"===s?o=0:"boolean"===s?o=!0:"object"===s?(o={},_.forEach(e.properties,function(e,r){var s=_.cloneDeep(e);s["default"]=n(e),o[r]=schemaToJSON(s,t,i,n)})):"array"===s&&(o=[],_.isArray(e.items)?_.forEach(e.items,function(e){o.push(schemaToJSON(e,t,i,n))}):_.isPlainObject(e.items)?o.push(schemaToJSON(e.items,t,i,n)):_.isUndefined(e.items)?o.push({}):Helpers.log("Array type's 'items' property is not an array or an object, cannot process")):o=e["default"]),o}function schemaToHTML(e,t,i,n){function r(e,t,n){var r,o=t;return e.$ref?(o=e.title||Helpers.simpleRef(e.$ref),r=i[o]):_.isUndefined(t)&&(o=e.title||"Inline Model "+ ++f,r={definition:e}),n!==!0&&(l[o]=_.isUndefined(r)?{}:r.definition),o}function o(e){var t='<span class="propType">',i=e.type||"object";return e.$ref?t+=r(e,Helpers.simpleRef(e.$ref)):"object"===i?t+=_.isUndefined(e.properties)?"object":r(e):"array"===i?(t+="Array[",_.isArray(e.items)?t+=_.map(e.items,r).join(","):_.isPlainObject(e.items)?t+=_.isUndefined(e.items.$ref)?_.isUndefined(e.items.type)||-1!==_.indexOf(["array","object"],e.items.type)?r(e.items):e.items.type:r(e.items,Helpers.simpleRef(e.items.$ref)):(Helpers.log("Array type's 'items' schema is not an array or an object, cannot process"),t+="object"),t+="]"):t+=e.type,t+="</span>"}function s(e,t){var i="",n=e.type||"object",r="array"===n;switch(r&&(n=_.isPlainObject(e.items)&&!_.isUndefined(e.items.type)?e.items.type:"object"),_.isUndefined(e["default"])||(i+=optionHtml("Default",e["default"])),n){case"string":e.minLength&&(i+=optionHtml("Min. Length",e.minLength)),e.maxLength&&(i+=optionHtml("Max. Length",e.maxLength)),e.pattern&&(i+=optionHtml("Reg. Exp.",e.pattern));break;case"integer":case"number":e.minimum&&(i+=optionHtml("Min. Value",e.minimum)),e.exclusiveMinimum&&(i+=optionHtml("Exclusive Min.","true")),e.maximum&&(i+=optionHtml("Max. Value",e.maximum)),e.exclusiveMaximum&&(i+=optionHtml("Exclusive Max.","true")),e.multipleOf&&(i+=optionHtml("Multiple Of",e.multipleOf))}if(r&&(e.minItems&&(i+=optionHtml("Min. Items",e.minItems)),e.maxItems&&(i+=optionHtml("Max. Items",e.maxItems)),e.uniqueItems&&(i+=optionHtml("Unique Items","true")),e.collectionFormat&&(i+=optionHtml("Coll. Format",e.collectionFormat))),_.isUndefined(e.items)&&_.isArray(e["enum"])){var o;o="number"===n||"integer"===n?e["enum"].join(", "):'"'+e["enum"].join('", "')+'"',i+=optionHtml("Enum",o)}return i.length>0&&(t='<span class="propWrap">'+t+'<table class="optionsWrapper"><tr><th colspan="2">'+n+"</th></tr>"+i+"</table></span>"),t}function a(e,t){var a=e.type||"object",l="array"===e.type,f=p+t+" "+(l?"[":"{")+m;if(t&&d.push(t),l)_.isArray(e.items)?f+="<div>"+_.map(e.items,function(e){var t=e.type||"object";return _.isUndefined(e.$ref)?_.indexOf(["array","object"],t)>-1?"object"===t&&_.isUndefined(e.properties)?"object":r(e):s(e,t):r(e,Helpers.simpleRef(e.$ref))}).join(",</div><div>"):_.isPlainObject(e.items)?f+=_.isUndefined(e.items.$ref)?_.indexOf(["array","object"],e.items.type||"object")>-1?(_.isUndefined(e.items.type)||"object"===e.items.type)&&_.isUndefined(e.items.properties)?"<div>object</div>":"<div>"+r(e.items)+"</div>":"<div>"+s(e.items,e.items.type)+"</div>":"<div>"+r(e.items,Helpers.simpleRef(e.items.$ref))+"</div>":(Helpers.log("Array type's 'items' property is not an array or an object, cannot process"),f+="<div>object</div>");else if(e.$ref)f+="<div>"+r(e,t)+"</div>";else if("object"===a){if(_.isPlainObject(e.properties)){var c=_.map(e.properties,function(t,r){var a,p,m=_.indexOf(e.required,r)>=0,l=_.cloneDeep(t),d=m?"required":"",f='<span class="propName '+d+'">'+r+"</span> (";return l["default"]=n(l),l=Helpers.resolveSchema(l),p=t.description||l.description,_.isUndefined(l.$ref)||(a=i[Helpers.simpleRef(l.$ref)],_.isUndefined(a)||-1!==_.indexOf([void 0,"array","object"],a.definition.type)||(l=Helpers.resolveSchema(a.definition))),f+=o(l),m||(f+=', <span class="propOptKey">optional</span>'),t.readOnly&&(f+=', <span class="propReadOnly">read only</span>'),f+=")",_.isUndefined(p)||(f+=': <span class="propDesc">'+p+"</span>"),l["enum"]&&(f+=' = <span class="propVals">[\''+l["enum"].join("', '")+"']</span>"),"<div"+(t.readOnly?' class="readOnly"':"")+">"+s(l,f)}).join(",</div>");c&&(f+=c+"</div>")}}else f+="<div>"+s(e,a)+"</div>";return f+p+(l?"]":"}")+m}var p='<span class="strong">',m="</span>";if(_.isObject(arguments[0])&&(e=void 0,t=arguments[0],i=arguments[1],n=arguments[2]),i=i||{},t=Helpers.resolveSchema(t),_.isEmpty(t))return p+"Empty"+m;if("string"==typeof t.$ref&&(e=Helpers.simpleRef(t.$ref),t=i[e],"undefined"==typeof t))return p+e+" is not defined!"+m;"string"!=typeof e&&(e=t.title||"Inline Model"),t.definition&&(t=t.definition),"function"!=typeof n&&(n=function(e){return(e||{})["default"]});for(var l={},d=[],f=0,c=a(t,e);_.keys(l).length>0;)_.forEach(l,function(e,t){var i=_.indexOf(d,t)>-1;delete l[t],i||(d.push(t),c+="<br />"+a(e,t))});return c}var Helpers=require("./helpers"),_={isPlainObject:require("lodash-compat/lang/isPlainObject"),isUndefined:require("lodash-compat/lang/isUndefined"),isArray:require("lodash-compat/lang/isArray"),isObject:require("lodash-compat/lang/isObject"),isEmpty:require("lodash-compat/lang/isEmpty"),map:require("lodash-compat/collection/map"),indexOf:require("lodash-compat/array/indexOf"),cloneDeep:require("lodash-compat/lang/cloneDeep"),keys:require("lodash-compat/object/keys"),forEach:require("lodash-compat/collection/forEach")};module.exports.optionHtml=optionHtml,module.exports.typeFromJsonSchema=typeFromJsonSchema,module.exports.getStringSignature=getStringSignature,module.exports.schemaToHTML=schemaToHTML,module.exports.schemaToJSON=schemaToJSON;
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
},{"./helpers":4,"lodash-compat/array/indexOf":49,"lodash-compat/collection/forEach":54,"lodash-compat/collection/map":56,"lodash-compat/lang/cloneDeep":138,"lodash-compat/lang/isArray":140,"lodash-compat/lang/isEmpty":141,"lodash-compat/lang/isObject":144,"lodash-compat/lang/isPlainObject":145,"lodash-compat/lang/isUndefined":148,"lodash-compat/object/keys":149}],8:[function(require,module,exports){
|
|
38
|
-
"use strict";var SwaggerHttp=require("./http"),_={isObject:require("lodash-compat/lang/isObject")},SwaggerSpecConverter=module.exports=function(){this.errors=[],this.warnings=[],this.modelMap={}};SwaggerSpecConverter.prototype.setDocumentationLocation=function(e){this.docLocation=e},SwaggerSpecConverter.prototype.convert=function(e,t,r,i){if(!e||!Array.isArray(e.apis))return this.finish(i,null);this.clientAuthorizations=t;var s={swagger:"2.0"};s.originalVersion=e.swaggerVersion,this.apiInfo(e,s),this.securityDefinitions(e,s),e.basePath&&this.setDocumentationLocation(e.basePath);var n,o=!1;for(n=0;n<e.apis.length;n++){var a=e.apis[n];Array.isArray(a.operations)&&(o=!0)}o?(this.declaration(e,s),this.finish(i,s)):this.resourceListing(e,s,r,i)},SwaggerSpecConverter.prototype.declaration=function(e,t){var r,i,s,n;if(e.apis){0===e.basePath.indexOf("http://")?(s=e.basePath.substring("http://".length),n=s.indexOf("/"),n>0?(t.host=s.substring(0,n),t.basePath=s.substring(n)):(t.host=s,t.basePath="/")):0===e.basePath.indexOf("https://")?(s=e.basePath.substring("https://".length),n=s.indexOf("/"),n>0?(t.host=s.substring(0,n),t.basePath=s.substring(n)):(t.host=s,t.basePath="/")):t.basePath=e.basePath;var o;if(e.authorizations&&(o=e.authorizations),e.consumes&&(t.consumes=e.consumes),e.produces&&(t.produces=e.produces),_.isObject(e))for(r in e.models){var a=e.models[r],p=a.id||r;this.modelMap[p]=r}for(i=0;i<e.apis.length;i++){var u=e.apis[i],c=u.path,f=u.operations;this.operations(c,e.resourcePath,f,o,t)}var h=e.models||{};this.models(h,t)}},SwaggerSpecConverter.prototype.models=function(e,t){if(_.isObject(e)){var r;t.definitions=t.definitions||{};for(r in e){var i,s=e[r],n=[],o={properties:{}};for(i in s.properties){var a=s.properties[i],p={};this.dataType(a,p),a.description&&(p.description=a.description),a["enum"]&&(p["enum"]=a["enum"]),"boolean"==typeof a.required&&a.required===!0&&n.push(i),"string"==typeof a.required&&"true"===a.required&&n.push(i),o.properties[i]=p}n.length>0?o.required=n:o.required=s.required,t.definitions[r]=o}}},SwaggerSpecConverter.prototype.extractTag=function(e){var t=e||"default";return 0!==t.indexOf("http:")&&0!==t.indexOf("https:")||(t=t.split(["/"]),t=t[t.length-1].substring()),t.endsWith(".json")&&(t=t.substring(0,t.length-".json".length)),t.replace("/","")},SwaggerSpecConverter.prototype.operations=function(e,t,r,i,s){if(Array.isArray(r)){var n;s.paths||(s.paths={});var o=s.paths[e]||{},a=this.extractTag(t);s.tags=s.tags||[];var p=!1;for(n=0;n<s.tags.length;n++){var u=s.tags[n];u.name===a&&(p=!0)}for(p||s.tags.push({name:a}),n=0;n<r.length;n++){var c=r[n],f=(c.method||c.httpMethod).toLowerCase(),h={tags:[a]},l=c.authorizations;if(l&&0===Object.keys(l).length&&(l=i),"undefined"!=typeof l){var m;for(var d in l){h.security=h.security||[];var g=l[d];if(g){var y=[];for(var v in g)y.push(g[v].scope);m={},m[d]=y,h.security.push(m)}else m={},m[d]=[],h.security.push(m)}}c.consumes?h.consumes=c.consumes:s.consumes&&(h.consumes=s.consumes),c.produces?h.produces=c.produces:s.produces&&(h.produces=s.produces),c.summary&&(h.summary=c.summary),c.notes&&(h.description=c.notes),c.nickname&&(h.operationId=c.nickname),c.deprecated&&(h.deprecated=c.deprecated),this.authorizations(l,s),this.parameters(h,c.parameters,s),this.responseMessages(h,c,s),o[f]=h}s.paths[e]=o}},SwaggerSpecConverter.prototype.responseMessages=function(e,t){if(_.isObject(t)){var r={};this.dataType(t,r),!r.schema&&r.type&&(r={schema:r}),e.responses=e.responses||{};var i=!1;if(Array.isArray(t.responseMessages)){var s,n=t.responseMessages;for(s=0;s<n.length;s++){var o=n[s],a={description:o.message};200===o.code&&(i=!0),o.responseModel&&(a.schema={$ref:"#/definitions/"+o.responseModel}),e.responses[""+o.code]=a}}i?e.responses["default"]=r:e.responses[200]=r}},SwaggerSpecConverter.prototype.authorizations=function(e){!_.isObject(e)},SwaggerSpecConverter.prototype.parameters=function(e,t){if(Array.isArray(t)){var r;for(r=0;r<t.length;r++){var i=t[r],s={};if(s.name=i.name,s.description=i.description,s.required=i.required,s["in"]=i.paramType,"body"===s["in"]&&(s.name="body"),"form"===s["in"]&&(s["in"]="formData"),i["enum"]&&(s["enum"]=i["enum"]),i.allowMultiple===!0||"true"===i.allowMultiple){var n={};if(this.dataType(i,n),s.type="array",s.items=n,i.allowableValues){var o=i.allowableValues;"LIST"===o.valueType&&(s["enum"]=o.values)}}else this.dataType(i,s);"undefined"!=typeof i.defaultValue&&(s["default"]=i.defaultValue),e.parameters=e.parameters||[],e.parameters.push(s)}}},SwaggerSpecConverter.prototype.dataType=function(e,t){if(_.isObject(e)){e.minimum&&(t.minimum=e.minimum),e.maximum&&(t.maximum=e.maximum),e.format&&(t.format=e.format),"undefined"!=typeof e.defaultValue&&(t["default"]=e.defaultValue);var r=this.toJsonSchema(e);r&&(t=t||{},r.type&&(t.type=r.type),r.format&&(t.format=r.format),r.$ref&&(t.schema={$ref:r.$ref}),r.items&&(t.items=r.items))}},SwaggerSpecConverter.prototype.toJsonSchema=function(e){if(!e)return"object";var t=e.type||e.dataType||e.responseClass||"",r=t.toLowerCase(),i=(e.format||"").toLowerCase();if(0===r.indexOf("list[")){var s=t.substring(5,t.length-1),n=this.toJsonSchema({type:s});return{type:"array",items:n}}if("int"===r||"integer"===r&&"int32"===i)return{type:"integer",format:"int32"};if("long"===r||"integer"===r&&"int64"===i)return{type:"integer",format:"int64"};if("integer"===r)return{type:"integer",format:"int64"};if("float"===r||"number"===r&&"float"===i)return{type:"number",format:"float"};if("double"===r||"number"===r&&"double"===i)return{type:"number",format:"double"};if("string"===r&&"date-time"===i||"date"===r)return{type:"string",format:"date-time"};if("string"===r)return{type:"string"};if("file"===r)return{type:"file"};if("boolean"===r)return{type:"boolean"};if("boolean"===r)return{type:"boolean"};if("array"===r||"list"===r){if(e.items){var o=this.toJsonSchema(e.items);return{type:"array",items:o}}return{type:"array",items:{type:"object"}}}return e.$ref?{$ref:this.modelMap[e.$ref]?"#/definitions/"+this.modelMap[e.$ref]:e.$ref}:"void"===r||""===r?{}:this.modelMap[e.type]?{$ref:"#/definitions/"+this.modelMap[e.type]}:{type:e.type}},SwaggerSpecConverter.prototype.resourceListing=function(e,t,r,i){var s,n=0,o=this,a=e.apis.length,p=t,u={};r&&r.requestInterceptor&&(u.requestInterceptor=r.requestInterceptor),r&&r.responseInterceptor&&(u.responseInterceptor=r.responseInterceptor);var c="application/json";for(r&&r.swaggerRequestHeaders&&(c=r.swaggerRequestHeaders),0===a&&this.finish(i,t),s=0;a>s;s++){var f=e.apis[s],h=f.path,l=this.getAbsolutePath(e.swaggerVersion,this.docLocation,h);f.description&&(t.tags=t.tags||[],t.tags.push({name:this.extractTag(f.path),description:f.description||""}));var m={url:l,headers:{accept:c},on:{},method:"get",timeout:r.timeout};m.on.response=function(e){n+=1;var t=e.obj;t&&o.declaration(t,p),n===a&&o.finish(i,p)},m.on.error=function(e){console.error(e),n+=1,n===a&&o.finish(i,p)},this.clientAuthorizations&&"function"==typeof this.clientAuthorizations.apply&&this.clientAuthorizations.apply(m),(new SwaggerHttp).execute(m,u)}},SwaggerSpecConverter.prototype.getAbsolutePath=function(e,t,r){if("1.0"===e&&t.endsWith(".json")){var i=t.lastIndexOf("/");i>0&&(t=t.substring(0,i))}var s=t;return 0===r.indexOf("http:")||0===r.indexOf("https:")?s=r:(t.endsWith("/")&&(s=t.substring(0,t.length-1)),s+=r),s=s.replace("{format}","json")},SwaggerSpecConverter.prototype.securityDefinitions=function(e,t){if(e.authorizations){var r;for(r in e.authorizations){var i=!1,s={
|
|
38
|
+
"use strict";var SwaggerHttp=require("./http"),_={isObject:require("lodash-compat/lang/isObject")},SwaggerSpecConverter=module.exports=function(){this.errors=[],this.warnings=[],this.modelMap={}};SwaggerSpecConverter.prototype.setDocumentationLocation=function(e){this.docLocation=e},SwaggerSpecConverter.prototype.convert=function(e,t,r,i){if(!e||!Array.isArray(e.apis))return this.finish(i,null);this.clientAuthorizations=t;var s={swagger:"2.0"};s.originalVersion=e.swaggerVersion,this.apiInfo(e,s),this.securityDefinitions(e,s),e.basePath&&this.setDocumentationLocation(e.basePath);var n,o=!1;for(n=0;n<e.apis.length;n++){var a=e.apis[n];Array.isArray(a.operations)&&(o=!0)}o?(this.declaration(e,s),this.finish(i,s)):this.resourceListing(e,s,r,i)},SwaggerSpecConverter.prototype.declaration=function(e,t){var r,i,s,n;if(e.apis){0===e.basePath.indexOf("http://")?(s=e.basePath.substring("http://".length),n=s.indexOf("/"),n>0?(t.host=s.substring(0,n),t.basePath=s.substring(n)):(t.host=s,t.basePath="/")):0===e.basePath.indexOf("https://")?(s=e.basePath.substring("https://".length),n=s.indexOf("/"),n>0?(t.host=s.substring(0,n),t.basePath=s.substring(n)):(t.host=s,t.basePath="/")):t.basePath=e.basePath;var o;if(e.authorizations&&(o=e.authorizations),e.consumes&&(t.consumes=e.consumes),e.produces&&(t.produces=e.produces),_.isObject(e))for(r in e.models){var a=e.models[r],p=a.id||r;this.modelMap[p]=r}for(i=0;i<e.apis.length;i++){var u=e.apis[i],c=u.path,f=u.operations;this.operations(c,e.resourcePath,f,o,t)}var h=e.models||{};this.models(h,t)}},SwaggerSpecConverter.prototype.models=function(e,t){if(_.isObject(e)){var r;t.definitions=t.definitions||{};for(r in e){var i,s=e[r],n=[],o={properties:{}};for(i in s.properties){var a=s.properties[i],p={};this.dataType(a,p),a.description&&(p.description=a.description),a["enum"]&&(p["enum"]=a["enum"]),"boolean"==typeof a.required&&a.required===!0&&n.push(i),"string"==typeof a.required&&"true"===a.required&&n.push(i),o.properties[i]=p}n.length>0?o.required=n:o.required=s.required,t.definitions[r]=o}}},SwaggerSpecConverter.prototype.extractTag=function(e){var t=e||"default";return 0!==t.indexOf("http:")&&0!==t.indexOf("https:")||(t=t.split(["/"]),t=t[t.length-1].substring()),t.endsWith(".json")&&(t=t.substring(0,t.length-".json".length)),t.replace("/","")},SwaggerSpecConverter.prototype.operations=function(e,t,r,i,s){if(Array.isArray(r)){var n;s.paths||(s.paths={});var o=s.paths[e]||{},a=this.extractTag(t);s.tags=s.tags||[];var p=!1;for(n=0;n<s.tags.length;n++){var u=s.tags[n];u.name===a&&(p=!0)}for(p||s.tags.push({name:a}),n=0;n<r.length;n++){var c=r[n],f=(c.method||c.httpMethod).toLowerCase(),h={tags:[a]},l=c.authorizations;if(l&&0===Object.keys(l).length&&(l=i),"undefined"!=typeof l){var m;for(var d in l){h.security=h.security||[];var g=l[d];if(g){var y=[];for(var v in g)y.push(g[v].scope);m={},m[d]=y,h.security.push(m)}else m={},m[d]=[],h.security.push(m)}}c.consumes?h.consumes=c.consumes:s.consumes&&(h.consumes=s.consumes),c.produces?h.produces=c.produces:s.produces&&(h.produces=s.produces),c.summary&&(h.summary=c.summary),c.notes&&(h.description=c.notes),c.nickname&&(h.operationId=c.nickname),c.deprecated&&(h.deprecated=c.deprecated),this.authorizations(l,s),this.parameters(h,c.parameters,s),this.responseMessages(h,c,s),o[f]=h}s.paths[e]=o}},SwaggerSpecConverter.prototype.responseMessages=function(e,t){if(_.isObject(t)){var r={};this.dataType(t,r),!r.schema&&r.type&&(r={schema:r}),e.responses=e.responses||{};var i=!1;if(Array.isArray(t.responseMessages)){var s,n=t.responseMessages;for(s=0;s<n.length;s++){var o=n[s],a={description:o.message};200===o.code&&(i=!0),o.responseModel&&(a.schema={$ref:"#/definitions/"+o.responseModel}),e.responses[""+o.code]=a}}i?e.responses["default"]=r:e.responses[200]=r}},SwaggerSpecConverter.prototype.authorizations=function(e){!_.isObject(e)},SwaggerSpecConverter.prototype.parameters=function(e,t){if(Array.isArray(t)){var r;for(r=0;r<t.length;r++){var i=t[r],s={};if(s.name=i.name,s.description=i.description,s.required=i.required,s["in"]=i.paramType,"body"===s["in"]&&(s.name="body"),"form"===s["in"]&&(s["in"]="formData"),i["enum"]&&(s["enum"]=i["enum"]),i.allowMultiple===!0||"true"===i.allowMultiple){var n={};if(this.dataType(i,n),s.type="array",s.items=n,i.allowableValues){var o=i.allowableValues;"LIST"===o.valueType&&(s["enum"]=o.values)}}else this.dataType(i,s);"undefined"!=typeof i.defaultValue&&(s["default"]=i.defaultValue),e.parameters=e.parameters||[],e.parameters.push(s)}}},SwaggerSpecConverter.prototype.dataType=function(e,t){if(_.isObject(e)){e.minimum&&(t.minimum=e.minimum),e.maximum&&(t.maximum=e.maximum),e.format&&(t.format=e.format),"undefined"!=typeof e.defaultValue&&(t["default"]=e.defaultValue);var r=this.toJsonSchema(e);r&&(t=t||{},r.type&&(t.type=r.type),r.format&&(t.format=r.format),r.$ref&&(t.schema={$ref:r.$ref}),r.items&&(t.items=r.items))}},SwaggerSpecConverter.prototype.toJsonSchema=function(e){if(!e)return"object";var t=e.type||e.dataType||e.responseClass||"",r=t.toLowerCase(),i=(e.format||"").toLowerCase();if(0===r.indexOf("list[")){var s=t.substring(5,t.length-1),n=this.toJsonSchema({type:s});return{type:"array",items:n}}if("int"===r||"integer"===r&&"int32"===i)return{type:"integer",format:"int32"};if("long"===r||"integer"===r&&"int64"===i)return{type:"integer",format:"int64"};if("integer"===r)return{type:"integer",format:"int64"};if("float"===r||"number"===r&&"float"===i)return{type:"number",format:"float"};if("double"===r||"number"===r&&"double"===i)return{type:"number",format:"double"};if("string"===r&&"date-time"===i||"date"===r)return{type:"string",format:"date-time"};if("string"===r)return{type:"string"};if("file"===r)return{type:"file"};if("boolean"===r)return{type:"boolean"};if("boolean"===r)return{type:"boolean"};if("array"===r||"list"===r){if(e.items){var o=this.toJsonSchema(e.items);return{type:"array",items:o}}return{type:"array",items:{type:"object"}}}return e.$ref?{$ref:this.modelMap[e.$ref]?"#/definitions/"+this.modelMap[e.$ref]:e.$ref}:"void"===r||""===r?{}:this.modelMap[e.type]?{$ref:"#/definitions/"+this.modelMap[e.type]}:{type:e.type}},SwaggerSpecConverter.prototype.resourceListing=function(e,t,r,i){var s,n=0,o=this,a=e.apis.length,p=t,u={};r&&r.requestInterceptor&&(u.requestInterceptor=r.requestInterceptor),r&&r.responseInterceptor&&(u.responseInterceptor=r.responseInterceptor);var c="application/json";for(r&&r.swaggerRequestHeaders&&(c=r.swaggerRequestHeaders),0===a&&this.finish(i,t),s=0;a>s;s++){var f=e.apis[s],h=f.path,l=this.getAbsolutePath(e.swaggerVersion,this.docLocation,h);f.description&&(t.tags=t.tags||[],t.tags.push({name:this.extractTag(f.path),description:f.description||""}));var m={url:l,headers:{accept:c},on:{},method:"get",timeout:r.timeout};m.on.response=function(e){n+=1;var t=e.obj;t&&o.declaration(t,p),n===a&&o.finish(i,p)},m.on.error=function(e){console.error(e),n+=1,n===a&&o.finish(i,p)},this.clientAuthorizations&&"function"==typeof this.clientAuthorizations.apply&&this.clientAuthorizations.apply(m),(new SwaggerHttp).execute(m,u)}},SwaggerSpecConverter.prototype.getAbsolutePath=function(e,t,r){if("1.0"===e&&t.endsWith(".json")){var i=t.lastIndexOf("/");i>0&&(t=t.substring(0,i))}var s=t;return 0===r.indexOf("http:")||0===r.indexOf("https:")?s=r:(t.endsWith("/")&&(s=t.substring(0,t.length-1)),s+=r),s=s.replace("{format}","json")},SwaggerSpecConverter.prototype.securityDefinitions=function(e,t){if(e.authorizations){var r;for(r in e.authorizations){var i=!1,s={},n=e.authorizations[r];if("apiKey"===n.type)s.type="apiKey",s["in"]=n.passAs,s.name=n.keyname||r,i=!0;else if("basicAuth"===n.type)s.type="basicAuth",i=!0;else if("oauth2"===n.type){var o,a=n.scopes||[],p={};for(o in a){var u=a[o];p[u.scope]=u.description}if(s.type="oauth2",o>0&&(s.scopes=p),n.grantTypes){if(n.grantTypes.implicit){var c=n.grantTypes.implicit;s.flow="implicit",s.authorizationUrl=c.loginEndpoint,i=!0}if(n.grantTypes.authorization_code&&!s.flow){var f=n.grantTypes.authorization_code;s.flow="accessCode",s.authorizationUrl=f.tokenRequestEndpoint.url,s.tokenUrl=f.tokenEndpoint.url,i=!0}}}i&&(t.securityDefinitions=t.securityDefinitions||{},t.securityDefinitions[r]=s)}}},SwaggerSpecConverter.prototype.apiInfo=function(e,t){if(e.info){var r=e.info;t.info={},r.contact&&(t.info.contact={},t.info.contact.email=r.contact),r.description&&(t.info.description=r.description),r.title&&(t.info.title=r.title),r.termsOfServiceUrl&&(t.info.termsOfService=r.termsOfServiceUrl),(r.license||r.licenseUrl)&&(t.license={},r.license&&(t.license.name=r.license),r.licenseUrl&&(t.license.url=r.licenseUrl))}else this.warnings.push("missing info section")},SwaggerSpecConverter.prototype.finish=function(e,t){e(t)};
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
},{"./http":5,"lodash-compat/lang/isObject":144}],9:[function(require,module,exports){
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
},{"../helpers":4,"../schema-markup.js":7,"js-yaml":19,"lodash-compat/lang/isPlainObject":145,"lodash-compat/lang/isString":146}],10:[function(require,module,exports){
|
|
46
|
-
"use strict";function itemByPriority(e,t){if(_.isEmpty(t))return e[0];for(var r=0,i=t.length;i>r;r++)if(e.indexOf(t[r])>-1)return t[r];return e[0]}var _={cloneDeep:require("lodash-compat/lang/cloneDeep"),isUndefined:require("lodash-compat/lang/isUndefined"),isEmpty:require("lodash-compat/lang/isEmpty"),isObject:require("lodash-compat/lang/isObject")},helpers=require("../helpers"),Model=require("./model"),SwaggerHttp=require("../http"),Q=require("q"),Operation=module.exports=function(e,t,r,i,s,n,o,a,p){var l=[];e=e||{},n=n||{},e&&e.options&&(this.client=e.options.client||null,this.requestInterceptor=e.options.requestInterceptor||null,this.responseInterceptor=e.options.responseInterceptor||null,this.requestAgent=e.options.requestAgent),this.authorizations=n.security,this.basePath=e.basePath||"/",this.clientAuthorizations=p,this.consumes=n.consumes||e.consumes||["application/json"],this.produces=n.produces||e.produces||["application/json"],this.deprecated=n.deprecated,this.description=n.description,this.host=e.host,this.method=i||l.push("Operation "+r+" is missing method."),this.models=a||{},this.nickname=r||l.push("Operations must have a nickname."),this.operation=n,this.operations={},this.parameters=null!==n?n.parameters||[]:{},this.parent=e,this.path=s||l.push("Operation "+this.nickname+" is missing path."),this.responses=n.responses||{},this.scheme=t||e.scheme||"http",this.schemes=n.schemes||e.schemes,this.security=n.security||e.security,this.summary=n.summary||"",this.timeout=e.timeout,this.type=null,this.useJQuery=e.useJQuery,this.jqueryAjaxCache=e.jqueryAjaxCache,this.enableCookies=e.enableCookies;var u;if(this.host||("undefined"!=typeof window?this.host=window.location.host:this.host="localhost"),this.parameterMacro=e.parameterMacro||function(e,t){return t["default"]},this.inlineModels=[],"/"!==this.basePath&&"/"===this.basePath.slice(-1)&&(this.basePath=this.basePath.slice(0,-1)),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0;break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}var h,c;if(o)for(u in o)c=new Model(u,o[u],this.models,e.modelPropertyMacro),c&&(this.models[u]=c);else o={};for(h=0;h<this.parameters.length;h++){var d,f=this.parameters[h];f["default"]=this.parameterMacro(this,f),"array"===f.type&&(f.isList=!0,f.allowMultiple=!0);var m=this.getType(f);m&&"boolean"===m.toString().toLowerCase()&&(f.allowableValues={},f.isList=!0,f["enum"]=[!0,!1]);for(u in f)helpers.extractExtensions(u,f);"undefined"!=typeof f["x-example"]&&(d=f["x-example"],f["default"]=d),f["x-examples"]&&(d=f["x-examples"]["default"],"undefined"!=typeof d&&(f["default"]=d));var y=f["enum"]||f.items&&f.items["enum"];if("undefined"!=typeof y){var g;for(f.allowableValues={},f.allowableValues.values=[],f.allowableValues.descriptiveValues=[],g=0;g<y.length;g++){var v=y[g],b=v===f["default"]||v+""===f["default"];f.allowableValues.values.push(v),f.allowableValues.descriptiveValues.push({value:v+"",isDefault:b})}}"array"===f.type&&(m=[m],"undefined"==typeof f.allowableValues&&(delete f.isList,delete f.allowMultiple)),f.modelSignature={type:m,definitions:this.models},f.signature=this.getModelSignature(m,this.models).toString(),f.sampleJSON=this.getModelSampleJSON(m,this.models),f.responseClassSignature=f.signature}var x,O,C,w=this.responses;w[200]?(C=w[200],O="200"):w[201]?(C=w[201],O="201"):w[202]?(C=w[202],O="202"):w[203]?(C=w[203],O="203"):w[204]?(C=w[204],O="204"):w[205]?(C=w[205],O="205"):w[206]?(C=w[206],O="206"):w["default"]&&(C=w["default"],O="default");for(x in w)if(helpers.extractExtensions(x,w),"string"==typeof x&&-1===x.indexOf("x-")){var A=w[x];if("object"==typeof A&&"object"==typeof A.headers){var M=A.headers;for(var P in M){var j=M[P];if("object"==typeof j)for(var q in j)helpers.extractExtensions(q,j)}}}if(C)for(x in C)helpers.extractExtensions(x,C);if(C&&C.schema){var Q,k=this.resolveModel(C.schema,o);delete w[O],k?(this.successResponse={},Q=this.successResponse[O]=k):C.schema.type&&"object"!==C.schema.type&&"array"!==C.schema.type?(this.successResponse={},Q=this.successResponse[O]=C.schema):(this.successResponse={},Q=this.successResponse[O]=new Model(void 0,C.schema||{},this.models,e.modelPropertyMacro)),Q&&(Q.vendorExtensions=C.vendorExtensions,C.description&&(Q.description=C.description),C.examples&&(Q.examples=C.examples),C.headers&&(Q.headers=C.headers)),this.type=C}return l.length>0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(l),this};Operation.prototype.isDefaultArrayItemValue=function(e,t){return t["default"]&&Array.isArray(t["default"])?-1!==t["default"].indexOf(e):e===t["default"]},Operation.prototype.getType=function(e){var t,r=e.type,i=e.format,s=!1;"integer"===r&&"int32"===i?t="integer":"integer"===r&&"int64"===i?t="long":"integer"===r?t="integer":"string"===r?t="date-time"===i?"date-time":"date"===i?"date":"string":"number"===r&&"float"===i?t="float":"number"===r&&"double"===i?t="double":"number"===r?t="double":"boolean"===r?t="boolean":"array"===r?(s=!0,e.items&&(t=this.getType(e.items))):"file"===r&&(t="file"),e.$ref&&(t=helpers.simpleRef(e.$ref));var n=e.schema;if(n){var o=n.$ref;return o?(o=helpers.simpleRef(o),s?[o]:o):"object"===n.type?this.addInlineModel(n):this.getType(n)}return s?[t]:t},Operation.prototype.addInlineModel=function(e){var t=this.inlineModels.length,r=this.resolveModel(e,{});return r?(this.inlineModels.push(r),"Inline Model "+t):null},Operation.prototype.getInlineModel=function(e){if(/^Inline Model \d+$/.test(e)){var t=parseInt(e.substr("Inline Model".length).trim(),10),r=this.inlineModels[t];return r}return null},Operation.prototype.resolveModel=function(e,t){if("undefined"!=typeof e.$ref){var r=e.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),t[r])return new Model(r,t[r],this.models,this.parent.modelPropertyMacro)}else if(e&&"object"==typeof e&&("object"===e.type||_.isUndefined(e.type)))return new Model(void 0,e,this.models,this.parent.modelPropertyMacro);return null},Operation.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",r=0;r<this.parameters.length;r++){var i=this.parameters[r],s=i.signature;t+="\n * "+i.name+" ("+s+"): "+i.description}return"undefined"==typeof e&&helpers.log(t),t},Operation.prototype.getModelSignature=function(e,t){var r,i;return e instanceof Array&&(i=!0,e=e[0]),"undefined"==typeof e?(e="undefined",r=!0):t[e]?(e=t[e],r=!1):this.getInlineModel(e)?(e=this.getInlineModel(e),r=!1):r=!0,r?i?"Array["+e+"]":e.toString():i?"Array["+e.getMockSignature()+"]":e.getMockSignature()},Operation.prototype.supportHeaderParams=function(){return!0},Operation.prototype.supportedSubmitMethods=function(){return this.parent.supportedSubmitMethods},Operation.prototype.getHeaderParams=function(e){for(var t=this.setContentTypes(e,{}),r={},i=0;i<this.parameters.length;i++){var s=this.parameters[i];"header"===s["in"]&&(r[s.name.toLowerCase()]=s)}for(var n in e){var o=r[n.toLowerCase()];if("undefined"!=typeof o){var a=e[n];Array.isArray(a)&&(a=a.toString()),t[o.name]=a}}return t},Operation.prototype.urlify=function(e,t){for(var r={},i=this.path.replace(/#.*/,""),s="",n=0;n<this.parameters.length;n++){var o=this.parameters[n];if("undefined"!=typeof e[o.name]){var a;if("string"===o.type&&"password"===o.format&&t&&(a=!0),"path"===o["in"]){var p=new RegExp("{"+o.name+"}","gi"),l=e[o.name];Array.isArray(l)?l=this.encodePathCollection(o.collectionFormat,o.name,l,a):"undefined"!=typeof o["x-escape"]&&o["x-escape"]!==!0||(l=this.encodePathParam(l,a)),i=i.replace(p,l)}else if("query"===o["in"]&&"undefined"!=typeof e[o.name])if(s+=""===s&&i.indexOf("?")<0?"?":"&","undefined"!=typeof o.collectionFormat){var u=e[o.name];s+=Array.isArray(u)?this.encodeQueryCollection(o.collectionFormat,o.name,u,a):this.encodeQueryKey(o.name)+"="+this.encodeQueryParam(e[o.name],a)}else s+=this.encodeQueryKey(o.name)+"="+this.encodeQueryParam(e[o.name],a);else"formData"===o["in"]&&(r[o.name]=e[o.name])}else if("query"===o["in"]&&"undefined"==typeof e[o.name]&&o.allowEmptyValue===!0)if(s+=""===s&&i.indexOf("?")<0?"?":"&","undefined"!=typeof o.collectionFormat||"array"===o.type){var u,h=o.collectionFormat||"multi";s+=Array.isArray(u)?this.encodeQueryCollection(h,o.name,u,a):this.encodeQueryCollection(h,o.name,[u],a)}else s+=this.encodeQueryKey(o.name)+"="+this.encodeQueryParam("",a)}var c=this.scheme+"://"+this.host;return"/"!==this.basePath&&(c+=this.basePath),c+i+s},Operation.prototype.getMissingParams=function(e){var t,r=[];for(t=0;t<this.parameters.length;t++){var i=this.parameters[t];i.required===!0&&"undefined"==typeof e[i.name]&&(r=i.name)}return r},Operation.prototype.getBody=function(e,t,r){for(var i,s,n,o,a,p={},l=!1,u=0;u<this.parameters.length;u++)if(s=this.parameters[u],"undefined"!=typeof t[s.name]){var h;"string"===s.type&&"password"===s.format&&(h="password"),"body"===s["in"]?n=t[s.name]:"formData"===s["in"]&&(p[s.name]={param:s,value:t[s.name],password:h},i=!0)}else"body"===s["in"]&&(l=!0);if(l&&"undefined"==typeof n){var c=e["Content-Type"];c&&0===c.indexOf("application/json")&&(n="{}")}var d=!1;if(e["Content-Type"]&&e["Content-Type"].indexOf("multipart/form-data")>=0&&(d=!0),i&&!d){var f="";for(o in p){s=p[o].param,a=p[o].value;var m;r&&r.maskPasswords&&(m=p[o].password),"undefined"!=typeof a&&(Array.isArray(a)?(""!==f&&(f+="&"),f+=this.encodeQueryCollection(s.collectionFormat,o,a,m)):(""!==f&&(f+="&"),f+=encodeURIComponent(o)+"="+mask(encodeURIComponent(a),m)))}n=f}else if(d){var y;if("function"==typeof FormData){y=new FormData,y.type="formData";for(o in p)if(s=p[o].param,a=t[o],"undefined"!=typeof a)if("[object File]"==={}.toString.apply(a))y.append(o,a);else if("file"===a.type&&a.value)y.append(o,a.value);else if(Array.isArray(a))if("multi"===s.collectionFormat){y["delete"](o);for(var g in a)y.append(o,a[g])}else y.append(o,this.encodeQueryCollection(s.collectionFormat,o,a).split("=").slice(1).join("="));else y.append(o,a);n=y}else{y={};for(o in p)if(a=t[o],Array.isArray(a)){var v,b=s.collectionFormat||"multi";if("ssv"===b)v=" ";else if("pipes"===b)v="|";else if("tsv"===b)v=" ";else{if("multi"===b){y[o]=a;break}v=","}var x;a.forEach(function(e){x?x+=v:x="",x+=e}),y[o]=x}else y[o]=a;n=y}e["Content-Type"]="multipart/form-data"}return n},Operation.prototype.getModelSampleJSON=function(e,t){var r,i,s;if(t=t||{},r=e instanceof Array,s=r?e[0]:e,t[s]?i=t[s].createJSONSample():this.getInlineModel(s)&&(i=this.getInlineModel(s).createJSONSample()),i){if(i=r?[i]:i,"string"==typeof i)return i;if(_.isObject(i)){var n=i;if(i instanceof Array&&i.length>0&&(n=i[0]),n.nodeName&&"Node"==typeof n){var o=(new XMLSerializer).serializeToString(n);return this.formatXml(o)}return JSON.stringify(i,null,2)}return i}},Operation.prototype["do"]=function(e,t,r,i,s){return this.execute(e,t,r,i,s)},Operation.prototype.execute=function(e,t,r,i,s){var n,o,a,p,l=e||{},u={};_.isObject(t)&&(u=t,n=r,o=i),p="undefined"!=typeof u.timeout?u.timeout:this.timeout,this.client&&(u.client=this.client),this.requestAgent&&(u.requestAgent=this.requestAgent),!u.requestInterceptor&&this.requestInterceptor&&(u.requestInterceptor=this.requestInterceptor),!u.responseInterceptor&&this.responseInterceptor&&(u.responseInterceptor=this.responseInterceptor),"function"==typeof t&&(n=t,o=r),this.parent.usePromise?a=Q.defer():(n=n||this.parent.defaultSuccessCallback||helpers.log,o=o||this.parent.defaultErrorCallback||helpers.log),"undefined"==typeof u.useJQuery&&(u.useJQuery=this.useJQuery),"undefined"==typeof u.jqueryAjaxCache&&(u.jqueryAjaxCache=this.jqueryAjaxCache),"undefined"==typeof u.enableCookies&&(u.enableCookies=this.enableCookies);var h=this.getMissingParams(l);if(h.length>0){var c="missing required params: "+h;return helpers.fail(c),this.parent.usePromise?(a.reject(c),a.promise):(o(c,s),{})}var d,f=this.getHeaderParams(l),m=this.setContentTypes(l,u),y={};for(d in f)y[d]=f[d];for(d in m)y[d]=m[d];var g=this.getBody(m,l,u),v=this.urlify(l,u.maskPasswords);if(v.indexOf(".{format}")>0&&y){var b=y.Accept||y.accept;b&&b.indexOf("json")>0?v=v.replace(".{format}",".json"):b&&b.indexOf("xml")>0&&(v=v.replace(".{format}",".xml"))}var x={url:v,method:this.method.toUpperCase(),body:g,enableCookies:u.enableCookies,useJQuery:u.useJQuery,jqueryAjaxCache:u.jqueryAjaxCache,deferred:a,headers:y,clientAuthorizations:u.clientAuthorizations,operation:this,connectionAgent:this.connectionAgent,on:{response:function(e){return a?(a.resolve(e),a.promise):n(e,s)},error:function(e){return a?(a.reject(e),a.promise):o(e,s)}}};return p&&(x.timeout=p),this.clientAuthorizations.apply(x,this.operation.security),u.mock===!0?(u.requestInterceptor&&u.requestInterceptor.apply(x),x):(new SwaggerHttp).execute(x,u)},Operation.prototype.setContentTypes=function(e,t){var r,i,s=this.parameters,n=e.parameterContentType||itemByPriority(this.consumes,["application/json","application/yaml"]),o=t.responseContentType||itemByPriority(this.produces,["application/json","application/yaml"]),a=[],p=[],l={};for(i=0;i<s.length;i++){var u=s[i];if("formData"===u["in"])"file"===u.type?a.push(u):p.push(u);else if("header"===u["in"]&&t){var h=u.name,c=t[u.name];"undefined"!=typeof t[u.name]&&(l[h]=c)}else"body"===u["in"]&&"undefined"!=typeof e[u.name]&&(r=e[u.name])}var d=r||a.length||p.length;if("post"===this.method||"put"===this.method||"patch"===this.method||("delete"===this.method||"get"===this.method)&&d){if(t.requestContentType&&(n=t.requestContentType),p.length>0){if(n=void 0,t.requestContentType)n=t.requestContentType;else if(a.length>0)n="multipart/form-data";else if(this.consumes&&this.consumes.length>0)for(var f in this.consumes){var m=this.consumes[f];0!==m.indexOf("application/x-www-form-urlencoded")&&0!==m.indexOf("multipart/form-data")||(n=m)}"undefined"==typeof n&&(n="application/x-www-form-urlencoded")}}else n=null;return n&&this.consumes&&-1===this.consumes.indexOf(n)&&helpers.log("server doesn't consume "+n+", try "+JSON.stringify(this.consumes)),this.matchesAccept(o)||helpers.log("server can't produce "+o),n&&""!==r||"application/x-www-form-urlencoded"===n?l["Content-Type"]=n:this.consumes&&this.consumes.length>0&&"application/x-www-form-urlencoded"===this.consumes[0]&&(l["Content-Type"]=this.consumes[0]),o&&(l.Accept=o),l},Operation.prototype.matchesAccept=function(e){return e&&this.produces?-1!==this.produces.indexOf(e)||-1!==this.produces.indexOf("*/*"):!0},Operation.prototype.asCurl=function(e,t){var r={mock:!0,maskPasswords:!0};if("object"==typeof t)for(var i in t)r[i]=t[i];var s=this.execute(e,r);this.clientAuthorizations.apply(s,this.operation.security);var n=[];if(n.push("-X "+this.method.toUpperCase()),"undefined"!=typeof s.headers){var o;for(o in s.headers){var a=s.headers[o];"string"==typeof a&&(a=a.replace(/\'/g,"\\u0027")),n.push("--header '"+o+": "+a+"'")}}var p=!1,l=!1,u=s.headers["Content-Type"];if(u&&0===u.indexOf("application/x-www-form-urlencoded")?p=!0:u&&0===u.indexOf("multipart/form-data")&&(p=!0,l=!0),s.body){var h;if(_.isObject(s.body)){if(l){l=!0;for(var c=0;c<this.parameters.length;c++){var d=this.parameters[c];if("formData"===d["in"]){h||(h="");var f;if(f="function"==typeof FormData&&s.body instanceof FormData?s.body.getAll(d.name):s.body[d.name])if("file"===d.type)f.name&&(h+="-F "+d.name+'=@"'+f.name+'" ');else if(Array.isArray(f))if("multi"===d.collectionFormat)for(var m in f)h+="-F "+this.encodeQueryKey(d.name)+"="+mask(f[m],d.format)+" ";else h+="-F "+this.encodeQueryCollection(d.collectionFormat,d.name,mask(f,d.format))+" ";else h+="-F "+this.encodeQueryKey(d.name)+"="+mask(f,d.format)+" "}}}h||(h=JSON.stringify(s.body))}else h=s.body;h=h.replace(/\'/g,"%27").replace(/\n/g," \\ \n "),p||(h=h.replace(/&/g,"%26")),l?n.push(h):n.push("-d '"+h.replace(/@/g,"%40")+"'")}return"curl "+n.join(" ")+" '"+s.url+"'"},Operation.prototype.encodePathCollection=function(e,t,r,i){var s,n="",o="";for(o="ssv"===e?"%20":"tsv"===e?"%09":"pipes"===e?"|":",",s=0;s<r.length;s++)0===s?n=this.encodeQueryParam(r[s],i):n+=o+this.encodeQueryParam(r[s],i);return n},Operation.prototype.encodeQueryCollection=function(e,t,r,i){var s,n="";if(e=e||"default","default"===e||"multi"===e)for(s=0;s<r.length;s++)s>0&&(n+="&"),n+=this.encodeQueryKey(t)+"="+mask(this.encodeQueryParam(r[s]),i);else{var o="";if("csv"===e)o=",";else if("ssv"===e)o="%20";else if("tsv"===e)o="%09";else if("pipes"===e)o="|";else if("brackets"===e)for(s=0;s<r.length;s++)0!==s&&(n+="&"),n+=this.encodeQueryKey(t)+"[]="+mask(this.encodeQueryParam(r[s]),i);if(""!==o)for(s=0;s<r.length;s++)0===s?n=this.encodeQueryKey(t)+"="+this.encodeQueryParam(r[s]):n+=o+this.encodeQueryParam(r[s])}return n},Operation.prototype.encodeQueryKey=function(e){return encodeURIComponent(e).replace("%5B","[").replace("%5D","]").replace("%24","$")},Operation.prototype.encodeQueryParam=function(e,t){return t?"******":void 0!==e&&null!==e?encodeURIComponent(e):""},Operation.prototype.encodePathParam=function(e,t){return encodeURIComponent(e,t)};var mask=function(e,t){return"string"==typeof t&&"password"===t?"******":e};
|
|
46
|
+
"use strict";function itemByPriority(e,t){if(_.isEmpty(t))return e[0];for(var r=0,i=t.length;i>r;r++)if(e.indexOf(t[r])>-1)return t[r];return e[0]}var _={cloneDeep:require("lodash-compat/lang/cloneDeep"),isUndefined:require("lodash-compat/lang/isUndefined"),isEmpty:require("lodash-compat/lang/isEmpty"),isObject:require("lodash-compat/lang/isObject")},helpers=require("../helpers"),Model=require("./model"),SwaggerHttp=require("../http"),Q=require("q"),Operation=module.exports=function(e,t,r,i,n,s,o,a,p){var l=[];if(e=e||{},s=s||{},e&&e.options&&(this.client=e.options.client||null,this.requestInterceptor=e.options.requestInterceptor||null,this.responseInterceptor=e.options.responseInterceptor||null),this.authorizations=s.security,this.basePath=e.basePath||"/",this.clientAuthorizations=p,this.consumes=s.consumes||e.consumes||["application/json"],this.produces=s.produces||e.produces||["application/json"],this.deprecated=s.deprecated,this.description=s.description,this.host=e.host,this.method=i||l.push("Operation "+r+" is missing method."),this.models=a||{},this.nickname=r||l.push("Operations must have a nickname."),this.operation=s,this.operations={},this.parameters=null!==s?s.parameters||[]:{},this.parent=e,this.path=n||l.push("Operation "+this.nickname+" is missing path."),this.responses=s.responses||{},this.scheme=t||e.scheme||"http",this.schemes=s.schemes||e.schemes,this.security=s.security||e.security,this.summary=s.summary||"",this.timeout=e.timeout,this.type=null,this.useJQuery=e.useJQuery,this.jqueryAjaxCache=e.jqueryAjaxCache,this.enableCookies=e.enableCookies,this.host||("undefined"!=typeof window?this.host=window.location.host:this.host="localhost"),this.parameterMacro=e.parameterMacro||function(e,t){return t["default"]},this.inlineModels=[],"/"!==this.basePath&&"/"===this.basePath.slice(-1)&&(this.basePath=this.basePath.slice(0,-1)),"string"==typeof this.deprecated)switch(this.deprecated.toLowerCase()){case"true":case"yes":case"1":this.deprecated=!0;break;case"false":case"no":case"0":case null:this.deprecated=!1;break;default:this.deprecated=Boolean(this.deprecated)}var u,h;if(o){var c;for(c in o)h=new Model(c,o[c],this.models,e.modelPropertyMacro),h&&(this.models[c]=h)}else o={};for(u=0;u<this.parameters.length;u++){var d=this.parameters[u];d["default"]=this.parameterMacro(this,d),"array"===d.type&&(d.isList=!0,d.allowMultiple=!0);var f=this.getType(d);if(f&&"boolean"===f.toString().toLowerCase()&&(d.allowableValues={},d.isList=!0,d["enum"]=[!0,!1]),"undefined"!=typeof d["x-example"]){var m=d["x-example"];d["default"]=m}if(d["x-examples"]){var m=d["x-examples"]["default"];"undefined"!=typeof m&&(d["default"]=m)}var y=d["enum"]||d.items&&d.items["enum"];if("undefined"!=typeof y){var g;for(d.allowableValues={},d.allowableValues.values=[],d.allowableValues.descriptiveValues=[],g=0;g<y.length;g++){var v=y[g],b=v===d["default"]||v+""===d["default"];d.allowableValues.values.push(v),d.allowableValues.descriptiveValues.push({value:v+"",isDefault:b})}}"array"===d.type&&(f=[f],"undefined"==typeof d.allowableValues&&(delete d.isList,delete d.allowMultiple)),d.modelSignature={type:f,definitions:this.models},d.signature=this.getModelSignature(f,this.models).toString(),d.sampleJSON=this.getModelSampleJSON(f,this.models),d.responseClassSignature=d.signature}var O,C,x=this.responses;if(x[200]?(C=x[200],O="200"):x[201]?(C=x[201],O="201"):x[202]?(C=x[202],O="202"):x[203]?(C=x[203],O="203"):x[204]?(C=x[204],O="204"):x[205]?(C=x[205],O="205"):x[206]?(C=x[206],O="206"):x["default"]&&(C=x["default"],O="default"),C&&C.schema){var w,M=this.resolveModel(C.schema,o);delete x[O],M?(this.successResponse={},w=this.successResponse[O]=M):C.schema.type&&"object"!==C.schema.type&&"array"!==C.schema.type?(this.successResponse={},w=this.successResponse[O]=C.schema):(this.successResponse={},w=this.successResponse[O]=new Model(void 0,C.schema||{},this.models,e.modelPropertyMacro)),w&&(C.description&&(w.description=C.description),C.examples&&(w.examples=C.examples),C.headers&&(w.headers=C.headers)),this.type=C}return l.length>0&&this.resource&&this.resource.api&&this.resource.api.fail&&this.resource.api.fail(l),this};Operation.prototype.isDefaultArrayItemValue=function(e,t){return t["default"]&&Array.isArray(t["default"])?-1!==t["default"].indexOf(e):e===t["default"]},Operation.prototype.getType=function(e){var t,r=e.type,i=e.format,n=!1;"integer"===r&&"int32"===i?t="integer":"integer"===r&&"int64"===i?t="long":"integer"===r?t="integer":"string"===r?t="date-time"===i?"date-time":"date"===i?"date":"string":"number"===r&&"float"===i?t="float":"number"===r&&"double"===i?t="double":"number"===r?t="double":"boolean"===r?t="boolean":"array"===r?(n=!0,e.items&&(t=this.getType(e.items))):"file"===r&&(t="file"),e.$ref&&(t=helpers.simpleRef(e.$ref));var s=e.schema;if(s){var o=s.$ref;return o?(o=helpers.simpleRef(o),n?[o]:o):"object"===s.type?this.addInlineModel(s):this.getType(s)}return n?[t]:t},Operation.prototype.addInlineModel=function(e){var t=this.inlineModels.length,r=this.resolveModel(e,{});return r?(this.inlineModels.push(r),"Inline Model "+t):null},Operation.prototype.getInlineModel=function(e){if(/^Inline Model \d+$/.test(e)){var t=parseInt(e.substr("Inline Model".length).trim(),10),r=this.inlineModels[t];return r}return null},Operation.prototype.resolveModel=function(e,t){if("undefined"!=typeof e.$ref){var r=e.$ref;if(0===r.indexOf("#/definitions/")&&(r=r.substring("#/definitions/".length)),t[r])return new Model(r,t[r],this.models,this.parent.modelPropertyMacro)}else if(e&&"object"==typeof e&&("object"===e.type||_.isUndefined(e.type)))return new Model(void 0,e,this.models,this.parent.modelPropertyMacro);return null},Operation.prototype.help=function(e){for(var t=this.nickname+": "+this.summary+"\n",r=0;r<this.parameters.length;r++){var i=this.parameters[r],n=i.signature;t+="\n * "+i.name+" ("+n+"): "+i.description}return"undefined"==typeof e&&helpers.log(t),t},Operation.prototype.getModelSignature=function(e,t){var r,i;return e instanceof Array&&(i=!0,e=e[0]),"undefined"==typeof e?(e="undefined",r=!0):t[e]?(e=t[e],r=!1):this.getInlineModel(e)?(e=this.getInlineModel(e),r=!1):r=!0,r?i?"Array["+e+"]":e.toString():i?"Array["+e.getMockSignature()+"]":e.getMockSignature()},Operation.prototype.supportHeaderParams=function(){return!0},Operation.prototype.supportedSubmitMethods=function(){return this.parent.supportedSubmitMethods},Operation.prototype.getHeaderParams=function(e){for(var t=this.setContentTypes(e,{}),r={},i=0;i<this.parameters.length;i++){var n=this.parameters[i];"header"===n["in"]&&(r[n.name.toLowerCase()]=n)}for(var s in e){var o=r[s.toLowerCase()];if("undefined"!=typeof o){var a=e[s];Array.isArray(a)&&(a=a.toString()),t[o.name]=a}}return t},Operation.prototype.urlify=function(e){for(var t={},r=this.path.replace(/#.*/,""),i="",n=0;n<this.parameters.length;n++){var s=this.parameters[n];if("undefined"!=typeof e[s.name])if("path"===s["in"]){var o=new RegExp("{"+s.name+"}","gi"),a=e[s.name];a=Array.isArray(a)?this.encodePathCollection(s.collectionFormat,s.name,a):this.encodePathParam(a),r=r.replace(o,a)}else if("query"===s["in"]&&"undefined"!=typeof e[s.name])if(i+=""===i&&r.indexOf("?")<0?"?":"&","undefined"!=typeof s.collectionFormat){var p=e[s.name];i+=Array.isArray(p)?this.encodeQueryCollection(s.collectionFormat,s.name,p):this.encodeQueryKey(s.name)+"="+this.encodeQueryParam(e[s.name])}else i+=this.encodeQueryKey(s.name)+"="+this.encodeQueryParam(e[s.name]);else"formData"===s["in"]&&(t[s.name]=e[s.name])}var l=this.scheme+"://"+this.host;return"/"!==this.basePath&&(l+=this.basePath),l+r+i},Operation.prototype.getMissingParams=function(e){var t,r=[];for(t=0;t<this.parameters.length;t++){var i=this.parameters[t];i.required===!0&&"undefined"==typeof e[i.name]&&(r=i.name)}return r},Operation.prototype.getBody=function(e,t,r){for(var i,n,s,o,a={},p=!1,l=0;l<this.parameters.length;l++){var u=this.parameters[l];"undefined"!=typeof t[u.name]?"body"===u["in"]?n=t[u.name]:"formData"===u["in"]&&(a[u.name]={param:u,value:t[u.name]},i=!0):"body"===u["in"]&&(p=!0)}if(p&&"undefined"==typeof n){var h=e["Content-Type"];h&&0===h.indexOf("application/json")&&(n="{}")}var c=!1;if(e["Content-Type"]&&e["Content-Type"].indexOf("multipart/form-data")>=0&&(c=!0),i&&!c){var d="";for(s in a){var u=a[s].param;o=a[s].value,"undefined"!=typeof o&&(Array.isArray(o)?(""!==d&&(d+="&"),d+=this.encodeQueryCollection(u.collectionFormat,s,o)):(""!==d&&(d+="&"),d+=encodeURIComponent(s)+"="+encodeURIComponent(o)))}n=d}else if(c){var f;if("function"==typeof FormData){f=new FormData,f.type="formData";for(s in a){var u=a[s].param;if(o=t[s],"undefined"!=typeof o)if("[object File]"==={}.toString.apply(o))f.append(s,o);else if("file"===o.type&&o.value)f.append(s,o.value);else if(Array.isArray(o))if("multi"===u.collectionFormat){f["delete"](s);for(var m in o)f.append(s,o[m])}else f.append(s,this.encodeQueryCollection(u.collectionFormat,s,o).split("=").slice(1).join("="));else f.append(s,o)}n=f}else{f={};for(s in a)if(o=t[s],Array.isArray(o)){var y,g=u.collectionFormat||"multi";if("ssv"===g)y=" ";else if("pipes"===g)y="|";else if("tsv"===g)y=" ";else{if("multi"===g){f[s]=o;break}y=","}var v;o.forEach(function(e){v?v+=y:v="",v+=e}),f[s]=v}else f[s]=o;n=f}e["Content-Type"]="multipart/form-data"}return n},Operation.prototype.getModelSampleJSON=function(e,t){var r,i,n;if(t=t||{},r=e instanceof Array,n=r?e[0]:e,t[n]?i=t[n].createJSONSample():this.getInlineModel(n)&&(i=this.getInlineModel(n).createJSONSample()),i){if(i=r?[i]:i,"string"==typeof i)return i;if(_.isObject(i)){var s=i;if(i instanceof Array&&i.length>0&&(s=i[0]),s.nodeName&&"Node"==typeof s){var o=(new XMLSerializer).serializeToString(s);return this.formatXml(o)}return JSON.stringify(i,null,2)}return i}},Operation.prototype["do"]=function(e,t,r,i,n){return this.execute(e,t,r,i,n)},Operation.prototype.execute=function(e,t,r,i,n){var s,o,a,p,l=e||{},u={};_.isObject(t)&&(u=t,s=r,o=i),p="undefined"!=typeof u.timeout?u.timeout:this.timeout,this.client&&(u.client=this.client),!u.requestInterceptor&&this.requestInterceptor&&(u.requestInterceptor=this.requestInterceptor),!u.responseInterceptor&&this.responseInterceptor&&(u.responseInterceptor=this.responseInterceptor),"function"==typeof t&&(s=t,o=r),this.parent.usePromise?a=Q.defer():(s=s||this.parent.defaultSuccessCallback||helpers.log,o=o||this.parent.defaultErrorCallback||helpers.log),"undefined"==typeof u.useJQuery&&(u.useJQuery=this.useJQuery),"undefined"==typeof u.jqueryAjaxCache&&(u.jqueryAjaxCache=this.jqueryAjaxCache),"undefined"==typeof u.enableCookies&&(u.enableCookies=this.enableCookies);var h=this.getMissingParams(l);if(h.length>0){var c="missing required params: "+h;return helpers.fail(c),this.parent.usePromise?(a.reject(c),a.promise):(o(c,n),{})}var d,f=this.getHeaderParams(l),m=this.setContentTypes(l,u),y={};for(d in f)y[d]=f[d];for(d in m)y[d]=m[d];var g=this.getBody(m,l,u),v=this.urlify(l);if(v.indexOf(".{format}")>0&&y){var b=y.Accept||y.accept;b&&b.indexOf("json")>0?v=v.replace(".{format}",".json"):b&&b.indexOf("xml")>0&&(v=v.replace(".{format}",".xml"))}var O={url:v,method:this.method.toUpperCase(),body:g,enableCookies:u.enableCookies,useJQuery:u.useJQuery,jqueryAjaxCache:u.jqueryAjaxCache,deferred:a,headers:y,clientAuthorizations:u.clientAuthorizations,on:{response:function(e){return a?(a.resolve(e),a.promise):s(e,n)},error:function(e){return a?(a.reject(e),a.promise):o(e,n)}}};return p&&(O.timeout=p),this.clientAuthorizations.apply(O,this.operation.security),u.mock===!0?O:(new SwaggerHttp).execute(O,u)},Operation.prototype.setContentTypes=function(e,t){var r,i,n=this.parameters,s=e.parameterContentType||itemByPriority(this.consumes,["application/json","application/yaml"]),o=t.responseContentType||itemByPriority(this.produces,["application/json","application/yaml"]),a=[],p=[],l={};for(i=0;i<n.length;i++){var u=n[i];if("formData"===u["in"])"file"===u.type?a.push(u):p.push(u);else if("header"===u["in"]&&t){var h=u.name,c=t[u.name];"undefined"!=typeof t[u.name]&&(l[h]=c)}else"body"===u["in"]&&"undefined"!=typeof e[u.name]&&(r=e[u.name])}var d=r||a.length||p.length;if("post"===this.method||"put"===this.method||"patch"===this.method||("delete"===this.method||"get"===this.method)&&d){if(t.requestContentType&&(s=t.requestContentType),p.length>0){if(s=void 0,t.requestContentType)s=t.requestContentType;else if(a.length>0)s="multipart/form-data";else if(this.consumes&&this.consumes.length>0)for(var f in this.consumes){var m=this.consumes[f];0!==m.indexOf("application/x-www-form-urlencoded")&&0!==m.indexOf("multipart/form-data")||(s=m)}"undefined"==typeof s&&(s="application/x-www-form-urlencoded")}}else s=null;return s&&this.consumes&&-1===this.consumes.indexOf(s)&&helpers.log("server doesn't consume "+s+", try "+JSON.stringify(this.consumes)),this.matchesAccept(o)||helpers.log("server can't produce "+o),s&&""!==r||"application/x-www-form-urlencoded"===s?l["Content-Type"]=s:this.consumes&&this.consumes.length>0&&"application/x-www-form-urlencoded"===this.consumes[0]&&(l["Content-Type"]=this.consumes[0]),o&&(l.Accept=o),l},Operation.prototype.matchesAccept=function(e){return e&&this.produces?-1!==this.produces.indexOf(e)||-1!==this.produces.indexOf("*/*"):!0},Operation.prototype.asCurl=function(e,t){var r={mock:!0};if("object"==typeof t)for(var i in t)r[i]=t[i];var n=this.execute(e,r);this.clientAuthorizations.apply(n,this.operation.security);var s=[];if(s.push("-X "+this.method.toUpperCase()),"undefined"!=typeof n.headers){var o;for(o in n.headers){var a=n.headers[o];"string"==typeof a&&(a=a.replace(/\'/g,"\\u0027")),s.push("--header '"+o+": "+a+"'")}}var p=!1,l=!1,u=n.headers["Content-Type"];if(u&&0===u.indexOf("application/x-www-form-urlencoded")?p=!0:u&&0===u.indexOf("multipart/form-data")&&(p=!0,l=!0),n.body){var h;if(_.isObject(n.body)){if(l){l=!0;for(var c=0;c<this.parameters.length;c++){var d=this.parameters[c];if("formData"===d["in"]){h||(h="");var f;if(f="function"==typeof FormData&&n.body instanceof FormData?n.body.getAll(d.name):n.body[d.name])if("file"===d.type)f.name&&(h+="-F "+d.name+'=@"'+f.name+'" ');else if(Array.isArray(f))if("multi"===d.collectionFormat)for(var m in f)h+="-F "+this.encodeQueryKey(d.name)+"="+f[m]+" ";else h+="-F "+this.encodeQueryCollection(d.collectionFormat,d.name,f)+" ";else h+="-F "+this.encodeQueryKey(d.name)+"="+f+" "}}}h||(h=JSON.stringify(n.body))}else h=n.body;h=h.replace(/\'/g,"%27").replace(/\n/g," \\ \n "),p||(h=h.replace(/&/g,"%26")),l?s.push(h):s.push("-d '"+h.replace(/@/g,"%40")+"'")}return"curl "+s.join(" ")+" '"+n.url+"'"},Operation.prototype.encodePathCollection=function(e,t,r){var i,n="",s="";for(s="ssv"===e?"%20":"tsv"===e?"%09":"pipes"===e?"|":",",i=0;i<r.length;i++)0===i?n=this.encodeQueryParam(r[i]):n+=s+this.encodeQueryParam(r[i]);return n},Operation.prototype.encodeQueryCollection=function(e,t,r){var i,n="";if(e=e||"default","default"===e||"multi"===e)for(i=0;i<r.length;i++)i>0&&(n+="&"),n+=this.encodeQueryKey(t)+"="+this.encodeQueryParam(r[i]);else{var s="";if("csv"===e)s=",";else if("ssv"===e)s="%20";else if("tsv"===e)s="%09";else if("pipes"===e)s="|";else if("brackets"===e)for(i=0;i<r.length;i++)0!==i&&(n+="&"),n+=this.encodeQueryKey(t)+"[]="+this.encodeQueryParam(r[i]);if(""!==s)for(i=0;i<r.length;i++)0===i?n=this.encodeQueryKey(t)+"="+this.encodeQueryParam(r[i]):n+=s+this.encodeQueryParam(r[i])}return n},Operation.prototype.encodeQueryKey=function(e){return encodeURIComponent(e).replace("%5B","[").replace("%5D","]").replace("%24","$")},Operation.prototype.encodeQueryParam=function(e){return encodeURIComponent(e)},Operation.prototype.encodePathParam=function(e){return encodeURIComponent(e)};
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
},{"../helpers":4,"../http":5,"./model":9,"lodash-compat/lang/cloneDeep":138,"lodash-compat/lang/isEmpty":141,"lodash-compat/lang/isObject":144,"lodash-compat/lang/isUndefined":148,"q":157}],11:[function(require,module,exports){
|
package/lib/auth.js
CHANGED
|
@@ -11,7 +11,7 @@ var _ = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* SwaggerAuthorizations
|
|
14
|
+
* SwaggerAuthorizations applys the correct authorization to an operation being executed
|
|
15
15
|
*/
|
|
16
16
|
var SwaggerAuthorizations = module.exports.SwaggerAuthorizations = function (authz) {
|
|
17
17
|
this.authz = authz || {};
|
package/lib/client.js
CHANGED
|
@@ -125,7 +125,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
|
|
|
125
125
|
|
|
126
126
|
if(this.url && this.url.indexOf('http:') === -1 && this.url.indexOf('https:') === -1) {
|
|
127
127
|
// no protocol, so we can only use window if it exists
|
|
128
|
-
if(typeof(window) !== 'undefined' &&
|
|
128
|
+
if(typeof(window) !== 'undefined' && window && window.location) {
|
|
129
129
|
this.url = window.location.origin + this.url;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -136,7 +136,6 @@ SwaggerClient.prototype.initialize = function (url, options) {
|
|
|
136
136
|
this.defaultSuccessCallback = options.defaultSuccessCallback || null;
|
|
137
137
|
this.defaultErrorCallback = options.defaultErrorCallback || null;
|
|
138
138
|
this.modelPropertyMacro = options.modelPropertyMacro || null;
|
|
139
|
-
this.connectionAgent = options.connectionAgent || null;
|
|
140
139
|
this.parameterMacro = options.parameterMacro || null;
|
|
141
140
|
this.usePromise = options.usePromise || null;
|
|
142
141
|
|
|
@@ -202,8 +201,6 @@ SwaggerClient.prototype.build = function (mock) {
|
|
|
202
201
|
var obj = {
|
|
203
202
|
useJQuery: this.useJQuery,
|
|
204
203
|
jqueryAjaxCache: this.jqueryAjaxCache,
|
|
205
|
-
connectionAgent: this.connectionAgent,
|
|
206
|
-
enableCookies: this.enableCookies,
|
|
207
204
|
url: this.url,
|
|
208
205
|
method: 'get',
|
|
209
206
|
headers: {
|
|
@@ -211,7 +208,7 @@ SwaggerClient.prototype.build = function (mock) {
|
|
|
211
208
|
},
|
|
212
209
|
on: {
|
|
213
210
|
error: function (response) {
|
|
214
|
-
if (self
|
|
211
|
+
if (self.url.substring(0, 4) !== 'http') {
|
|
215
212
|
return self.fail('Please specify the protocol for ' + self.url);
|
|
216
213
|
} else if (response.errObj && (response.errObj.code === 'ECONNABORTED' || response.errObj.message.indexOf('timeout') !== -1)) {
|
|
217
214
|
return self.fail('Request timed out after ' + self.fetchSpecTimeout + 'ms');
|
|
@@ -259,7 +256,7 @@ SwaggerClient.prototype.build = function (mock) {
|
|
|
259
256
|
obj.timeout = this.fetchSpecTimeout;
|
|
260
257
|
}
|
|
261
258
|
|
|
262
|
-
if (this.spec
|
|
259
|
+
if (this.spec) {
|
|
263
260
|
self.swaggerObject = this.spec;
|
|
264
261
|
setTimeout(function () {
|
|
265
262
|
new Resolver().resolve(self.spec, self.url, self.buildFromSpec, self);
|
|
@@ -290,77 +287,43 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
|
|
|
290
287
|
this.info = response.info || {};
|
|
291
288
|
this.produces = response.produces;
|
|
292
289
|
this.schemes = response.schemes || [];
|
|
293
|
-
this.securityDefinitions =
|
|
290
|
+
this.securityDefinitions = response.securityDefinitions;
|
|
294
291
|
this.security = response.security;
|
|
295
292
|
this.title = response.title || '';
|
|
296
293
|
|
|
297
|
-
var key, definedTags = {}, k, location, self = this, i;
|
|
298
|
-
|
|
299
294
|
if (response.externalDocs) {
|
|
300
295
|
this.externalDocs = response.externalDocs;
|
|
301
296
|
}
|
|
302
297
|
|
|
303
298
|
// legacy support
|
|
304
|
-
this.authSchemes =
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
var securityDefinition = this.securityDefinitions[key];
|
|
309
|
-
securityDefinition.vendorExtensions = {};
|
|
310
|
-
for(var ext in securityDefinition) {
|
|
311
|
-
helpers.extractExtensions(ext, securityDefinition);
|
|
312
|
-
if (ext === 'scopes') {
|
|
313
|
-
var scopes = securityDefinition[ext];
|
|
314
|
-
if(typeof scopes === 'object') {
|
|
315
|
-
scopes.vendorExtensions = {};
|
|
316
|
-
for (var s in scopes) {
|
|
317
|
-
helpers.extractExtensions(s, scopes);
|
|
318
|
-
if(s.indexOf('x-') === 0) {
|
|
319
|
-
delete scopes[s];
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
299
|
+
this.authSchemes = response.securityDefinitions;
|
|
300
|
+
|
|
301
|
+
var definedTags = {};
|
|
302
|
+
var k;
|
|
327
303
|
|
|
328
304
|
if (Array.isArray(response.tags)) {
|
|
329
305
|
definedTags = {};
|
|
330
306
|
|
|
331
307
|
for (k = 0; k < response.tags.length; k++) {
|
|
332
|
-
var t =
|
|
308
|
+
var t = response.tags[k];
|
|
333
309
|
definedTags[t.name] = t;
|
|
334
|
-
for(i in t) {
|
|
335
|
-
if(i === 'externalDocs' && typeof t[i] === 'object') {
|
|
336
|
-
for(var j in t[i]) {
|
|
337
|
-
helpers.extractExtensions(j, t[i]);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
helpers.extractExtensions(i, t);
|
|
341
|
-
}
|
|
342
310
|
}
|
|
343
311
|
}
|
|
344
312
|
|
|
313
|
+
var location;
|
|
345
314
|
|
|
346
315
|
if (typeof this.url === 'string') {
|
|
347
316
|
location = this.parseUri(this.url);
|
|
348
317
|
if (typeof this.scheme === 'undefined' && typeof this.schemes === 'undefined' || this.schemes.length === 0) {
|
|
349
|
-
if
|
|
350
|
-
this.scheme = location.scheme;
|
|
351
|
-
}
|
|
352
|
-
if(typeof window !== 'undefined' && typeof(window.location) !== 'undefined') {
|
|
318
|
+
if(typeof window !== 'undefined') {
|
|
353
319
|
// use the window scheme
|
|
354
320
|
this.scheme = window.location.protocol.replace(':','');
|
|
355
321
|
}
|
|
356
322
|
else {
|
|
357
323
|
this.scheme = location.scheme || 'http';
|
|
358
324
|
}
|
|
359
|
-
} else if (typeof
|
|
360
|
-
|
|
361
|
-
this.scheme = location.scheme;
|
|
362
|
-
} else if (typeof this.scheme === 'undefined') {
|
|
363
|
-
if(typeof window !== 'undefined' && typeof(window.location) !== 'undefined') {
|
|
325
|
+
} else if (typeof this.scheme === 'undefined') {
|
|
326
|
+
if(typeof window !== 'undefined') {
|
|
364
327
|
var scheme = window.location.protocol.replace(':','');
|
|
365
328
|
if(scheme === 'https' && this.schemes.indexOf(scheme) === -1) {
|
|
366
329
|
// can't call http from https served page in a browser!
|
|
@@ -403,6 +366,8 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
|
|
|
403
366
|
|
|
404
367
|
this.definitions = response.definitions;
|
|
405
368
|
|
|
369
|
+
var key;
|
|
370
|
+
|
|
406
371
|
for (key in this.definitions) {
|
|
407
372
|
var model = new Model(key, this.definitions[key], this.models, this.modelPropertyMacro);
|
|
408
373
|
|
|
@@ -412,6 +377,7 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
|
|
|
412
377
|
}
|
|
413
378
|
|
|
414
379
|
// get paths, create functions for each operationId
|
|
380
|
+
var self = this;
|
|
415
381
|
|
|
416
382
|
// Bind help to 'client.apis'
|
|
417
383
|
self.apis.help = _.bind(self.help, self);
|
|
@@ -453,20 +419,6 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
|
|
|
453
419
|
self.models,
|
|
454
420
|
self.clientAuthorizations);
|
|
455
421
|
|
|
456
|
-
operationObject.connectionAgent = self.connectionAgent;
|
|
457
|
-
operationObject.vendorExtensions = {};
|
|
458
|
-
for(i in operation) {
|
|
459
|
-
helpers.extractExtensions(i, operationObject, operation[i]);
|
|
460
|
-
}
|
|
461
|
-
operationObject.externalDocs = operation.externalDocs;
|
|
462
|
-
if(operationObject.externalDocs) {
|
|
463
|
-
operationObject.externalDocs = _.cloneDeep(operationObject.externalDocs);
|
|
464
|
-
operationObject.externalDocs.vendorExtensions = {};
|
|
465
|
-
for(i in operationObject.externalDocs) {
|
|
466
|
-
helpers.extractExtensions(i, operationObject.externalDocs);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
422
|
// bind self operation's execute command to the api
|
|
471
423
|
_.forEach(tags, function (tag) {
|
|
472
424
|
var clientProperty = _.indexOf(reservedClientTags, tag) > -1 ? '_' + tag : tag;
|
|
@@ -504,7 +456,6 @@ SwaggerClient.prototype.buildFromSpec = function (response) {
|
|
|
504
456
|
if (!_.isUndefined(tagDef)) {
|
|
505
457
|
operationGroup.description = tagDef.description;
|
|
506
458
|
operationGroup.externalDocs = tagDef.externalDocs;
|
|
507
|
-
operationGroup.vendorExtensions = tagDef.vendorExtensions;
|
|
508
459
|
}
|
|
509
460
|
|
|
510
461
|
self[clientProperty].help = _.bind(self.help, operationGroup);
|
|
@@ -709,6 +660,7 @@ SwaggerClient.prototype.setSchemes = function (schemes) {
|
|
|
709
660
|
}
|
|
710
661
|
};
|
|
711
662
|
|
|
663
|
+
|
|
712
664
|
SwaggerClient.prototype.fail = function (message) {
|
|
713
665
|
if (this.usePromise) {
|
|
714
666
|
this.deferredClient.reject(message);
|