Skip to content

Commit

Permalink
Merge pull request #4 from nci-ats/api-ui
Browse files Browse the repository at this point in the history
v0.0.3v2
  • Loading branch information
brianfunk committed Jun 28, 2015
2 parents d028184 + a16f7c9 commit 6db7817
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
8 changes: 5 additions & 3 deletions client/api-docs/apis.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"apiVersion": "0.0.3",
"basePath": "/api-docs",
"resourcePath": "/api",
"apis": [
{
"description": "FDA Food Recall - Search API",
"path": "http://localhost:8000/api-docs/search.json"
"path": "/search.json"
},
{
"description": "FDA Food Recall - Count API",
"path": "http://localhost:8000/api-docs/count.json"
"path": "/count.json"
},
{
"description": "FDA Food Recall - Crowdsource API",
"path": "http://localhost:8000/api-docs/crowd.json"
"path": "/crowd.json"
}
],
"swaggerVersion": "1.2"
Expand Down
2 changes: 1 addition & 1 deletion client/api-docs/count.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"apiVersion": "1.0",
"apiVersion": "0.0.3",
"apis": [
{
"operations": [
Expand Down
2 changes: 1 addition & 1 deletion client/api-docs/crowd.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"apiVersion": "1.0",
"apiVersion": "0.0.3",
"apis": [
{
"operations": [
Expand Down
35 changes: 30 additions & 5 deletions client/api-docs/lib/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments)[0] );
//console.log( Array.prototype.slice.call(arguments)[0] );
}
};

Expand Down Expand Up @@ -341,15 +341,24 @@ var SwaggerResource = function(resourceObj, api) {
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
this.description = resourceObj.description;

// use relative path
var url_arr = window.location.href.split("/");
var full_url = url_arr[0] + "//" + url_arr[2];

var parts = this.path.split("/");
this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath;

this.basePath = full_url;
this.api.basePath = this.api.basePath;

this.operations = {};
this.operationsArray = [];
this.modelsArray = [];
this.models = {};
this.rawModels = {};
this.useJQuery = (typeof api.useJQuery !== 'undefined' ? api.useJQuery : null);

//console.log('this.api.basePath : ' + this.api.basePath );

if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
this.addApiDeclaration(resourceObj);
Expand All @@ -360,8 +369,11 @@ var SwaggerResource = function(resourceObj, api) {
if (this.path.substring(0, 4) === 'http') {
this.url = this.path.replace('{format}', 'json');
} else {
this.url = this.api.basePath + this.path.replace('{format}', 'json');
this.url = this.basePath + this.api.basePath + this.path.replace('{format}', 'json');
}

//console.log('this.url : ' + this.url );

this.api.progress('fetching resource ' + this.name + ': ' + this.url);
obj = {
url: this.url,
Expand Down Expand Up @@ -392,7 +404,7 @@ SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
url = this.api.basePath;
pos = url.lastIndexOf(relativeBasePath);
var parts = url.split("/");
var rootUrl = parts[0] + "//" + parts[2];
var rootUrl = parts[0] + "//" + parts[2];

if(relativeBasePath.indexOf("http") === 0)
return relativeBasePath;
Expand Down Expand Up @@ -947,7 +959,19 @@ SwaggerOperation.prototype.encodePathParam = function(pathParam) {
};

SwaggerOperation.prototype.urlify = function(args) {

// get relative path
var url_arr = window.location.href.split("/");
var full_url = url_arr[0] + "//" + url_arr[2];

if ((!this.resource.basePath) || (this.resource.basePath == '//undefined') || (this.resource.basePath == 'undefined') || (this.resource.basePath == '')) {
this.resource.basePath = full_url;
}

var url = this.resource.basePath + this.pathJson();

//console.log('url ^ : ' + url );

var params = this.parameters;
for(var i = 0; i < params.length; i ++){
var param = params[i];
Expand Down Expand Up @@ -1165,7 +1189,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
body = data;
}
}

if (!((this.headers != null) && (this.headers.mock != null))) {
obj = {
url: this.url,
Expand Down Expand Up @@ -1459,6 +1483,7 @@ ShredHttpClient.prototype.execute = function(obj) {
var cb = obj.on, res;

var transform = function(response) {

var out = {
headers: response._headers,
url: response.request.url,
Expand Down
2 changes: 1 addition & 1 deletion client/api-docs/search.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"apiVersion": "1.0",
"apiVersion": "0.0.3",
"apis": [
{
"operations": [
Expand Down
2 changes: 1 addition & 1 deletion client/api-docs/swagger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments)[0] );
//console.log( Array.prototype.slice.call(arguments)[0] );
}
};

Expand Down

0 comments on commit 6db7817

Please sign in to comment.