Commit 2a206b0a authored by Tony Tam's avatar Tony Tam
Browse files

renamed discoveryUrl to url to match js change

parent 6a5dfdce
......@@ -20,7 +20,7 @@
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs",
url:"http://localhost:8002/api/api-docs",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
......
......@@ -5,7 +5,7 @@
SwaggerApi = (function() {
SwaggerApi.prototype.discoveryUrl = "http://api.wordnik.com/v4/resources.json";
SwaggerApi.prototype.url = "http://api.wordnik.com/v4/resources.json";
SwaggerApi.prototype.debug = false;
......@@ -15,12 +15,21 @@
SwaggerApi.prototype.authorizationScheme = null;
function SwaggerApi(options) {
function SwaggerApi(url, options) {
if (options == null) {
options = {};
}
if (options.discoveryUrl != null) {
this.discoveryUrl = options.discoveryUrl;
if (url) {
if (url.url) {
options = url;
} else {
this.url = url;
}
} else {
options = url;
}
if (options.url != null) {
this.url = options.url;
}
this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
if (options.success != null) {
......@@ -37,21 +46,21 @@
SwaggerApi.prototype.build = function() {
var obj,
_this = this;
this.progress('fetching resource list: ' + this.discoveryUrl);
console.log('getting ' + this.discoveryUrl);
this.progress('fetching resource list: ' + this.url);
console.log('getting ' + this.url);
obj = {
url: this.discoveryUrl,
url: this.url,
method: "get",
on: {
error: function(response) {
if (_this.discoveryUrl.substring(0, 4) !== 'http') {
return _this.fail('Please specify the protocol for ' + _this.discoveryUrl);
if (_this.url.substring(0, 4) !== 'http') {
return _this.fail('Please specify the protocol for ' + _this.url);
} else if (error.status === 0) {
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
} else if (error.status === 404) {
return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl);
return _this.fail('Can\'t read swagger JSON from ' + _this.url);
} else {
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.url);
}
},
response: function(rawResponse) {
......@@ -83,10 +92,10 @@
} else {
if (response.basePath) {
_this.basePath = response.basePath;
} else if (_this.discoveryUrl.indexOf('?') > 0) {
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
} else if (_this.url.indexOf('?') > 0) {
_this.basePath = _this.url.substring(0, _this.url.lastIndexOf('?'));
} else {
_this.basePath = _this.discoveryUrl;
_this.basePath = _this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
......
......@@ -1384,7 +1384,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
};
SwaggerUi.prototype.updateSwaggerUi = function(data) {
this.options.discoveryUrl = data.discoveryUrl;
this.options.url = data.url;
return this.load();
};
......@@ -1393,7 +1393,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
if ((_ref = this.mainView) != null) {
_ref.clear();
}
this.headerView.update(this.options.discoveryUrl);
this.headerView.update(this.options.url);
return this.api = new SwaggerApi(this.options);
};
......@@ -1469,13 +1469,13 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
HeaderView.prototype.showPetStore = function(e) {
return this.trigger('update-swagger-ui', {
discoveryUrl: "http://petstore.swagger.wordnik.com/api/api-docs.json"
url: "http://petstore.swagger.wordnik.com/api/api-docs.json"
});
};
HeaderView.prototype.showWordnikDev = function(e) {
return this.trigger('update-swagger-ui', {
discoveryUrl: "http://api.wordnik.com/v4/resources.json"
url: "http://api.wordnik.com/v4/resources.json"
});
};
......@@ -1490,7 +1490,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
e.preventDefault();
}
return this.trigger('update-swagger-ui', {
discoveryUrl: $('#input_baseUrl').val(),
url: $('#input_baseUrl').val(),
apiKey: $('#input_apiKey').val()
});
};
......@@ -1503,7 +1503,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
$('#input_apiKey').val(apiKey);
if (trigger) {
return this.trigger('update-swagger-ui', {
discoveryUrl: url,
url: url,
apiKey: apiKey
});
}
......
This diff is collapsed.
......@@ -5,7 +5,7 @@
SwaggerApi = (function() {
SwaggerApi.prototype.discoveryUrl = "http://api.wordnik.com/v4/resources.json";
SwaggerApi.prototype.url = "http://api.wordnik.com/v4/resources.json";
SwaggerApi.prototype.debug = false;
......@@ -15,12 +15,21 @@
SwaggerApi.prototype.authorizationScheme = null;
function SwaggerApi(options) {
function SwaggerApi(url, options) {
if (options == null) {
options = {};
}
if (options.discoveryUrl != null) {
this.discoveryUrl = options.discoveryUrl;
if (url) {
if (url.url) {
options = url;
} else {
this.url = url;
}
} else {
options = url;
}
if (options.url != null) {
this.url = options.url;
}
this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
if (options.success != null) {
......@@ -37,21 +46,21 @@
SwaggerApi.prototype.build = function() {
var obj,
_this = this;
this.progress('fetching resource list: ' + this.discoveryUrl);
console.log('getting ' + this.discoveryUrl);
this.progress('fetching resource list: ' + this.url);
console.log('getting ' + this.url);
obj = {
url: this.discoveryUrl,
url: this.url,
method: "get",
on: {
error: function(response) {
if (_this.discoveryUrl.substring(0, 4) !== 'http') {
return _this.fail('Please specify the protocol for ' + _this.discoveryUrl);
if (_this.url.substring(0, 4) !== 'http') {
return _this.fail('Please specify the protocol for ' + _this.url);
} else if (error.status === 0) {
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
} else if (error.status === 404) {
return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl);
return _this.fail('Can\'t read swagger JSON from ' + _this.url);
} else {
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.url);
}
},
response: function(rawResponse) {
......@@ -83,10 +92,10 @@
} else {
if (response.basePath) {
_this.basePath = response.basePath;
} else if (_this.discoveryUrl.indexOf('?') > 0) {
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
} else if (_this.url.indexOf('?') > 0) {
_this.basePath = _this.url.substring(0, _this.url.lastIndexOf('?'));
} else {
_this.basePath = _this.discoveryUrl;
_this.basePath = _this.url;
}
_ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
......
......@@ -34,14 +34,14 @@ class SwaggerUi extends Backbone.Router
# Event handler for when url/key is received from user
updateSwaggerUi: (data) ->
@options.discoveryUrl = data.discoveryUrl
@options.url = data.url
@load()
# Create an api and render
load: ->
# Initialize the API object
@mainView?.clear()
@headerView.update(@options.discoveryUrl)
@headerView.update(@options.url)
@api = new SwaggerApi(@options)
# This is bound to success handler for SwaggerApi
......
......@@ -12,13 +12,13 @@ class HeaderView extends Backbone.View
showPetStore: (e) ->
@trigger(
'update-swagger-ui'
{discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json"}
{url:"http://petstore.swagger.wordnik.com/api/api-docs.json"}
)
showWordnikDev: (e) ->
@trigger(
'update-swagger-ui'
{discoveryUrl:"http://api.wordnik.com/v4/resources.json"}
{url:"http://api.wordnik.com/v4/resources.json"}
)
showCustomOnKeyup: (e) ->
......@@ -28,10 +28,10 @@ class HeaderView extends Backbone.View
e?.preventDefault()
@trigger(
'update-swagger-ui'
{discoveryUrl: $('#input_baseUrl').val(), apiKey: $('#input_apiKey').val()}
{url: $('#input_baseUrl').val(), apiKey: $('#input_apiKey').val()}
)
update: (url, apiKey, trigger = false) ->
$('#input_baseUrl').val url
$('#input_apiKey').val apiKey
@trigger 'update-swagger-ui', {discoveryUrl:url, apiKey:apiKey} if trigger
@trigger 'update-swagger-ui', {url:url, apiKey:apiKey} if trigger
......@@ -20,7 +20,7 @@
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs",
url:"http://localhost:8002/api/api-docs",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
......
window.api_key = 'a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5'
window.discoveryUrl = "http://api.wordnik.com/v4/resources.json"
window.url = "http://api.wordnik.com/v4/resources.json"
describe 'SwaggerUi', ->
......@@ -8,7 +7,7 @@ describe 'SwaggerUi', ->
beforeEach ->
window.ui = new SwaggerUi
api_key: window.api_key
discoveryUrl: window.discoveryUrl
url: window.url
waitsFor ->
ui.ready
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment