Skip to content

Commit f999509

Browse files
committed
Merge pull request #603 from bvleur/with-credentials
enableCookies option in client and operations
2 parents e5fcef5 + 9d6e1bc commit f999509

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
@@ -45,6 +45,7 @@ var Operation = module.exports = function (parent, scheme, operationId, httpMeth
4545
this.summary = args.summary || '';
4646
this.type = null;
4747
this.useJQuery = parent.useJQuery;
48+
this.enableCookies = parent.enableCookies;
4849
this.parameterMacro = parent.parameterMacro || function (operation, parameter) {
4950
return parameter.default;
5051
};
@@ -668,6 +669,11 @@ Operation.prototype.execute = function (arg1, arg2, arg3, arg4, parent) {
668669
if (typeof opts.useJQuery === 'undefined') {
669670
opts.useJQuery = this.useJQuery;
670671
}
672+
673+
if (typeof opts.enableCookies === 'undefined') {
674+
opts.enableCookies = this.enableCookies;
675+
}
676+
671677
var missingParams = this.getMissingParams(args);
672678

673679
if (missingParams.length > 0) {
@@ -710,6 +716,7 @@ Operation.prototype.execute = function (arg1, arg2, arg3, arg4, parent) {
710716
url: url,
711717
method: this.method.toUpperCase(),
712718
body: body,
719+
enableCookies: opts.enableCookies,
713720
useJQuery: opts.useJQuery,
714721
deferred: deferred,
715722
headers: headers,

0 commit comments

Comments
 (0)