first working version of swagger ui without the form submission/sandbox
This commit is contained in:
@@ -2,13 +2,13 @@ jQuery(function($) {
|
||||
// create and initialize SwaggerService
|
||||
var swaggerService = new SwaggerService();
|
||||
swaggerService.init();
|
||||
|
||||
|
||||
// Create convenience references to Spine models
|
||||
var ApiResource = swaggerService.ApiResource();
|
||||
|
||||
// Register a callback for when apis are loaded
|
||||
ApiResource.bind("refresh", apisLoaded);
|
||||
|
||||
|
||||
function apisLoaded() {
|
||||
for(var i = 0; i < ApiResource.all().length; i++) {
|
||||
var apiResource = ApiResource.all()[i];
|
||||
@@ -20,5 +20,5 @@ jQuery(function($) {
|
||||
|
||||
if (window.console) console.log("apis loaded");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ function SwaggerService(hostUrl) {
|
||||
this.path_json = this.path + ".json";
|
||||
this.path_xml = this.path + ".xml";
|
||||
this.baseUrl = apiHost;
|
||||
this.name = this.path.substr(0, this.path.length);
|
||||
this.name = this.path.substr(1, this.path.length);
|
||||
this.apiList = Api.sub();
|
||||
this.modelList = ApiModel.sub();
|
||||
},
|
||||
@@ -62,9 +62,9 @@ function SwaggerService(hostUrl) {
|
||||
this.path_xml = prefix + ".xml" + suffix;;
|
||||
|
||||
if(this.path.indexOf("/") == 0) {
|
||||
this.name = this.path.substr(1, secondPathSeperatorIndex);
|
||||
this.name = this.path.substr(1, secondPathSeperatorIndex - 1);
|
||||
} else {
|
||||
this.name = this.path.substr(0, secondPathSeperatorIndex);
|
||||
this.name = this.path.substr(0, secondPathSeperatorIndex - 1);
|
||||
}
|
||||
} else {
|
||||
this.path_json = this.path + ".json";
|
||||
@@ -78,16 +78,21 @@ function SwaggerService(hostUrl) {
|
||||
}
|
||||
|
||||
var value = this.operations;
|
||||
this.operations = ApiOperation.sub();
|
||||
if (value) this.operations.refresh(value);
|
||||
|
||||
for(var i = 0; i < this.operations.all().length; i++) {
|
||||
var operation = this.operations.all()[i];
|
||||
operation.apiName = this.name;
|
||||
operation.path = this.path;
|
||||
operation.path_json = this.path_json;
|
||||
operation.path_xml = this.path_xml;
|
||||
this.operations = ApiOperation.sub();
|
||||
if (value) {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
var obj = value[i];
|
||||
obj.apiName = this.name;
|
||||
obj.path = this.path;
|
||||
obj.path_json = this.path_json;
|
||||
obj.path_xml = this.path_xml;
|
||||
|
||||
}
|
||||
|
||||
this.operations.refresh(value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
@@ -106,14 +111,15 @@ function SwaggerService(hostUrl) {
|
||||
});
|
||||
|
||||
// Model: ApiOperation
|
||||
var ApiOperation = Spine.Model.setup("ApiOperation", ["baseUrl", "path", "path_json", "path_xml", "summary", "deprecated", "open", "httpMethod", "nickname", "responseClass", "parameters", "apiName"]);
|
||||
var ApiOperation = Spine.Model.setup("ApiOperation", ["baseUrl", "path", "path_json", "path_xml", "summary", "deprecated", "open", "httpMethod", "httpMethodLowercase", "nickname", "responseClass", "parameters", "apiName"]);
|
||||
ApiOperation.include({
|
||||
init: function(atts) {
|
||||
if (atts) this.load(atts);
|
||||
|
||||
this.baseUrl = apiHost;
|
||||
this.httpMethodLowercase = this.httpMethod.toLowerCase();
|
||||
|
||||
var value = this.parameters;
|
||||
var value = this.parameters;
|
||||
this.parameters = ApiParameter.sub();
|
||||
if (value) this.parameters.refresh(value);
|
||||
},
|
||||
@@ -130,7 +136,7 @@ function SwaggerService(hostUrl) {
|
||||
}
|
||||
paramsString += ")";
|
||||
|
||||
return "{" + this.nickname + paramsString + ": " + this.summary + "}";
|
||||
return "{" + this.path_json + "| " + this.nickname + paramsString + ": " + this.summary + "}";
|
||||
}
|
||||
|
||||
});
|
||||
@@ -140,6 +146,8 @@ function SwaggerService(hostUrl) {
|
||||
ApiParameter.include({
|
||||
init: function(atts) {
|
||||
if (atts) this.load(atts);
|
||||
|
||||
this.name = this.name || this.dataType;
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
jQuery(function($) {
|
||||
// create and initialize SwaggerService
|
||||
var swaggerService = new SwaggerService();
|
||||
swaggerService.init();
|
||||
|
||||
// Create convenience references to Spine models
|
||||
var ApiResource = swaggerService.ApiResource();
|
||||
|
||||
// Register a callback for when apis are loaded
|
||||
ApiResource.bind("refresh", apisLoaded);
|
||||
|
||||
function apisLoaded() {
|
||||
for (var i = 0; i < ApiResource.all().length; i++) {
|
||||
var apiResource = ApiResource.all()[i];
|
||||
log("------------- apiResource : " + apiResource.name);
|
||||
|
||||
$("#resourceTemplate").tmpl(apiResource).appendTo("#resources");
|
||||
|
||||
// apiResource.apiList.logAll();
|
||||
var resourceApisContainer = "#" + apiResource.name + "_endpoint_list";
|
||||
log("resourceApisContainer = " + resourceApisContainer);
|
||||
for (var j = 0; j < apiResource.apiList.all().length; j++) {
|
||||
var api = apiResource.apiList.all()[j];
|
||||
$("#apiTemplate").tmpl(api).appendTo(resourceApisContainer);
|
||||
renderOperations(api);
|
||||
}
|
||||
|
||||
// apiResource.modelList.logAll();
|
||||
for (var k = 0; k < apiResource.modelList.all().length; k++) {
|
||||
var apiModel = apiResource.modelList.all()[k];
|
||||
}
|
||||
}
|
||||
|
||||
if (window.console) console.log("apis loaded");
|
||||
}
|
||||
|
||||
function renderOperations(api) {
|
||||
if (api.operations && api.operations.count() > 0) {
|
||||
var operationsContainer = "#" + api.name + "_endpoint_" + api.id + "_operations";
|
||||
for (var o = 0; o < api.operations.all().length; o++) {
|
||||
var operation = api.operations.all()[o];
|
||||
$("#operationTemplate").tmpl(operation).appendTo(operationsContainer);
|
||||
renderParameters(operation, $);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function renderParameters(operation) {
|
||||
if(operation.parameters && operation.parameters.count() > 0) {
|
||||
var isGetOpetation = (operation.httpMethodLowercase == "get");
|
||||
|
||||
var operationParamsContainer = "#" + operation.apiName + "_" + operation.nickname + "_" + operation.id + "_params";
|
||||
log("operationParamsContainer= " + operationParamsContainer);
|
||||
for (var p = 0; p < operation.parameters.all().length; p++) {
|
||||
var param = operation.parameters.all()[p];
|
||||
|
||||
var templateName = "#paramTemplate";
|
||||
if (param.required)
|
||||
templateName += "Required";
|
||||
|
||||
if (!isGetOpetation)
|
||||
templateName += "ReadOnly";
|
||||
|
||||
$(templateName).tmpl(param).appendTo(operationParamsContainer);
|
||||
|
||||
if (!isGetOpetation) {
|
||||
var submitButtonId = "#" + operation.apiName + "_" + operation.nickname + "_" + operation.id + "_content_sandbox_response_button";
|
||||
$(submitButtonId).hide();
|
||||
|
||||
var valueHeader = "#" + operation.apiName + "_" + operation.nickname + "_" + operation.id + "_value_header";
|
||||
$(valueHeader).html("Default Value");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user