Skip to content

Commit 91a9cfb

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: provide option sorter=[alpha|method] fixed undefined variable errors remove console.info swagger-api#254 alphabetical sort of apis and operations under apis new option sortAlphabetical=true|false updated distro to include swagger-api#493 Fix for issue swagger-api#492; HTML in response headers switched to snippet view swagger-api#491 updated versions, swagger-js Conflicts: dist/swagger-ui.js dist/swagger-ui.min.js src/main/coffeescript/view/SignatureView.coffee
2 parents 6eaaeaa + c948b40 commit 91a9cfb

File tree

12 files changed

+96
-44
lines changed

12 files changed

+96
-44
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ To use swagger-ui you should take a look at the [source of swagger-ui html page]
5959
* *dom_id parameter* is the the id of a dom element inside which SwaggerUi will put the user interface for swagger
6060
* *booleanValues* SwaggerUI renders boolean data types as a dropdown. By default it provides a 'true' and 'false' string as the possible choices. You can use this parameter to change the values in dropdown to be something else, for example 0 and 1 by setting booleanValues to new Array(0, 1)
6161
* *docExpansion* controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details)
62+
* *sorter* apply a sort to the API list. It can be 'alpha' (sort paths alphanumerically) or 'method' (sort operations by HTTP method). Default is the order returned by the server unchanged.
6263
* *onComplete* is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
6364
* *onFailure* is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
6465
* All other parameters are explained in greater detail below

dist/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
onFailure: function(data) {
4848
log("Unable to Load SwaggerUI");
4949
},
50-
docExpansion: "none"
50+
docExpansion: "none",
51+
sorter : "alpha"
5152
});
5253

5354
$('#input_apiKey').change(function() {

dist/lib/swagger.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,24 @@ var SwaggerResource = function(resourceObj, api) {
372372
}
373373
}
374374

375-
SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
376-
var parts, pos, url;
375+
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
376+
var pos, url;
377377
url = this.api.basePath;
378378
pos = url.lastIndexOf(relativeBasePath);
379-
if (pos === -1) {
380-
parts = url.split("/");
381-
url = parts[0] + "//" + parts[2];
379+
var parts = url.split("/");
380+
var rootUrl = parts[0] + "//" + parts[2];
381+
//if the relative path is '/' return the root url
382+
if (relativeBasePath === '/'){
383+
return rootUrl
384+
}
385+
//if the relative path is not in the base path
386+
else if (pos === -1 ) {
382387
if (relativeBasePath.indexOf("/") === 0) {
383388
return url + relativeBasePath;
384389
} else {
385390
return url + "/" + relativeBasePath;
386391
}
387-
} else if (relativeBasePath === "/") {
388-
return url.substring(0, pos);
392+
//If the relative path is in the base path
389393
} else {
390394
return url.substring(0, pos) + relativeBasePath;
391395
}
@@ -1275,7 +1279,7 @@ SwaggerHttp.prototype.isIE8 = function() {
12751279
var JQueryHttpClient = function(options) {
12761280
"use strict";
12771281
if(!jQuery){
1278-
var jQuery = window.jQuery;
1282+
var jQuery = window.jQuery;
12791283
}
12801284
}
12811285

@@ -1350,7 +1354,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
13501354
else
13511355
return cb.response(out);
13521356
};
1353-
1357+
13541358
jQuery.support.cors = true;
13551359
return jQuery.ajax(obj);
13561360
}
@@ -1471,8 +1475,8 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
14711475
var status = null;
14721476
var key;
14731477

1474-
if(typeof authorizations === 'undefined') {
1475-
// apply all keys since no authorizations hash is defined
1478+
// if the "authorizations" key is undefined, or has an empty array, add all keys
1479+
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
14761480
for (key in this.authz) {
14771481
value = this.authz[key];
14781482
result = value.apply(obj, authorizations);

dist/swagger-ui.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swagger-ui.js
2-
// version 2.0.17
2+
// version 2.0.18
33
$(function() {
44

55
// Helper function for vertically aligning DOM elements
@@ -1298,7 +1298,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
12981298
this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...');
12991299
this.mainView = new MainView({
13001300
model: this.api,
1301-
el: $('#' + this.dom_id)
1301+
el: $('#' + this.dom_id),
1302+
swaggerOptions: this.options
13021303
}).render();
13031304
this.showMessage();
13041305
switch (this.options.docExpansion) {
@@ -1443,14 +1444,42 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
14431444
})(Backbone.View);
14441445

14451446
MainView = (function(_super) {
1447+
var sorters;
1448+
14461449
__extends(MainView, _super);
14471450

14481451
function MainView() {
14491452
_ref2 = MainView.__super__.constructor.apply(this, arguments);
14501453
return _ref2;
14511454
}
14521455

1453-
MainView.prototype.initialize = function() {};
1456+
sorters = {
1457+
'alpha': function(a, b) {
1458+
return a.path.localeCompare(b.path);
1459+
},
1460+
'method': function(a, b) {
1461+
return a.method.localeCompare(b.method);
1462+
}
1463+
};
1464+
1465+
MainView.prototype.initialize = function(opts) {
1466+
var route, sorter, sorterName, _i, _len, _ref3;
1467+
if (opts == null) {
1468+
opts = {};
1469+
}
1470+
if (opts.swaggerOptions.sorter) {
1471+
sorterName = opts.swaggerOptions.sorter;
1472+
sorter = sorters[sorterName];
1473+
_ref3 = this.model.apisArray;
1474+
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
1475+
route = _ref3[_i];
1476+
route.operationsArray.sort(sorter);
1477+
}
1478+
if (sorterName === "alpha") {
1479+
return this.model.apisArray.sort(sorter);
1480+
}
1481+
}
1482+
};
14541483

14551484
MainView.prototype.render = function() {
14561485
var counter, id, resource, resources, _i, _len, _ref3;
@@ -1563,8 +1592,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
15631592
OperationView.prototype.mouseEnter = function(e) {
15641593
var elem, hgh, pos, scMaxX, scMaxY, scX, scY, wd, x, y;
15651594
elem = $(e.currentTarget.parentNode).find('#api_information_panel');
1566-
x = event.pageX;
1567-
y = event.pageY;
1595+
x = e.pageX;
1596+
y = e.pageY;
15681597
scX = $(window).scrollLeft();
15691598
scY = $(window).scrollTop();
15701599
scMaxX = scX + $(window).width();
@@ -1992,7 +2021,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
19922021
$(".request_url", $(this.el)).html("<pre>" + url + "</pre>");
19932022
$(".response_code", $(this.el)).html("<pre>" + response.status + "</pre>");
19942023
$(".response_body", $(this.el)).html(response_body);
1995-
$(".response_headers", $(this.el)).html("<pre>" + JSON.stringify(response.headers, null, " ").replace(/\n/g, "<br>") + "</pre>");
2024+
$(".response_headers", $(this.el)).html("<pre>" + _.escape(JSON.stringify(response.headers, null, " ")).replace(/\n/g, "<br>") + "</pre>");
19962025
$(".response", $(this.el)).slideDown();
19972026
$(".response_hider", $(this.el)).show();
19982027
$(".response_throbber", $(this.el)).hide();
@@ -2200,9 +2229,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
22002229
var template;
22012230
template = this.template();
22022231
$(this.el).html(template(this.model));
2203-
this.switchToDescription();
2204-
$('.description-link', $(this.el)).removeClass('selected');
2205-
$(".description", $(this.el)).hide();
2232+
this.switchToSnippet();
2233+
$('.snippet-link', $(this.el)).removeClass('selected');
2234+
$(".snippet", $(this.el)).hide();
22062235
this.isParam = this.model.isParam;
22072236
if (this.isParam) {
22082237
$('.notice', $(this.el)).text('Click to set as parameter value');

dist/swagger-ui.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/swagger.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,24 @@ var SwaggerResource = function(resourceObj, api) {
372372
}
373373
}
374374

375-
SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
376-
var parts, pos, url;
375+
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
376+
var pos, url;
377377
url = this.api.basePath;
378378
pos = url.lastIndexOf(relativeBasePath);
379-
if (pos === -1) {
380-
parts = url.split("/");
381-
url = parts[0] + "//" + parts[2];
379+
var parts = url.split("/");
380+
var rootUrl = parts[0] + "//" + parts[2];
381+
//if the relative path is '/' return the root url
382+
if (relativeBasePath === '/'){
383+
return rootUrl
384+
}
385+
//if the relative path is not in the base path
386+
else if (pos === -1 ) {
382387
if (relativeBasePath.indexOf("/") === 0) {
383388
return url + relativeBasePath;
384389
} else {
385390
return url + "/" + relativeBasePath;
386391
}
387-
} else if (relativeBasePath === "/") {
388-
return url.substring(0, pos);
392+
//If the relative path is in the base path
389393
} else {
390394
return url.substring(0, pos) + relativeBasePath;
391395
}
@@ -1275,7 +1279,7 @@ SwaggerHttp.prototype.isIE8 = function() {
12751279
var JQueryHttpClient = function(options) {
12761280
"use strict";
12771281
if(!jQuery){
1278-
var jQuery = window.jQuery;
1282+
var jQuery = window.jQuery;
12791283
}
12801284
}
12811285

@@ -1350,7 +1354,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
13501354
else
13511355
return cb.response(out);
13521356
};
1353-
1357+
13541358
jQuery.support.cors = true;
13551359
return jQuery.ajax(obj);
13561360
}
@@ -1471,8 +1475,8 @@ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
14711475
var status = null;
14721476
var key;
14731477

1474-
if(typeof authorizations === 'undefined') {
1475-
// apply all keys since no authorizations hash is defined
1478+
// if the "authorizations" key is undefined, or has an empty array, add all keys
1479+
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
14761480
for (key in this.authz) {
14771481
value = this.authz[key];
14781482
result = value.apply(obj, authorizations);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-ui",
3-
"version": "2.0.17",
3+
"version": "2.0.18",
44
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
55
"scripts": {
66
"build": "PATH=$PATH:./node_modules/.bin cake dist",

src/main/coffeescript/SwaggerUi.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SwaggerUi extends Backbone.Router
5555
# so it gets called when SwaggerApi completes loading
5656
render:() ->
5757
@showMessage('Finished Loading Resource Information. Rendering Swagger UI...')
58-
@mainView = new MainView({model: @api, el: $('#' + @dom_id)}).render()
58+
@mainView = new MainView({model: @api, el: $('#' + @dom_id), swaggerOptions: @options}).render()
5959
@showMessage()
6060
switch @options.docExpansion
6161
when "full" then Docs.expandOperationsForResource('')

src/main/coffeescript/view/MainView.coffee

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
class MainView extends Backbone.View
2-
initialize: ->
2+
sorters = {
3+
'alpha' : (a,b) -> return a.path.localeCompare(b.path),
4+
'method' : (a,b) -> return a.method.localeCompare(b.method),
5+
}
36

7+
initialize: (opts={}) ->
8+
if opts.swaggerOptions.sorter
9+
sorterName = opts.swaggerOptions.sorter
10+
sorter = sorters[sorterName]
11+
for route in @model.apisArray
12+
route.operationsArray.sort sorter
13+
if (sorterName == "alpha") # sort top level paths if alpha
14+
@model.apisArray.sort sorter
15+
416
render: ->
517
# Render the outer container for resources
618
$(@el).html(Handlebars.templates.main(@model))
@@ -25,4 +37,4 @@ class MainView extends Backbone.View
2537
$('#resources').append resourceView.render().el
2638

2739
clear: ->
28-
$(@el).html ''
40+
$(@el).html ''

src/main/coffeescript/view/OperationView.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class OperationView extends Backbone.View
1414

1515
mouseEnter: (e) ->
1616
elem = $(e.currentTarget.parentNode).find('#api_information_panel')
17-
x = event.pageX
18-
y = event.pageY
17+
x = e.pageX
18+
y = e.pageY
1919
scX = $(window).scrollLeft()
2020
scY = $(window).scrollTop()
2121
scMaxX = scX + $(window).width()
@@ -361,7 +361,7 @@ class OperationView extends Backbone.View
361361
$(".request_url", $(@el)).html "<pre>" + url + "</pre>"
362362
$(".response_code", $(@el)).html "<pre>" + response.status + "</pre>"
363363
$(".response_body", $(@el)).html response_body
364-
$(".response_headers", $(@el)).html "<pre>" + JSON.stringify(response.headers, null, " ").replace(/\n/g, "<br>") + "</pre>"
364+
$(".response_headers", $(@el)).html "<pre>" + _.escape(JSON.stringify(response.headers, null, " ")).replace(/\n/g, "<br>") + "</pre>"
365365
$(".response", $(@el)).slideDown()
366366
$(".response_hider", $(@el)).show()
367367
$(".response_throbber", $(@el)).hide()

0 commit comments

Comments
 (0)