Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions lib/swagger-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
this.description = args.description;
this.useJQuery = parent.useJQuery;

if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}

if(definitions) {
// add to global models
var key;
Expand Down Expand Up @@ -810,9 +824,7 @@ Operation.prototype.getHeaderParams = function (args) {
if (param.in === 'header') {
var value = args[param.name];
if(Array.isArray(value))
value = this.encodePathCollection(param.collectionFormat, param.name, value);
else
value = this.encodePathParam(value);
value = value.toString();
headers[param.name] = value;
}
}
Expand Down Expand Up @@ -1683,6 +1695,7 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {});


var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath;
Expand Down Expand Up @@ -1761,7 +1774,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
this.consumes = response.consumes;
if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0)
this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;

this.resourcePath = response.resourcePath;
this.addModels(response.models);
if (response.apis) {
for (var i = 0 ; i < response.apis.length; i++) {
Expand Down Expand Up @@ -2040,9 +2053,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.consumes = consumes;
this.produces = produces;
this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations;
this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated);
this.deprecated = deprecated;
this['do'] = __bind(this['do'], this);

if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}

if (errors.length > 0) {
console.error('SwaggerOperation errors', errors, arguments);
this.resource.api.fail(errors);
Expand Down
4 changes: 2 additions & 2 deletions lib/swagger-client.min.js

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/js/swagger-a.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ var Operation = function(parent, scheme, operationId, httpMethod, path, args, de
this.description = args.description;
this.useJQuery = parent.useJQuery;

if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}

if(definitions) {
// add to global models
var key;
Expand Down Expand Up @@ -528,9 +542,7 @@ Operation.prototype.getHeaderParams = function (args) {
if (param.in === 'header') {
var value = args[param.name];
if(Array.isArray(value))
value = this.encodePathCollection(param.collectionFormat, param.name, value);
else
value = this.encodePathParam(value);
value = value.toString();
headers[param.name] = value;
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/js/swagger-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {});


var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath;
Expand Down Expand Up @@ -239,7 +240,7 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
this.consumes = response.consumes;
if ((typeof response.basePath === 'string') && response.basePath.replace(/\s/g, '').length > 0)
this.basePath = response.basePath.indexOf('http') === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;

this.resourcePath = response.resourcePath;
this.addModels(response.models);
if (response.apis) {
for (var i = 0 ; i < response.apis.length; i++) {
Expand Down Expand Up @@ -518,9 +519,23 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.consumes = consumes;
this.produces = produces;
this.authorizations = typeof authorizations !== 'undefined' ? authorizations : resource.authorizations;
this.deprecated = (typeof deprecated === 'string' ? Boolean(deprecated) : deprecated);
this.deprecated = deprecated;
this['do'] = __bind(this['do'], this);

if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
this.deprecated = true;
break;
}
case 'false': case 'no': case '0': case null: {
this.deprecated = false;
break;
}
default: this.deprecated = Boolean(this.deprecated);
}
}

if (errors.length > 0) {
console.error('SwaggerOperation errors', errors, arguments);
this.resource.api.fail(errors);
Expand Down
1 change: 0 additions & 1 deletion test/compat/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describe('request operations', function() {
it('generate a get request', function() {
var petApi = sample.pet;
var req = petApi.getPetById({petId: 1}, {mock: true});

expect(petApi.operations.getPetById.deprecated).toBe(true);
});

Expand Down
44 changes: 44 additions & 0 deletions test/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,50 @@ describe('header extraction', function() {
expect(headers.myHeader).toBe('tony');
});


it('should not URL encode header string values', function() {
var parameters = [
{
in: 'header',
name: 'myHeader',
type: 'string'
}
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/path', { parameters: parameters });
var args = {
myHeader: 'someKey=someValue'
};

var url = op.urlify(args);
var headers = op.getHeaderParams(args);

expect(url).toBe('http://localhost/path');
expect(headers.myHeader).toBe('someKey=someValue');
});

it('should not URL encode header string array values', function() {
var parameters = [
{
in: 'header',
name: 'myHeader',
type: 'array',
items: {
type: 'string'
}
}
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/path', { parameters: parameters });
var args = {
myHeader: ['firstParam=firstValue', 'secondParam=secondValue']
};

var url = op.urlify(args);
var headers = op.getHeaderParams(args);

expect(url).toBe('http://localhost/path');
expect(headers.myHeader).toBe('firstParam=firstValue,secondParam=secondValue');
});

it('should extract header params with string array with default collectionFormat', function() {
var parameters = [
{
Expand Down
32 changes: 32 additions & 0 deletions test/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,38 @@ describe('operations', function() {
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters });
expect(op.parameters[0].signature).toEqual('Array[date-time]');
});

it('should process the deprecated flag as boolean true', function() {
var parameters = [
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: true });
expect(op.deprecated).toEqual(true);
});

it('should process the deprecated flag as boolean false', function() {
var parameters = [
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: false });
expect(op.deprecated).toEqual(false);
});

it('should process the deprecated flag as string true', function() {
var parameters = [
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'true' });
expect(op.deprecated).toEqual(true);
});

it('should process the deprecated flag as string false', function() {
var parameters = [
{ in: 'query', name: 'year', type: 'array', items: {type: 'string', format: 'date-time'} }
];
var op = new swagger.Operation({}, 'http', 'test', 'get', '/fantastic', { parameters: parameters, deprecated: 'false' });
expect(op.deprecated).toEqual(false);
});
});

var quantityQP = {
Expand Down