Skip to content

Commit 9d6e1bc

Browse files
committed
enableCookies option in client and operations
Setting `enableCookies` to true in the options of a new SwaggerClient or in the options object of an operation makes the browser include the cookies and other HTTP credentials in it's requests. Naming the option 'enableCookies' as suggested by user tonytam in IRC. More information about sending credentials: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials
1 parent e9bd43d commit 9d6e1bc

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

lib/client.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var reservedClientTags = [
3838
'debug',
3939
'defaultErrorCallback',
4040
'defaultSuccessCallback',
41+
'enableCookies',
4142
'fail',
4243
'failure',
4344
'finish',
@@ -88,6 +89,7 @@ var SwaggerClient = module.exports = function (url, options) {
8889
this.authorizationScheme = null;
8990
this.basePath = null;
9091
this.debug = false;
92+
this.enableCookies = false;
9193
this.info = null;
9294
this.isBuilt = false;
9395
this.isValid = false;
@@ -135,6 +137,10 @@ SwaggerClient.prototype.initialize = function (url, options) {
135137
this.useJQuery = options.useJQuery;
136138
}
137139

140+
if (options.enableCookies) {
141+
this.enableCookies = options.enableCookies;
142+
};
143+
138144
this.options = options || {};
139145

140146
this.supportedSubmitMethods = options.supportedSubmitMethods || [];

lib/http.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ SuperagentHttpClient.prototype.execute = function (obj) {
207207
r.set(name, headers[name]);
208208
}
209209

210+
if (obj.enableCookies) {
211+
r.withCredentials();
212+
}
213+
210214
if (obj.body) {
211215
r.send(obj.body);
212216
}

lib/types/operation.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var Operation = module.exports = function (parent, scheme, operationId, httpMeth
4444
this.summary = args.summary || '';
4545
this.type = null;
4646
this.useJQuery = parent.useJQuery;
47+
this.enableCookies = parent.enableCookies;
4748
this.parameterMacro = parent.parameterMacro || function (operation, parameter) {
4849
return parameter.default;
4950
};
@@ -667,6 +668,11 @@ Operation.prototype.execute = function (arg1, arg2, arg3, arg4, parent) {
667668
if (typeof opts.useJQuery === 'undefined') {
668669
opts.useJQuery = this.useJQuery;
669670
}
671+
672+
if (typeof opts.enableCookies === 'undefined') {
673+
opts.enableCookies = this.enableCookies;
674+
}
675+
670676
var missingParams = this.getMissingParams(args);
671677

672678
if (missingParams.length > 0) {
@@ -709,6 +715,7 @@ Operation.prototype.execute = function (arg1, arg2, arg3, arg4, parent) {
709715
url: url,
710716
method: this.method.toUpperCase(),
711717
body: body,
718+
enableCookies: opts.enableCookies,
712719
useJQuery: opts.useJQuery,
713720
deferred: deferred,
714721
headers: headers,

0 commit comments

Comments
 (0)