Skip to content

Commit 7fde1b4

Browse files
committed
Merge pull request #233 from swagger-api/issue-232
Issue 232
2 parents 9ca9ac8 + 341fb22 commit 7fde1b4

File tree

7 files changed

+142
-13
lines changed

7 files changed

+142
-13
lines changed

lib/swagger-client.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
578578
this.description = args.description;
579579
this.useJQuery = parent.useJQuery;
580580

581+
if(typeof this.deprecated === 'string') {
582+
switch(this.deprecated.toLowerCase()) {
583+
case 'true': case 'yes': case '1': {
584+
this.deprecated = true;
585+
break;
586+
}
587+
case 'false': case 'no': case '0': case null: {
588+
this.deprecated = false;
589+
break;
590+
}
591+
default: this.deprecated = Boolean(this.deprecated);
592+
}
593+
}
594+
581595
if(definitions) {
582596
// add to global models
583597
var key;
@@ -810,9 +824,7 @@ Operation.prototype.getHeaderParams = function (args) {
810824
if (param.in === 'header') {
811825
var value = args[param.name];
812826
if(Array.isArray(value))
813-
value = this.encodePathCollection(param.collectionFormat, param.name, value);
814-
else
815-
value = this.encodePathParam(value);
827+
value = value.toString();
816828
headers[param.name] = value;
817829
}
818830
}
@@ -1683,6 +1695,7 @@ var SwaggerResource = function (resourceObj, api) {
16831695
this.description = resourceObj.description;
16841696
this.authorizations = (resourceObj.authorizations || {});
16851697

1698+
16861699
var parts = this.path.split('/');
16871700
this.name = parts[parts.length - 1].replace('.{format}', '');
16881701
this.basePath = this.api.basePath;
@@ -1761,7 +1774,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
17611774
this.consumes = response.consumes;
17621775
if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0)
17631776
this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
1764-
1777+
this.resourcePath = response.resourcePath;
17651778
this.addModels(response.models);
17661779
if (response.apis) {
17671780
for (var i = 0 ; i < response.apis.length; i++) {
@@ -2040,9 +2053,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
20402053
this.consumes = consumes;
20412054
this.produces = produces;
20422055
this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations;
2043-
this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated);
2056+
this.deprecated = deprecated;
20442057
this['do'] = __bind(this['do'], this);
20452058

2059+
if(typeof this.deprecated === 'string') {
2060+
switch(this.deprecated.toLowerCase()) {
2061+
case 'true': case 'yes': case '1': {
2062+
this.deprecated = true;
2063+
break;
2064+
}
2065+
case 'false': case 'no': case '0': case null: {
2066+
this.deprecated = false;
2067+
break;
2068+
}
2069+
default: this.deprecated = Boolean(this.deprecated);
2070+
}
2071+
}
2072+
20462073
if (errors.length > 0) {
20472074
console.error('SwaggerOperation errors', errors, arguments);
20482075
this.resource.api.fail(errors);

lib/swagger-client.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/swagger-a.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
296296
this.description = args.description;
297297
this.useJQuery = parent.useJQuery;
298298

299+
if(typeof this.deprecated === 'string') {
300+
switch(this.deprecated.toLowerCase()) {
301+
case 'true': case 'yes': case '1': {
302+
this.deprecated = true;
303+
break;
304+
}
305+
case 'false': case 'no': case '0': case null: {
306+
this.deprecated = false;
307+
break;
308+
}
309+
default: this.deprecated = Boolean(this.deprecated);
310+
}
311+
}
312+
299313
if(definitions) {
300314
// add to global models
301315
var key;
@@ -528,9 +542,7 @@ Operation.prototype.getHeaderParams = function (args) {
528542
if (param.in === 'header') {
529543
var value = args[param.name];
530544
if(Array.isArray(value))
531-
value = this.encodePathCollection(param.collectionFormat, param.name, value);
532-
else
533-
value = this.encodePathParam(value);
545+
value = value.toString();
534546
headers[param.name] = value;
535547
}
536548
}

src/js/swagger-compat.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ var SwaggerResource = function (resourceObj, api) {
161161
this.description = resourceObj.description;
162162
this.authorizations = (resourceObj.authorizations || {});
163163

164+
164165
var parts = this.path.split('/');
165166
this.name = parts[parts.length - 1].replace('.{format}', '');
166167
this.basePath = this.api.basePath;
@@ -239,7 +240,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
239240
this.consumes = response.consumes;
240241
if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0)
241242
this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
242-
243+
this.resourcePath = response.resourcePath;
243244
this.addModels(response.models);
244245
if (response.apis) {
245246
for (var i = 0 ; i < response.apis.length; i++) {
@@ -518,9 +519,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
518519
this.consumes = consumes;
519520
this.produces = produces;
520521
this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations;
521-
this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated);
522+
this.deprecated = deprecated;
522523
this['do'] = __bind(this['do'], this);
523524

525+
if(typeof this.deprecated === 'string') {
526+
switch(this.deprecated.toLowerCase()) {
527+
case 'true': case 'yes': case '1': {
528+
this.deprecated = true;
529+
break;
530+
}
531+
case 'false': case 'no': case '0': case null: {
532+
this.deprecated = false;
533+
break;
534+
}
535+
default: this.deprecated = Boolean(this.deprecated);
536+
}
537+
}
538+
524539
if (errors.length > 0) {
525540
console.error('SwaggerOperation errors', errors, arguments);
526541
this.resource.api.fail(errors);

test/compat/request.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ describe('request operations', function() {
4545
it('generate a get request', function() {
4646
var petApi = sample.pet;
4747
var req = petApi.getPetById({petId: 1}, {mock: true});
48-
4948
expect(petApi.operations.getPetById.deprecated).toBe(true);
5049
});
5150

test/headers.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,50 @@ describe('header extraction', function() {
2323
expect(headers.myHeader).toBe('tony');
2424
});
2525

26+
27+
it('should not URL encode header string values', function() {
28+
var parameters = [
29+
{
30+
in: 'header',
31+
name: 'myHeader',
32+
type: 'string'
33+
}
34+
];
35+
var op = new swagger.Operation({}, 'http', 'test', 'get', '/path', { parameters: parameters });
36+
var args = {
37+
myHeader: 'someKey=someValue'
38+
};
39+
40+
var url = op.urlify(args);
41+
var headers = op.getHeaderParams(args);
42+
43+
expect(url).toBe('http://localhost/path');
44+
expect(headers.myHeader).toBe('someKey=someValue');
45+
});
46+
47+
it('should not URL encode header string array values', function() {
48+
var parameters = [
49+
{
50+
in: 'header',
51+
name: 'myHeader',
52+
type: 'array',
53+
items: {
54+
type: 'string'
55+
}
56+
}
57+
];
58+
var op = new swagger.Operation({}, 'http', 'test', 'get', '/path', { parameters: parameters });
59+
var args = {
60+
myHeader: ['firstParam=firstValue', 'secondParam=secondValue']
61+
};
62+
63+
var url = op.urlify(args);
64+
var headers = op.getHeaderParams(args);
65+
66+
expect(url).toBe('http://localhost/path');
67+
expect(headers.myHeader).toBe('firstParam=firstValue,secondParam=secondValue');
68+
});
69+
2670
it('should extract header params with string array with default collectionFormat', function() {
2771
var parameters = [
2872
{

test/operation.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,38 @@ describe('operations', function() {
248248
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters });
249249
expect(op.parameters[0].signature).toEqual('Array[date-time]');
250250
});
251+
252+
it('should process the deprecated flag as boolean true', function() {
253+
var parameters = [
254+
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
255+
];
256+
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: true });
257+
expect(op.deprecated).toEqual(true);
258+
});
259+
260+
it('should process the deprecated flag as boolean false', function() {
261+
var parameters = [
262+
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
263+
];
264+
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: false });
265+
expect(op.deprecated).toEqual(false);
266+
});
267+
268+
it('should process the deprecated flag as string true', function() {
269+
var parameters = [
270+
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
271+
];
272+
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'true' });
273+
expect(op.deprecated).toEqual(true);
274+
});
275+
276+
it('should process the deprecated flag as string false', function() {
277+
var parameters = [
278+
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
279+
];
280+
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'false' });
281+
expect(op.deprecated).toEqual(false);
282+
});
251283
});
252284

253285
var quantityQP = {

0 commit comments

Comments
 (0)