102
dist/lib/swagger.js
vendored
102
dist/lib/swagger.js
vendored
@@ -55,26 +55,49 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
response: function(rawResponse) {
|
response: function(rawResponse) {
|
||||||
var res, resource, response, _i, _len, _ref;
|
var api, isApi, newName, operation, res, resource, response, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
|
||||||
response = JSON.parse(rawResponse.content.data);
|
response = JSON.parse(rawResponse.content.data);
|
||||||
if (response.apiVersion != null) {
|
if (response.apiVersion != null) {
|
||||||
_this.apiVersion = response.apiVersion;
|
_this.apiVersion = response.apiVersion;
|
||||||
}
|
}
|
||||||
_this.apis = {};
|
_this.apis = {};
|
||||||
_this.apisArray = [];
|
_this.apisArray = [];
|
||||||
if (response.basePath) {
|
isApi = false;
|
||||||
_this.basePath = response.basePath;
|
|
||||||
} else if (_this.discoveryUrl.indexOf('?') > 0) {
|
|
||||||
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
|
|
||||||
} else {
|
|
||||||
_this.basePath = _this.discoveryUrl;
|
|
||||||
}
|
|
||||||
_ref = response.apis;
|
_ref = response.apis;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
resource = _ref[_i];
|
api = _ref[_i];
|
||||||
res = new SwaggerResource(resource, _this);
|
if (api.operations) {
|
||||||
_this.apis[res.name] = res;
|
_ref1 = api.operations;
|
||||||
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
|
operation = _ref1[_j];
|
||||||
|
isApi = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isApi) {
|
||||||
|
newName = response.resourcePath.replace(/\//g, '');
|
||||||
|
_this.resourcePath = response.resourcePath;
|
||||||
|
res = new SwaggerResource(response, _this);
|
||||||
|
_this.apis[newName] = res;
|
||||||
_this.apisArray.push(res);
|
_this.apisArray.push(res);
|
||||||
|
} else {
|
||||||
|
if (response.basePath) {
|
||||||
|
_this.basePath = response.basePath;
|
||||||
|
} else if (_this.discoveryUrl.indexOf('?') > 0) {
|
||||||
|
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
|
||||||
|
} else {
|
||||||
|
_this.basePath = _this.discoveryUrl;
|
||||||
|
}
|
||||||
|
_ref2 = response.apis;
|
||||||
|
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
||||||
|
resource = _ref2[_k];
|
||||||
|
res = new SwaggerResource(resource, _this);
|
||||||
|
_this.apis[res.name] = res;
|
||||||
|
_this.apisArray.push(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_this.success) {
|
||||||
|
_this.success();
|
||||||
}
|
}
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@@ -179,11 +202,8 @@
|
|||||||
this.operationsArray = [];
|
this.operationsArray = [];
|
||||||
this.modelsArray = [];
|
this.modelsArray = [];
|
||||||
this.models = {};
|
this.models = {};
|
||||||
if ((resourceObj.operations != null) && (this.api.resourcePath != null)) {
|
if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
|
||||||
this.api.progress('reading resource ' + this.name + ' models and operations');
|
this.addApiDeclaration(resourceObj);
|
||||||
this.addModels(resourceObj.models);
|
|
||||||
this.addOperations(resourceObj.path, resourceObj.operations);
|
|
||||||
this.api[this.name] = this;
|
|
||||||
} else {
|
} else {
|
||||||
if (this.path == null) {
|
if (this.path == null) {
|
||||||
this.api.fail("SwaggerResources must have a path.");
|
this.api.fail("SwaggerResources must have a path.");
|
||||||
@@ -198,28 +218,9 @@
|
|||||||
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
|
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
|
||||||
},
|
},
|
||||||
response: function(rawResponse) {
|
response: function(rawResponse) {
|
||||||
var endpoint, response, _i, _len, _ref;
|
var response;
|
||||||
response = JSON.parse(rawResponse.content._body);
|
response = JSON.parse(rawResponse.content.data);
|
||||||
if (response.produces != null) {
|
return _this.addApiDeclaration(response);
|
||||||
_this.produces = response.produces;
|
|
||||||
}
|
|
||||||
if (response.consumes != null) {
|
|
||||||
_this.consumes = response.consumes;
|
|
||||||
}
|
|
||||||
if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
|
|
||||||
_this.basePath = response.basePath;
|
|
||||||
}
|
|
||||||
_this.addModels(response.models);
|
|
||||||
if (response.apis) {
|
|
||||||
_ref = response.apis;
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
endpoint = _ref[_i];
|
|
||||||
_this.addOperations(endpoint.path, endpoint.operations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_this.api[_this.name] = _this;
|
|
||||||
_this.ready = true;
|
|
||||||
return _this.api.selfReflect();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -227,6 +228,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwaggerResource.prototype.addApiDeclaration = function(response) {
|
||||||
|
var endpoint, _i, _len, _ref;
|
||||||
|
if (response.produces != null) {
|
||||||
|
this.produces = response.produces;
|
||||||
|
}
|
||||||
|
if (response.consumes != null) {
|
||||||
|
this.consumes = response.consumes;
|
||||||
|
}
|
||||||
|
if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
|
||||||
|
this.basePath = response.basePath;
|
||||||
|
}
|
||||||
|
this.addModels(response.models);
|
||||||
|
if (response.apis) {
|
||||||
|
_ref = response.apis;
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
endpoint = _ref[_i];
|
||||||
|
this.addOperations(endpoint.path, endpoint.operations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.api[this.name] = this;
|
||||||
|
this.ready = true;
|
||||||
|
return this.api.selfReflect();
|
||||||
|
};
|
||||||
|
|
||||||
SwaggerResource.prototype.addModels = function(models) {
|
SwaggerResource.prototype.addModels = function(models) {
|
||||||
var model, modelName, swaggerModel, _i, _len, _ref, _results;
|
var model, modelName, swaggerModel, _i, _len, _ref, _results;
|
||||||
if (models != null) {
|
if (models != null) {
|
||||||
@@ -989,7 +1014,6 @@
|
|||||||
|
|
||||||
ApiKeyAuthorization.prototype.apply = function(obj) {
|
ApiKeyAuthorization.prototype.apply = function(obj) {
|
||||||
if (this.type === "query") {
|
if (this.type === "query") {
|
||||||
console.log(this.value);
|
|
||||||
if (obj.url.indexOf('?') > 0) {
|
if (obj.url.indexOf('?') > 0) {
|
||||||
obj.url = obj.url + "&" + this.name + "=" + this.value;
|
obj.url = obj.url + "&" + this.name + "=" + this.value;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
101
lib/swagger.js
101
lib/swagger.js
@@ -55,26 +55,49 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
response: function(rawResponse) {
|
response: function(rawResponse) {
|
||||||
var res, resource, response, _i, _len, _ref;
|
var api, isApi, newName, operation, res, resource, response, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
|
||||||
response = JSON.parse(rawResponse.content.data);
|
response = JSON.parse(rawResponse.content.data);
|
||||||
if (response.apiVersion != null) {
|
if (response.apiVersion != null) {
|
||||||
_this.apiVersion = response.apiVersion;
|
_this.apiVersion = response.apiVersion;
|
||||||
}
|
}
|
||||||
_this.apis = {};
|
_this.apis = {};
|
||||||
_this.apisArray = [];
|
_this.apisArray = [];
|
||||||
if (response.basePath) {
|
isApi = false;
|
||||||
_this.basePath = response.basePath;
|
|
||||||
} else if (_this.discoveryUrl.indexOf('?') > 0) {
|
|
||||||
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
|
|
||||||
} else {
|
|
||||||
_this.basePath = _this.discoveryUrl;
|
|
||||||
}
|
|
||||||
_ref = response.apis;
|
_ref = response.apis;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
resource = _ref[_i];
|
api = _ref[_i];
|
||||||
res = new SwaggerResource(resource, _this);
|
if (api.operations) {
|
||||||
_this.apis[res.name] = res;
|
_ref1 = api.operations;
|
||||||
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
|
operation = _ref1[_j];
|
||||||
|
isApi = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isApi) {
|
||||||
|
newName = response.resourcePath.replace(/\//g, '');
|
||||||
|
_this.resourcePath = response.resourcePath;
|
||||||
|
res = new SwaggerResource(response, _this);
|
||||||
|
_this.apis[newName] = res;
|
||||||
_this.apisArray.push(res);
|
_this.apisArray.push(res);
|
||||||
|
} else {
|
||||||
|
if (response.basePath) {
|
||||||
|
_this.basePath = response.basePath;
|
||||||
|
} else if (_this.discoveryUrl.indexOf('?') > 0) {
|
||||||
|
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
|
||||||
|
} else {
|
||||||
|
_this.basePath = _this.discoveryUrl;
|
||||||
|
}
|
||||||
|
_ref2 = response.apis;
|
||||||
|
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
||||||
|
resource = _ref2[_k];
|
||||||
|
res = new SwaggerResource(resource, _this);
|
||||||
|
_this.apis[res.name] = res;
|
||||||
|
_this.apisArray.push(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_this.success) {
|
||||||
|
_this.success();
|
||||||
}
|
}
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@@ -179,11 +202,8 @@
|
|||||||
this.operationsArray = [];
|
this.operationsArray = [];
|
||||||
this.modelsArray = [];
|
this.modelsArray = [];
|
||||||
this.models = {};
|
this.models = {};
|
||||||
if ((resourceObj.operations != null) && (this.api.resourcePath != null)) {
|
if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
|
||||||
this.api.progress('reading resource ' + this.name + ' models and operations');
|
this.addApiDeclaration(resourceObj);
|
||||||
this.addModels(resourceObj.models);
|
|
||||||
this.addOperations(resourceObj.path, resourceObj.operations);
|
|
||||||
this.api[this.name] = this;
|
|
||||||
} else {
|
} else {
|
||||||
if (this.path == null) {
|
if (this.path == null) {
|
||||||
this.api.fail("SwaggerResources must have a path.");
|
this.api.fail("SwaggerResources must have a path.");
|
||||||
@@ -198,28 +218,9 @@
|
|||||||
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
|
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
|
||||||
},
|
},
|
||||||
response: function(rawResponse) {
|
response: function(rawResponse) {
|
||||||
var endpoint, response, _i, _len, _ref;
|
var response;
|
||||||
response = JSON.parse(rawResponse.content._body);
|
response = JSON.parse(rawResponse.content.data);
|
||||||
if (response.produces != null) {
|
return _this.addApiDeclaration(response);
|
||||||
_this.produces = response.produces;
|
|
||||||
}
|
|
||||||
if (response.consumes != null) {
|
|
||||||
_this.consumes = response.consumes;
|
|
||||||
}
|
|
||||||
if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
|
|
||||||
_this.basePath = response.basePath;
|
|
||||||
}
|
|
||||||
_this.addModels(response.models);
|
|
||||||
if (response.apis) {
|
|
||||||
_ref = response.apis;
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
endpoint = _ref[_i];
|
|
||||||
_this.addOperations(endpoint.path, endpoint.operations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_this.api[_this.name] = _this;
|
|
||||||
_this.ready = true;
|
|
||||||
return _this.api.selfReflect();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -227,6 +228,30 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwaggerResource.prototype.addApiDeclaration = function(response) {
|
||||||
|
var endpoint, _i, _len, _ref;
|
||||||
|
if (response.produces != null) {
|
||||||
|
this.produces = response.produces;
|
||||||
|
}
|
||||||
|
if (response.consumes != null) {
|
||||||
|
this.consumes = response.consumes;
|
||||||
|
}
|
||||||
|
if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
|
||||||
|
this.basePath = response.basePath;
|
||||||
|
}
|
||||||
|
this.addModels(response.models);
|
||||||
|
if (response.apis) {
|
||||||
|
_ref = response.apis;
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
endpoint = _ref[_i];
|
||||||
|
this.addOperations(endpoint.path, endpoint.operations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.api[this.name] = this;
|
||||||
|
this.ready = true;
|
||||||
|
return this.api.selfReflect();
|
||||||
|
};
|
||||||
|
|
||||||
SwaggerResource.prototype.addModels = function(models) {
|
SwaggerResource.prototype.addModels = function(models) {
|
||||||
var model, modelName, swaggerModel, _i, _len, _ref, _results;
|
var model, modelName, swaggerModel, _i, _len, _ref, _results;
|
||||||
if (models != null) {
|
if (models != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user