Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Commit bdcae38

Browse files
committed
updated swagger-js per swagger-api/swagger-js#167
1 parent 114add9 commit bdcae38

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ example.html
44
.classpath
55
.project
66
.npmignore
7+
dist/sample.html
8+
dist/spec.js
79
node_modules

dist/lib/swagger-client.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger-client.js
2-
// version 2.1.0-alpha.2
2+
// version 2.1.0-alpha.3
33
/**
44
* Array Model
55
**/
@@ -840,7 +840,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
840840
var reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
841841
requestUrl = requestUrl.replace(reg, this.encodePathParam(args[param.name]));
842842
}
843-
else if (param.in === 'query') {
843+
else if (param.in === 'query' && typeof args[param.name] !== 'undefined') {
844844
if(querystring === '')
845845
querystring += '?';
846846
else
@@ -1103,14 +1103,11 @@ Model.prototype.getMockSignature = function(modelsToIgnore) {
11031103
var Property = function(name, obj, required) {
11041104
this.schema = obj;
11051105
this.required = required;
1106-
if(obj['$ref']) {
1107-
var refType = obj['$ref'];
1108-
refType = refType.indexOf('#/definitions') === -1 ? refType : refType.substring('#/definitions').length;
1109-
this['$ref'] = refType;
1110-
}
1106+
if(obj['$ref'])
1107+
this['$ref'] = simpleRef(obj['$ref']);
11111108
else if (obj.type === 'array') {
11121109
if(obj.items['$ref'])
1113-
this['$ref'] = obj.items['$ref'];
1110+
this['$ref'] = simpleRef(obj.items['$ref']);
11141111
else
11151112
obj = obj.items;
11161113
}
@@ -1141,7 +1138,8 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
11411138
var output;
11421139

11431140
if(this['$ref']) {
1144-
var refModel = models[this['$ref']];
1141+
var refModelName = simpleRef(this['$ref']);
1142+
var refModel = models[refModelName];
11451143
if(refModel && typeof ignoredModels[type] === 'undefined') {
11461144
ignoredModels[type] = this;
11471145
output = refModel.getSampleValue(ignoredModels);
@@ -1200,14 +1198,18 @@ getStringSignature = function(obj) {
12001198
str += 'double';
12011199
else if(obj.type === 'boolean')
12021200
str += 'boolean';
1201+
else if(obj['$ref'])
1202+
str += simpleRef(obj['$ref']);
12031203
else
1204-
str += obj.type || obj['$ref'];
1204+
str += obj.type;
12051205
if(obj.type === 'array')
12061206
str += ']';
12071207
return str;
12081208
}
12091209

12101210
simpleRef = function(name) {
1211+
if(typeof name === 'undefined')
1212+
return null;
12111213
if(name.indexOf("#/definitions/") === 0)
12121214
return name.substring('#/definitions/'.length)
12131215
else

lib/swagger-client.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger-client.js
2-
// version 2.1.0-alpha.2
2+
// version 2.1.0-alpha.3
33
/**
44
* Array Model
55
**/
@@ -840,7 +840,7 @@ Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) {
840840
var reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
841841
requestUrl = requestUrl.replace(reg, this.encodePathParam(args[param.name]));
842842
}
843-
else if (param.in === 'query') {
843+
else if (param.in === 'query' && typeof args[param.name] !== 'undefined') {
844844
if(querystring === '')
845845
querystring += '?';
846846
else
@@ -1103,14 +1103,11 @@ Model.prototype.getMockSignature = function(modelsToIgnore) {
11031103
var Property = function(name, obj, required) {
11041104
this.schema = obj;
11051105
this.required = required;
1106-
if(obj['$ref']) {
1107-
var refType = obj['$ref'];
1108-
refType = refType.indexOf('#/definitions') === -1 ? refType : refType.substring('#/definitions').length;
1109-
this['$ref'] = refType;
1110-
}
1106+
if(obj['$ref'])
1107+
this['$ref'] = simpleRef(obj['$ref']);
11111108
else if (obj.type === 'array') {
11121109
if(obj.items['$ref'])
1113-
this['$ref'] = obj.items['$ref'];
1110+
this['$ref'] = simpleRef(obj.items['$ref']);
11141111
else
11151112
obj = obj.items;
11161113
}
@@ -1141,7 +1138,8 @@ Property.prototype.sampleValue = function(isArray, ignoredModels) {
11411138
var output;
11421139

11431140
if(this['$ref']) {
1144-
var refModel = models[this['$ref']];
1141+
var refModelName = simpleRef(this['$ref']);
1142+
var refModel = models[refModelName];
11451143
if(refModel && typeof ignoredModels[type] === 'undefined') {
11461144
ignoredModels[type] = this;
11471145
output = refModel.getSampleValue(ignoredModels);
@@ -1200,14 +1198,18 @@ getStringSignature = function(obj) {
12001198
str += 'double';
12011199
else if(obj.type === 'boolean')
12021200
str += 'boolean';
1201+
else if(obj['$ref'])
1202+
str += simpleRef(obj['$ref']);
12031203
else
1204-
str += obj.type || obj['$ref'];
1204+
str += obj.type;
12051205
if(obj.type === 'array')
12061206
str += ']';
12071207
return str;
12081208
}
12091209

12101210
simpleRef = function(name) {
1211+
if(typeof name === 'undefined')
1212+
return null;
12111213
if(name.indexOf("#/definitions/") === 0)
12121214
return name.substring('#/definitions/'.length)
12131215
else

0 commit comments

Comments
 (0)