Merge pull request #8 from zeke/master

Updates to allow for presence or absence of .{format} string in discovery and resource URLs
This commit is contained in:
Zeke Sikelianos
2012-01-24 16:44:50 -08:00
11 changed files with 132 additions and 80 deletions

View File

@@ -124,7 +124,7 @@
<option selected='selected' value=''></option>
{{/if}}
{{each allowableValues.values}}
{{if $value == defaultValue && required == true}}
{{if $value == defaultValue && required == true }}
<option selected='selected' value='${$value}'>${$value}</option>
{{else}}
<option value='${$value}'>${$value}</option>

View File

@@ -2168,10 +2168,10 @@ function clippyCopiedCallback(a) {
}
// Logging function that accounts for browsers that don't have window.console
function log(m) {
if (window.console) console.log(m);
function log() {
if (window.console) console.log.apply(console,arguments);
}
var Docs = {
shebang: function() {
@@ -2529,12 +2529,15 @@ arguments),this._chain)}});j.prototype.chain=function(){this._chain=!0;return th
// adeed by ayush
createAll: function(values){
// debugger;
values = this.fromJSON(values);
// debugger;
for (var i=0, il = values.length; i < il; i++) {
var record = values[i];
record.newRecord = false;
record.id = record.id || Spine.guid();
record.id = record.id || Spine.guid();
this.records[record.id] = record;
}
@@ -2578,7 +2581,7 @@ arguments),this._chain)}});j.prototype.chain=function(){this._chain=!0;return th
},
last: function(){
var values = this.recordsValues()
var values = this.recordsValues();
var record = values[values.length - 1];
return(record && record.clone());
},
@@ -2627,7 +2630,7 @@ arguments),this._chain)}});j.prototype.chain=function(){this._chain=!0;return th
fromJSON: function(objects){
if ( !objects ) return;
if ( typeof objects == "string" )
objects = JSON.parse(objects)
objects = JSON.parse(objects);
if ( isArray(objects) ) {
var results = [];
for (var i=0; i < objects.length; i++)

View File

@@ -62,10 +62,10 @@ function clippyCopiedCallback(a) {
}
// Logging function that accounts for browsers that don't have window.console
function log(m) {
if (window.console) console.log(m);
function log() {
if (window.console) console.log.apply(console,arguments);
}
var Docs = {
shebang: function() {

View File

@@ -233,12 +233,15 @@
// adeed by ayush
createAll: function(values){
// debugger;
values = this.fromJSON(values);
// debugger;
for (var i=0, il = values.length; i < il; i++) {
var record = values[i];
record.newRecord = false;
record.id = record.id || Spine.guid();
record.id = record.id || Spine.guid();
this.records[record.id] = record;
}
@@ -282,7 +285,7 @@
},
last: function(){
var values = this.recordsValues()
var values = this.recordsValues();
var record = values[values.length - 1];
return(record && record.clone());
},
@@ -331,7 +334,7 @@
fromJSON: function(objects){
if ( !objects ) return;
if ( typeof objects == "string" )
objects = JSON.parse(objects)
objects = JSON.parse(objects);
if ( isArray(objects) ) {
var results = [];
for (var i=0; i < objects.length; i++)

View File

@@ -10,10 +10,18 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
if (! (baseUrl.toLowerCase().indexOf("http:") == 0 || baseUrl.toLowerCase().indexOf("https:") == 0)) {
baseUrl = ("http://" + baseUrl);
}
baseUrl = baseUrl + "/resources.json";
// baseUrl = baseUrl + "/resources.json";
// log("using base url " + baseUrl);
var apiHost = baseUrl.substr(0, baseUrl.lastIndexOf("/"));
var rootResourcesApiName = baseUrl.substr(baseUrl.lastIndexOf("/") + 1, (baseUrl.lastIndexOf(".") - baseUrl.lastIndexOf("/") - 1));
// debugger
// var rootResourcesApiName = baseUrl.substr(baseUrl.lastIndexOf("/") + 1, (baseUrl.lastIndexOf(".") - baseUrl.lastIndexOf("/") - 1));
// assuming root swagger is resources
var rootResourcesApiName = "resources";
if (baseUrl.indexOf(".json") > -1) rootResourcesApiName += ".json";
var formatString = ".{format}";
var statusListener = statusCallback;
var apiKey = _apiKey;
@@ -24,16 +32,13 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
if (apiKey.length > 0)
apiKeySuffix = "?api_key=" + apiKey;
}
// log("apiHost=" + apiHost);
// log("apiKey=" + apiKey);
// log("rootResourcesApiName = " + rootResourcesApiName);
// utility functions
function log(m) {
if (window.console) console.log(m);
function log() {
if (window.console) console.log.apply(console,arguments);
}
function error(m) {
if (window.console) console.log("ERROR: " + m);
log("ERROR: " + m);
}
function updateStatus(status) {
@@ -65,12 +70,16 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
this.path_xml = this.path.replace("{format}", "xml");
this.baseUrl = apiHost;
//execluded 9 letters to remove .{format} from name
this.name = this.path.substr(1, this.path.length - formatString.length - 1).replace(/\//g, "_");
this.name = this.path.split("/");
this.name = this.name[this.name.length - 1];
this.name = this.name.replace(".{format}",'').replace(/\//g, "_");
// this.name = this.path.substr(1, this.path.length - formatString.length - 1).replace(/\//g, "_");
this.apiList = Api.sub();
this.modelList = ApiModel.sub();
},
addApis: function(apiObjects) {
log("apiObjects: %o", apiObjects);
this.apiList.createAll(apiObjects);
},
@@ -365,19 +374,19 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
var controller = this;
updateStatus("Fetching API List...");
$.getJSON(apiHost + "/" + rootResourcesApiName + ".json" + apiKeySuffix,
function(response) {
//log(response);
ApiResource.createAll(response.apis);
var url = apiHost + "/" + rootResourcesApiName + apiKeySuffix;
$.getJSON(url, function(response) {
// if (response.apis) {
ApiResource.createAll(response.apis);
// }
// get rid of the root resource list api since we're not going to document that
var obj = ApiResource.findByAttribute("name", rootResourcesApiName);
if (obj)
obj.destroy();
obj.destroy();
controller.fetchResources();
});
});
},
fetchResources: function() {
@@ -392,8 +401,11 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
fetchResource: function(apiResource) {
var controller = this;
updateStatus("Fetching " + apiResource.name + "...");
$.getJSON(apiHost + apiResource.path_json + apiKeySuffix,
var resourceUrl = apiHost + apiResource.path_json + apiKeySuffix;
log("resourceUrl: %o", resourceUrl);
$.getJSON(resourceUrl,
function(response) {
log(response);
controller.loadResources(response, apiResource);
});
},
@@ -402,7 +414,9 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
try {
this.countLoaded++;
// log(response);
apiResource.addApis(response.apis);
// if (response.apis) {
apiResource.addApis(response.apis);
// }
// updateStatus("Parsed Apis");
//log(response.models);
if (response.models) {

View File

@@ -32,6 +32,20 @@ jQuery(function($) {
apiSelectionController.adaptToScale();
});
this.handleEnter();
},
handleEnter: function(){
var self = this;
var submit = function() { self.showApi() }
$('#input_baseUrl').keydown(function(e) {
if(e.which != 13) return;
submit();
})
$('#input_apiKey').keydown(function(e) {
if(e.which != 13) return;
submit();
})
},
adaptToScale: function() {
@@ -44,10 +58,10 @@ jQuery(function($) {
// $('#input_baseUrl').width($('#input_baseUrl').width() + free_width - 50);
},
slapOn: function() {
// messageController.showMessage("Please enter the base URL of the API that you wish to explore.");
$("#content_message").show();
$("#resources_container").hide();
this.showApi();
},
@@ -66,11 +80,9 @@ jQuery(function($) {
if (baseUrl.length == 0) {
$("#input_baseUrl").wiggle();
} else {
if (this.supportsLocalStorage()) {
localStorage.setItem("com.wordnik.swagger.ui.apiKey", apiKey);
localStorage.setItem("com.wordnik.swagger.ui.baseUrl", baseUrl);
}
var resourceListController = ResourceListController.init({
baseUrl: baseUrl,
@@ -133,6 +145,7 @@ jQuery(function($) {
// Create convenience references to Spine models
this.ApiResource = swaggerService.ApiResource();
debugger;
this.ApiResource.bind("refresh", this.addAll);
},
@@ -165,14 +178,9 @@ jQuery(function($) {
init: function() {
this.render();
this.apiResource = this.item;
this.apiList = this.apiResource.apiList;
this.modelList = this.apiResource.modelList;
// log("------------- apiResource : " + this.apiResource.name);
// this.apiList.logAll();
// this.modelList.logAll();
this.apiList.each(this.renderApi);
},
@@ -358,7 +366,7 @@ jQuery(function($) {
});
// Attach controller to window
// Attach controller to window*
window.apiSelectionController = ApiSelectionController.init();
if (this.baseUrl) {

View File

@@ -62,10 +62,10 @@ function clippyCopiedCallback(a) {
}
// Logging function that accounts for browsers that don't have window.console
function log(m) {
if (window.console) console.log(m);
function log() {
if (window.console) console.log.apply(console,arguments);
}
var Docs = {
shebang: function() {

View File

@@ -233,12 +233,15 @@
// adeed by ayush
createAll: function(values){
// debugger;
values = this.fromJSON(values);
// debugger;
for (var i=0, il = values.length; i < il; i++) {
var record = values[i];
record.newRecord = false;
record.id = record.id || Spine.guid();
record.id = record.id || Spine.guid();
this.records[record.id] = record;
}
@@ -282,7 +285,7 @@
},
last: function(){
var values = this.recordsValues()
var values = this.recordsValues();
var record = values[values.length - 1];
return(record && record.clone());
},
@@ -331,7 +334,7 @@
fromJSON: function(objects){
if ( !objects ) return;
if ( typeof objects == "string" )
objects = JSON.parse(objects)
objects = JSON.parse(objects);
if ( isArray(objects) ) {
var results = [];
for (var i=0; i < objects.length; i++)

View File

@@ -10,10 +10,18 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
if (! (baseUrl.toLowerCase().indexOf("http:") == 0 || baseUrl.toLowerCase().indexOf("https:") == 0)) {
baseUrl = ("http://" + baseUrl);
}
baseUrl = baseUrl + "/resources.json";
// baseUrl = baseUrl + "/resources.json";
// log("using base url " + baseUrl);
var apiHost = baseUrl.substr(0, baseUrl.lastIndexOf("/"));
var rootResourcesApiName = baseUrl.substr(baseUrl.lastIndexOf("/") + 1, (baseUrl.lastIndexOf(".") - baseUrl.lastIndexOf("/") - 1));
// debugger
// var rootResourcesApiName = baseUrl.substr(baseUrl.lastIndexOf("/") + 1, (baseUrl.lastIndexOf(".") - baseUrl.lastIndexOf("/") - 1));
// assuming root swagger is resources
var rootResourcesApiName = "resources";
if (baseUrl.indexOf(".json") > -1) rootResourcesApiName += ".json";
var formatString = ".{format}";
var statusListener = statusCallback;
var apiKey = _apiKey;
@@ -24,16 +32,13 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
if (apiKey.length > 0)
apiKeySuffix = "?api_key=" + apiKey;
}
// log("apiHost=" + apiHost);
// log("apiKey=" + apiKey);
// log("rootResourcesApiName = " + rootResourcesApiName);
// utility functions
function log(m) {
if (window.console) console.log(m);
function log() {
if (window.console) console.log.apply(console,arguments);
}
function error(m) {
if (window.console) console.log("ERROR: " + m);
log("ERROR: " + m);
}
function updateStatus(status) {
@@ -65,12 +70,16 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
this.path_xml = this.path.replace("{format}", "xml");
this.baseUrl = apiHost;
//execluded 9 letters to remove .{format} from name
this.name = this.path.substr(1, this.path.length - formatString.length - 1).replace(/\//g, "_");
this.name = this.path.split("/");
this.name = this.name[this.name.length - 1];
this.name = this.name.replace(".{format}",'').replace(/\//g, "_");
// this.name = this.path.substr(1, this.path.length - formatString.length - 1).replace(/\//g, "_");
this.apiList = Api.sub();
this.modelList = ApiModel.sub();
},
addApis: function(apiObjects) {
log("apiObjects: %o", apiObjects);
this.apiList.createAll(apiObjects);
},
@@ -365,19 +374,19 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
var controller = this;
updateStatus("Fetching API List...");
$.getJSON(apiHost + "/" + rootResourcesApiName + ".json" + apiKeySuffix,
function(response) {
//log(response);
ApiResource.createAll(response.apis);
var url = apiHost + "/" + rootResourcesApiName + apiKeySuffix;
$.getJSON(url, function(response) {
// if (response.apis) {
ApiResource.createAll(response.apis);
// }
// get rid of the root resource list api since we're not going to document that
var obj = ApiResource.findByAttribute("name", rootResourcesApiName);
if (obj)
obj.destroy();
obj.destroy();
controller.fetchResources();
});
});
},
fetchResources: function() {
@@ -392,8 +401,11 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
fetchResource: function(apiResource) {
var controller = this;
updateStatus("Fetching " + apiResource.name + "...");
$.getJSON(apiHost + apiResource.path_json + apiKeySuffix,
var resourceUrl = apiHost + apiResource.path_json + apiKeySuffix;
log("resourceUrl: %o", resourceUrl);
$.getJSON(resourceUrl,
function(response) {
log(response);
controller.loadResources(response, apiResource);
});
},
@@ -402,7 +414,9 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) {
try {
this.countLoaded++;
// log(response);
apiResource.addApis(response.apis);
// if (response.apis) {
apiResource.addApis(response.apis);
// }
// updateStatus("Parsed Apis");
//log(response.models);
if (response.models) {

View File

@@ -32,6 +32,20 @@ jQuery(function($) {
apiSelectionController.adaptToScale();
});
this.handleEnter();
},
handleEnter: function(){
var self = this;
var submit = function() { self.showApi() }
$('#input_baseUrl').keydown(function(e) {
if(e.which != 13) return;
submit();
})
$('#input_apiKey').keydown(function(e) {
if(e.which != 13) return;
submit();
})
},
adaptToScale: function() {
@@ -44,10 +58,10 @@ jQuery(function($) {
// $('#input_baseUrl').width($('#input_baseUrl').width() + free_width - 50);
},
slapOn: function() {
// messageController.showMessage("Please enter the base URL of the API that you wish to explore.");
$("#content_message").show();
$("#resources_container").hide();
this.showApi();
},
@@ -66,11 +80,9 @@ jQuery(function($) {
if (baseUrl.length == 0) {
$("#input_baseUrl").wiggle();
} else {
if (this.supportsLocalStorage()) {
localStorage.setItem("com.wordnik.swagger.ui.apiKey", apiKey);
localStorage.setItem("com.wordnik.swagger.ui.baseUrl", baseUrl);
}
var resourceListController = ResourceListController.init({
baseUrl: baseUrl,
@@ -133,6 +145,7 @@ jQuery(function($) {
// Create convenience references to Spine models
this.ApiResource = swaggerService.ApiResource();
debugger;
this.ApiResource.bind("refresh", this.addAll);
},
@@ -165,14 +178,9 @@ jQuery(function($) {
init: function() {
this.render();
this.apiResource = this.item;
this.apiList = this.apiResource.apiList;
this.modelList = this.apiResource.modelList;
// log("------------- apiResource : " + this.apiResource.name);
// this.apiList.logAll();
// this.modelList.logAll();
this.apiList.each(this.renderApi);
},
@@ -358,7 +366,7 @@ jQuery(function($) {
});
// Attach controller to window
// Attach controller to window*
window.apiSelectionController = ApiSelectionController.init();
if (this.baseUrl) {

View File

@@ -226,7 +226,6 @@ form
display: block
clear: both
&.select
label
select
display: block
clear: both