Custom Header Parameters - (For Basic auth etc). Closes #53. Thanks @rintcius!
This commit is contained in:
@@ -47,6 +47,7 @@ To use swagger-ui you should take a look at the [source of swagger-ui html page]
|
|||||||
dom_id:"swagger-ui-container",
|
dom_id:"swagger-ui-container",
|
||||||
apiKey:"special-key",
|
apiKey:"special-key",
|
||||||
supportHeaderParams: false,
|
supportHeaderParams: false,
|
||||||
|
headers: { "Authorization": "XXXX", "someOtherHeader": "YYYY" },
|
||||||
supportedSubmitMethods: ['get', 'post', 'put']
|
supportedSubmitMethods: ['get', 'post', 'put']
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -71,6 +72,11 @@ header parameters are supported. However because of [Cross-Origin Resource Shari
|
|||||||
|
|
||||||
supportHeaderParams: true
|
supportHeaderParams: true
|
||||||
|
|
||||||
|
### Custom Header Parameters - (For Basic auth etc)
|
||||||
|
If you have some header parameters which you need to send with every request, use the headers as below:
|
||||||
|
|
||||||
|
headers: { "Authorization": "XXXX", "someOtherHeader": "YYYY" }
|
||||||
|
|
||||||
### Api Key Parameter
|
### Api Key Parameter
|
||||||
If you enter an api key in swagger-ui, it sends a parameter named 'api\_key' as a query (or as a header param if you've enabled it as described above). You may not want to use the name 'api\_key' as the name of this parameter. You can change its name by setting the _apiKeyName_ parameter when you instantiate a SwaggerUI instance. For example to call it 'sessionId'
|
If you enter an api key in swagger-ui, it sends a parameter named 'api\_key' as a query (or as a header param if you've enabled it as described above). You may not want to use the name 'api\_key' as the name of this parameter. You can change its name by setting the _apiKeyName_ parameter when you instantiate a SwaggerUI instance. For example to call it 'sessionId'
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
}
|
}
|
||||||
this.failure = options.failure != null ? options.failure : function() {};
|
this.failure = options.failure != null ? options.failure : function() {};
|
||||||
this.progress = options.progress != null ? options.progress : function() {};
|
this.progress = options.progress != null ? options.progress : function() {};
|
||||||
|
this.headers = options.headers != null ? options.headers : {};
|
||||||
this.discoveryUrl = this.suffixApiKey(this.discoveryUrl);
|
this.discoveryUrl = this.suffixApiKey(this.discoveryUrl);
|
||||||
if (options.success != null) {
|
if (options.success != null) {
|
||||||
this.build();
|
this.build();
|
||||||
@@ -394,7 +395,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args, includeApiKey) {
|
SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args, includeApiKey) {
|
||||||
var matchingParams, param, _i, _len, _ref;
|
var matchingParams, name, param, value, _i, _len, _ref, _ref1;
|
||||||
matchingParams = {};
|
matchingParams = {};
|
||||||
_ref = this.parameters;
|
_ref = this.parameters;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
@@ -406,6 +407,13 @@
|
|||||||
if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
|
if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
|
||||||
matchingParams[this.resource.api.apiKeyName] = this.resource.api.api_key;
|
matchingParams[this.resource.api.apiKeyName] = this.resource.api.api_key;
|
||||||
}
|
}
|
||||||
|
if (jQuery.inArray('header', paramTypes) >= 0) {
|
||||||
|
_ref1 = this.resource.api.headers;
|
||||||
|
for (name in _ref1) {
|
||||||
|
value = _ref1[name];
|
||||||
|
matchingParams[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
return matchingParams;
|
return matchingParams;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user