Browse Source

renamed discoveryUrl to url to match js change

bubble
Tony Tam 11 years ago
parent
commit
2a206b0a6b
9 changed files with 63 additions and 46 deletions
  1. +1
    -1
      dist/index.html
  2. +23
    -14
      dist/lib/swagger.js
  3. +6
    -6
      dist/swagger-ui.js
  4. +1
    -1
      dist/swagger-ui.min.js
  5. +23
    -14
      lib/swagger.js
  6. +2
    -2
      src/main/coffeescript/SwaggerUi.coffee
  7. +4
    -4
      src/main/coffeescript/view/HeaderView.coffee
  8. +1
    -1
      src/main/html/index.html
  9. +2
    -3
      src/test/swagger-ui-spec.coffee

+ 1
- 1
dist/index.html View File

@@ -20,7 +20,7 @@
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
window.swaggerUi = new SwaggerUi({ window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs",
url:"http://localhost:8002/api/api-docs",
dom_id:"swagger-ui-container", dom_id:"swagger-ui-container",
supportHeaderParams: false, supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put', 'delete'], supportedSubmitMethods: ['get', 'post', 'put', 'delete'],


+ 23
- 14
dist/lib/swagger.js View File

@@ -5,7 +5,7 @@


SwaggerApi = (function() { 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; SwaggerApi.prototype.debug = false;


@@ -15,12 +15,21 @@


SwaggerApi.prototype.authorizationScheme = null; SwaggerApi.prototype.authorizationScheme = null;


function SwaggerApi(options) {
function SwaggerApi(url, options) {
if (options == null) { if (options == null) {
options = {}; 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']; this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
if (options.success != null) { if (options.success != null) {
@@ -37,21 +46,21 @@
SwaggerApi.prototype.build = function() { SwaggerApi.prototype.build = function() {
var obj, var obj,
_this = this; _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 = { obj = {
url: this.discoveryUrl,
url: this.url,
method: "get", method: "get",
on: { on: {
error: function(response) { 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) { } else if (error.status === 0) {
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
} else if (error.status === 404) { } 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 { } else {
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.url);
} }
}, },
response: function(rawResponse) { response: function(rawResponse) {
@@ -83,10 +92,10 @@
} else { } else {
if (response.basePath) { if (response.basePath) {
_this.basePath = 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 { } else {
_this.basePath = _this.discoveryUrl;
_this.basePath = _this.url;
} }
_ref2 = response.apis; _ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {


+ 6
- 6
dist/swagger-ui.js View File

@@ -1384,7 +1384,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
}; };


SwaggerUi.prototype.updateSwaggerUi = function(data) { SwaggerUi.prototype.updateSwaggerUi = function(data) {
this.options.discoveryUrl = data.discoveryUrl;
this.options.url = data.url;
return this.load(); return this.load();
}; };


@@ -1393,7 +1393,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
if ((_ref = this.mainView) != null) { if ((_ref = this.mainView) != null) {
_ref.clear(); _ref.clear();
} }
this.headerView.update(this.options.discoveryUrl);
this.headerView.update(this.options.url);
return this.api = new SwaggerApi(this.options); 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) { HeaderView.prototype.showPetStore = function(e) {
return this.trigger('update-swagger-ui', { 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) { HeaderView.prototype.showWordnikDev = function(e) {
return this.trigger('update-swagger-ui', { 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(); e.preventDefault();
} }
return this.trigger('update-swagger-ui', { return this.trigger('update-swagger-ui', {
discoveryUrl: $('#input_baseUrl').val(),
url: $('#input_baseUrl').val(),
apiKey: $('#input_apiKey').val() apiKey: $('#input_apiKey').val()
}); });
}; };
@@ -1503,7 +1503,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
$('#input_apiKey').val(apiKey); $('#input_apiKey').val(apiKey);
if (trigger) { if (trigger) {
return this.trigger('update-swagger-ui', { return this.trigger('update-swagger-ui', {
discoveryUrl: url,
url: url,
apiKey: apiKey apiKey: apiKey
}); });
} }


+ 1
- 1
dist/swagger-ui.min.js
File diff suppressed because it is too large
View File


+ 23
- 14
lib/swagger.js View File

@@ -5,7 +5,7 @@


SwaggerApi = (function() { 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; SwaggerApi.prototype.debug = false;


@@ -15,12 +15,21 @@


SwaggerApi.prototype.authorizationScheme = null; SwaggerApi.prototype.authorizationScheme = null;


function SwaggerApi(options) {
function SwaggerApi(url, options) {
if (options == null) { if (options == null) {
options = {}; 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']; this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
if (options.success != null) { if (options.success != null) {
@@ -37,21 +46,21 @@
SwaggerApi.prototype.build = function() { SwaggerApi.prototype.build = function() {
var obj, var obj,
_this = this; _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 = { obj = {
url: this.discoveryUrl,
url: this.url,
method: "get", method: "get",
on: { on: {
error: function(response) { 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) { } else if (error.status === 0) {
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
} else if (error.status === 404) { } 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 { } else {
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.url);
} }
}, },
response: function(rawResponse) { response: function(rawResponse) {
@@ -83,10 +92,10 @@
} else { } else {
if (response.basePath) { if (response.basePath) {
_this.basePath = 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 { } else {
_this.basePath = _this.discoveryUrl;
_this.basePath = _this.url;
} }
_ref2 = response.apis; _ref2 = response.apis;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {


+ 2
- 2
src/main/coffeescript/SwaggerUi.coffee View File

@@ -34,14 +34,14 @@ class SwaggerUi extends Backbone.Router
# Event handler for when url/key is received from user # Event handler for when url/key is received from user
updateSwaggerUi: (data) -> updateSwaggerUi: (data) ->
@options.discoveryUrl = data.discoveryUrl
@options.url = data.url
@load() @load()
# Create an api and render # Create an api and render
load: -> load: ->
# Initialize the API object # Initialize the API object
@mainView?.clear() @mainView?.clear()
@headerView.update(@options.discoveryUrl)
@headerView.update(@options.url)
@api = new SwaggerApi(@options) @api = new SwaggerApi(@options)
# This is bound to success handler for SwaggerApi # This is bound to success handler for SwaggerApi


+ 4
- 4
src/main/coffeescript/view/HeaderView.coffee View File

@@ -12,13 +12,13 @@ class HeaderView extends Backbone.View
showPetStore: (e) -> showPetStore: (e) ->
@trigger( @trigger(
'update-swagger-ui' '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) -> showWordnikDev: (e) ->
@trigger( @trigger(
'update-swagger-ui' 'update-swagger-ui'
{discoveryUrl:"http://api.wordnik.com/v4/resources.json"}
{url:"http://api.wordnik.com/v4/resources.json"}
) )


showCustomOnKeyup: (e) -> showCustomOnKeyup: (e) ->
@@ -28,10 +28,10 @@ class HeaderView extends Backbone.View
e?.preventDefault() e?.preventDefault()
@trigger( @trigger(
'update-swagger-ui' 'update-swagger-ui'
{discoveryUrl: $('#input_baseUrl').val(), apiKey: $('#input_apiKey').val()}
{url: $('#input_baseUrl').val(), apiKey: $('#input_apiKey').val()}
) )


update: (url, apiKey, trigger = false) -> update: (url, apiKey, trigger = false) ->
$('#input_baseUrl').val url $('#input_baseUrl').val url
$('#input_apiKey').val apiKey $('#input_apiKey').val apiKey
@trigger 'update-swagger-ui', {discoveryUrl:url, apiKey:apiKey} if trigger
@trigger 'update-swagger-ui', {url:url, apiKey:apiKey} if trigger

+ 1
- 1
src/main/html/index.html View File

@@ -20,7 +20,7 @@
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
window.swaggerUi = new SwaggerUi({ window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs",
url:"http://localhost:8002/api/api-docs",
dom_id:"swagger-ui-container", dom_id:"swagger-ui-container",
supportHeaderParams: false, supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put', 'delete'], supportedSubmitMethods: ['get', 'post', 'put', 'delete'],


+ 2
- 3
src/test/swagger-ui-spec.coffee View File

@@ -1,5 +1,4 @@
window.api_key = 'a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5'
window.discoveryUrl = "http://api.wordnik.com/v4/resources.json"
window.url = "http://api.wordnik.com/v4/resources.json"


describe 'SwaggerUi', -> describe 'SwaggerUi', ->
@@ -8,7 +7,7 @@ describe 'SwaggerUi', ->
beforeEach -> beforeEach ->
window.ui = new SwaggerUi window.ui = new SwaggerUi
api_key: window.api_key api_key: window.api_key
discoveryUrl: window.discoveryUrl
url: window.url
waitsFor -> waitsFor ->
ui.ready ui.ready


Loading…
Cancel
Save