swagger-client
Advanced tools
Comparing version 2.1.26 to 2.1.27
@@ -356,3 +356,6 @@ 'use strict'; | ||
} | ||
} else if (typeof this.scheme === 'undefined') { | ||
} else if (typeof window !== 'undefined' && window.location.protocol.startsWith('chrome-extension')) { | ||
// if it is chrome swagger ui extension scheme then let swagger doc url scheme decide the protocol | ||
this.scheme = location.scheme; | ||
} else if (typeof this.scheme === 'undefined') { | ||
if(typeof window !== 'undefined') { | ||
@@ -410,3 +413,3 @@ var scheme = window.location.protocol.replace(':',''); | ||
// get paths, create functions for each operationId | ||
// Bind help to 'client.apis' | ||
@@ -452,2 +455,3 @@ self.apis.help = _.bind(self.help, self); | ||
operationObject.connectionAgent = self.connectionAgent; | ||
operationObject.vendorExtensions = {}; | ||
@@ -454,0 +458,0 @@ for(i in operation) { |
@@ -219,3 +219,2 @@ 'use strict'; | ||
SuperagentHttpClient.prototype.execute = function (obj) { | ||
var connectionAgent = obj.connectionAgent; | ||
var method = obj.method.toLowerCase(); | ||
@@ -229,8 +228,8 @@ var timeout = obj.timeout; | ||
if (connectionAgent) { | ||
request = request.agent(connectionAgent); | ||
var r = request[method](obj.url); | ||
if (obj.connectionAgent) { | ||
r.agent(obj.connectionAgent); | ||
} | ||
var r = request[method](obj.url); | ||
if (timeout) { | ||
@@ -237,0 +236,0 @@ r.timeout(timeout); |
@@ -494,3 +494,3 @@ 'use strict'; | ||
Operation.prototype.urlify = function (args) { | ||
Operation.prototype.urlify = function (args, maskPasswords) { | ||
var formParams = {}; | ||
@@ -504,2 +504,7 @@ var requestUrl = this.path.replace(/#.*/, ''); // remove URL fragment | ||
if (typeof args[param.name] !== 'undefined') { | ||
var isPassword; | ||
if(param.type === 'string' && param.format === 'password' && maskPasswords) { | ||
isPassword = true; | ||
} | ||
if (param.in === 'path') { | ||
@@ -510,5 +515,5 @@ var reg = new RegExp('\{' + param.name + '\}', 'gi'); | ||
if (Array.isArray(value)) { | ||
value = this.encodePathCollection(param.collectionFormat, param.name, value); | ||
value = this.encodePathCollection(param.collectionFormat, param.name, value, isPassword); | ||
} else { | ||
value = this.encodePathParam(value); | ||
value = this.encodePathParam(value, isPassword); | ||
} | ||
@@ -528,8 +533,8 @@ | ||
if (Array.isArray(qp)) { | ||
querystring += this.encodeQueryCollection(param.collectionFormat, param.name, qp); | ||
querystring += this.encodeQueryCollection(param.collectionFormat, param.name, qp, isPassword); | ||
} else { | ||
querystring += this.encodeQueryKey(param.name) + '=' + this.encodeQueryParam(args[param.name]); | ||
querystring += this.encodeQueryKey(param.name) + '=' + this.encodeQueryParam(args[param.name], isPassword); | ||
} | ||
} else { | ||
querystring += this.encodeQueryKey(param.name) + '=' + this.encodeQueryParam(args[param.name]); | ||
querystring += this.encodeQueryKey(param.name) + '=' + this.encodeQueryParam(args[param.name], isPassword); | ||
} | ||
@@ -573,2 +578,6 @@ } else if (param.in === 'formData') { | ||
if (typeof args[param.name] !== 'undefined') { | ||
var isPassword; | ||
if(param.type === 'string' && param.format === 'password') { | ||
isPassword = 'password'; | ||
} | ||
if (param.in === 'body') { | ||
@@ -579,3 +588,4 @@ body = args[param.name]; | ||
param: param, | ||
value: args[param.name] | ||
value: args[param.name], | ||
password: isPassword | ||
}; | ||
@@ -612,2 +622,3 @@ hasFormParams = true; | ||
value = formParams[key].value; | ||
var password = formParams[key].password; | ||
@@ -619,3 +630,3 @@ if (typeof value !== 'undefined') { | ||
} | ||
encoded += this.encodeQueryCollection(param.collectionFormat, key, value); | ||
encoded += this.encodeQueryCollection(param.collectionFormat, key, value, password); | ||
} | ||
@@ -627,3 +638,3 @@ else { | ||
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); | ||
encoded += encodeURIComponent(key) + '=' + mask(encodeURIComponent(value), password); | ||
} | ||
@@ -847,3 +858,3 @@ } | ||
var body = this.getBody(contentTypeHeaders, args, opts); | ||
var url = this.urlify(args); | ||
var url = this.urlify(args, opts.maskPasswords); | ||
@@ -872,2 +883,4 @@ if(url.indexOf('.{format}') > 0) { | ||
clientAuthorizations: opts.clientAuthorizations, | ||
operation: this.operation, | ||
connectionAgent: this.connectionAgent, | ||
on: { | ||
@@ -1029,3 +1042,3 @@ response: function (response) { | ||
Operation.prototype.asCurl = function (args1, args2) { | ||
var opts = {mock: true}; | ||
var opts = {mock: true, maskPasswords: true}; | ||
if (typeof args2 === 'object') { | ||
@@ -1097,10 +1110,10 @@ for (var argKey in args2) { | ||
for(var v in paramValue) { | ||
body += '-F ' + this.encodeQueryKey(parameter.name) + '=' + paramValue[v] + ' '; | ||
body += '-F ' + this.encodeQueryKey(parameter.name) + '=' + mask(paramValue[v], parameter.format) + ' '; | ||
} | ||
} | ||
else { | ||
body += '-F ' + this.encodeQueryCollection(parameter.collectionFormat, parameter.name, paramValue) + ' '; | ||
body += '-F ' + this.encodeQueryCollection(parameter.collectionFormat, parameter.name, mask(paramValue, parameter.format)) + ' '; | ||
} | ||
} else { | ||
body += '-F ' + this.encodeQueryKey(parameter.name) + '=' + paramValue + ' '; | ||
body += '-F ' + this.encodeQueryKey(parameter.name) + '=' + mask(paramValue, parameter.format) + ' '; | ||
} | ||
@@ -1136,3 +1149,3 @@ } | ||
Operation.prototype.encodePathCollection = function (type, name, value) { | ||
Operation.prototype.encodePathCollection = function (type, name, value, maskPasswords) { | ||
var encoded = ''; | ||
@@ -1154,5 +1167,5 @@ var i; | ||
if (i === 0) { | ||
encoded = this.encodeQueryParam(value[i]); | ||
encoded = this.encodeQueryParam(value[i], maskPasswords); | ||
} else { | ||
encoded += separator + this.encodeQueryParam(value[i]); | ||
encoded += separator + this.encodeQueryParam(value[i], maskPasswords); | ||
} | ||
@@ -1164,3 +1177,3 @@ } | ||
Operation.prototype.encodeQueryCollection = function (type, name, value) { | ||
Operation.prototype.encodeQueryCollection = function (type, name, value, maskPasswords) { | ||
var encoded = ''; | ||
@@ -1174,3 +1187,3 @@ var i; | ||
encoded += this.encodeQueryKey(name) + '=' + this.encodeQueryParam(value[i]); | ||
encoded += this.encodeQueryKey(name) + '=' + mask(this.encodeQueryParam(value[i]), maskPasswords); | ||
} | ||
@@ -1193,4 +1206,3 @@ } else { | ||
} | ||
encoded += this.encodeQueryKey(name) + '[]=' + this.encodeQueryParam(value[i]); | ||
encoded += this.encodeQueryKey(name) + '[]=' + mask(this.encodeQueryParam(value[i]), maskPasswords); | ||
} | ||
@@ -1218,3 +1230,6 @@ } | ||
Operation.prototype.encodeQueryParam = function (arg) { | ||
Operation.prototype.encodeQueryParam = function (arg, maskPasswords) { | ||
if(maskPasswords) { | ||
return "******"; | ||
} | ||
return encodeURIComponent(arg); | ||
@@ -1226,4 +1241,11 @@ }; | ||
**/ | ||
Operation.prototype.encodePathParam = function (pathParam) { | ||
return encodeURIComponent(pathParam); | ||
Operation.prototype.encodePathParam = function (pathParam, maskPasswords) { | ||
return encodeURIComponent(pathParam, maskPasswords); | ||
}; | ||
var mask = function(value, format) { | ||
if(typeof format === 'string' && format === 'password') { | ||
return '******'; | ||
} | ||
return value; | ||
} |
@@ -11,3 +11,3 @@ { | ||
"description": "swagger-client is a javascript client for use with swaggering APIs.", | ||
"version": "2.1.26", | ||
"version": "2.1.27", | ||
"homepage": "http://swagger.io", | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -109,13 +109,46 @@ # Swagger JS library | ||
``` | ||
### Authorization | ||
Need to pass an API key? Configure one in your client instance as a query string: | ||
Need to pass an API key? Ok, lets do it for this sample `swagger.yml`: | ||
```yaml | ||
# ... | ||
securityDefinitions: | ||
api_sheme_name: # swagger scheme name | ||
type: apiKey # swagger type (one of "basic", "apiKey" or "oauth2") | ||
name: queryParamName # The name of the header or query parameter to be used | ||
in: query # location of the API key | ||
api_sheme_name_2: | ||
type: apiKey | ||
name: X-KEY-PARAM | ||
in: header | ||
# ... | ||
``` | ||
Configure auth for that definition in your client instance as a *query string*: | ||
```js | ||
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","query")); | ||
client.clientAuthorizations.add("api_sheme_name", | ||
new Swagger.ApiKeyAuthorization( | ||
"queryParamName", | ||
"<YOUR-SECRET-KEY>", | ||
"query" | ||
) | ||
); | ||
``` | ||
...or with a header: | ||
...or with a *header*: | ||
```js | ||
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","header")); | ||
client.clientAuthorizations.add("api_sheme_name_2", | ||
new Swagger.ApiKeyAuthorization( | ||
"X-KEY-PARAM", | ||
"<YOUR-SECRET-KEY>", | ||
"header" | ||
) | ||
); | ||
``` | ||
@@ -122,0 +155,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1946164
25085
443