Skip to content

Commit 399d277

Browse files
committed
Merge pull request #24 from lostinthestory/master
remove collFormat, fix sidebar refresh height, nls swagger help box
2 parents 95894f3 + 6a5b91e commit 399d277

File tree

5 files changed

+76
-62
lines changed

5 files changed

+76
-62
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"name": "Nick O'Leary"
2222
},
2323
"dependencies": {
24-
"swagger-ui": "2.1.0"
24+
"swagger-ui": "2.1.0",
25+
"i18next-client": "1.10.2"
2526
}
2627
}

swagger/locales/en-US/swagger.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@
6161
"status": {
6262
"excluded": "Not included in Swagger",
6363
"missingconfig": "Swagger config not set"
64+
},
65+
"helpBox": {
66+
"title": "I see you're lacking Swagger doc...",
67+
"swaggerIntro": "Swagger is a simple yet powerful way to document your REST API.",
68+
"swaggerInfo": "The Swagger plug-in dynamically generates Swagger documentation based on input provided when setting up your HTTP endpoint nodes.",
69+
"swaggerInstructions0": "After building your REST APIs in the editor, click the HTTP endpoint node. You can then attach additional Swagger documentation to that node by clicking the add button next to Docs.",
70+
"swaggerInstructions1": "You are able to add additional details on the types of inputs and outputs expected from your endpoint by quickly navigating through the screens and providing some information.",
71+
"swaggerInstructions2": "Once your flow is deployed, this tab will be automatically populated by a visual representation of your API.",
72+
"swaggerOutro": "You can then use this Swagger-UI tab to effortlessly test your APIs."
6473
}
6574
}
6675
}

swagger/swagger-ui/swagger-ui.html

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<script src='reqs/swagger-ui.js' type='text/javascript'></script>
1818
<script src='reqs/lib/highlight.7.3.pack.js' type='text/javascript'></script>
1919
<script src='reqs/lib/marked.js' type='text/javascript'></script>
20+
<script src='reqs/i18next.min.js' type='text/javascript'></script>
2021
<script type="text/javascript">
2122
var url = parent.swaggerDocUrl;
2223
window.swaggerUi = new SwaggerUi({
@@ -30,12 +31,19 @@
3031
} else{
3132
$('.empty-swagger-doc').hide(1000);
3233
}
33-
console.log(window.swaggerUi.api.apisArray.length);
3434
},
3535
onFailure: function(data) {
3636
console.log("Unable to Load SwaggerUI");
3737
},
3838
});
39+
i18n.init({
40+
resGetPath: 'nls/__lng__/__ns__.json',
41+
load: 'current',
42+
ns: 'swagger',
43+
fallbackLng: 'en-us'
44+
}, function() {
45+
$('.empty-swagger-doc').i18n();
46+
});
3947
</script>
4048
<style>
4149
.empty-swagger-doc {
@@ -67,13 +75,13 @@ <h2><span class="fa-stack fa-lg">
6775
<i class="fa fa-circle-thin fa-stack-2x"></i>
6876
<i class="fa fa-question fa-stack-1x"></i>
6977
</span></h2>
70-
<h2>I see you're lacking Swagger doc...</h2>
71-
<p>Swagger is a simple yet powerful way to document your REST API.</p>
72-
<p>The Swagger plug-in dynamically generates Swagger documentation based on input provided when setting up your HTTP endpoint nodes.</p>
73-
<p>After building your REST APIs in the editor, click the HTTP endpoint node. You can then attach additional Swagger documentation to that node by clicking the <b>add</b> button next to <b>Docs</b></p>
74-
<p>You are able to add additional details on the types of inputs and outputs expected from your endpoint by quickly navigating through the screens and providing some information.</p>
75-
<p>Once your flow is deployed, this tab will be automatically populated by a visual representation of your API.</p>
76-
<p>You can then use this Swagger-UI tab to effortlessly test your APIs<p>
78+
<h2 data-i18n>swagger.helpBox.title</h2>
79+
<p data-i18n>swagger.helpBox.swaggerIntro</p>
80+
<p data-i18n>swagger.helpBox.swaggerInfo</p>
81+
<p data-i18n>swagger.helpBox.swaggerInstructions0</p>
82+
<p data-i18n>swagger.helpBox.swaggerInstructions1</p>
83+
<p data-i18n>swagger.helpBox.swaggerInstructions2</p>
84+
<p data-i18n>swagger.helpBox.swaggerOutro<p>
7785
</div>
7886
<div id="swagger-ui-container" class="swagger-ui-wrap" style="margin: 10px"></div>
7987

swagger/swagger.html

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,9 @@
117117
onpaletteadd: function() {
118118
//setup swagger-ui
119119
var swaggerUi;
120-
var refreshInfoHeight = 75;
121120
var content = $("<div/>",{
122121
id:"tab-swagger-ui", style:"position: relative; padding: 0px 4px; height: 100%; overflow: hidden"
123122
});
124-
var refreshInfo = $("<div/>", {
125-
style:"height: "+ refreshInfoHeight + "px; margin: 5px; text-align: center"
126-
});
127123

128124
RED.events.on("deploy",function() {
129125
if (swaggerUi) {
@@ -146,9 +142,9 @@
146142
swaggerFrame.load(function(){
147143
swaggerUi = document.getElementById('swagger-ui-frame').contentWindow.swaggerUi;
148144
window.addEventListener('resize', function(event){
149-
swaggerFrame.css('height', content.height() - refreshInfoHeight - 45);
145+
swaggerFrame.css('height', content.height());
150146
});
151-
swaggerFrame.css('height', content.height() - refreshInfoHeight - 45);
147+
swaggerFrame.css('height', content.height());
152148
swaggerUi.load();
153149
});
154150
},
@@ -249,7 +245,6 @@
249245
*/
250246
var generateTypeRow = function(opts, top) {
251247
var row = $("<div/>");
252-
253248
row.addClass('node-swagger-type-row');
254249
row.css('margin-top', '3px');
255250
if(top){
@@ -281,7 +276,7 @@
281276
}
282277
typeSelect.val(opts.type);
283278
var formatLabel = $("<label/>", {
284-
class: "node-swgger-type-format-label",
279+
class: "node-swagger-type-format-label",
285280
style: "width: auto; margin-left:20px; margin-right: 10px;"
286281
}).text(formatText).appendTo(row);
287282
formatLabel.popover({
@@ -296,37 +291,48 @@
296291
style: "width: 150px;",
297292
type: "text"
298293
}).val(opts.format).appendTo(row);
299-
var collFormatSelect = $('<select/>', {
300-
class: "node-swagger-type-collection-format",
301-
style: "width: 150px;",
302-
type: "text"
303-
}).appendTo(row);
304-
var collformatoptions = ["csv", "ssv", "tsv", "pipes"];
305-
if (top) {
306-
collformatoptions.push("multi");
307-
}
308-
for (var i = 0; i < collformatoptions.length; i++) {
309-
collFormatSelect.append($("<option/>").val(collformatoptions[i]).text(collformatoptions[i]));
294+
295+
if(!opts.propertyRow){
296+
var collFormatSelect = $('<select/>', {
297+
class: "node-swagger-type-collection-format",
298+
style: "width: 150px;",
299+
type: "text"
300+
}).appendTo(row);
301+
var collformatoptions = ["csv", "ssv", "tsv", "pipes"];
302+
if (top) {
303+
collformatoptions.push("multi");
304+
}
305+
for (var i = 0; i < collformatoptions.length; i++) {
306+
collFormatSelect.append($("<option/>").val(collformatoptions[i]).text(collformatoptions[i]));
307+
}
308+
collFormatSelect.val(opts.collectionFormat || "csv");
310309
}
311-
collFormatSelect.val(opts.collectionFormat || "csv");
312310

313311
typeSelect.change(function() {
314312
var t = $(this).val();
315313
if (t != "array") {
316314
$(this).parent().find(".node-swagger-type-row").remove();
317315
$(this).parent().find(".node-swagger-type-format").show();
316+
$(this).parent().find(".node-swagger-type-format-label").text(formatText);
318317
$(this).parent().find(".node-swagger-type-collection-format").hide();
319-
318+
320319
if (t == "ref") {
321-
$(this).parent().find(".node-swgger-type-format-label").text("");
320+
$(this).parent().find(".node-swagger-type-format-label").text("");
322321
} else {
323-
$(this).parent().find(".node-swgger-type-format-label").text(formatText);
322+
$(this).parent().find(".node-swagger-type-format-label").text(formatText);
324323
}
325324

326325

327326
} else {
328327
$(this).parent().find(".node-swagger-type-format").hide();
329328
$(this).parent().find(".node-swagger-type-collection-format").show();
329+
if(opts.propertyRow){
330+
$(this).parent().find(".node-swagger-type-format-label").text("");
331+
if(!opts.items){
332+
opts.items = {};
333+
}
334+
opts.items.propertyRow = true;
335+
}
330336
generateTypeRow(opts.items || {}, false).appendTo($(this).parent());
331337
}
332338
});
@@ -374,6 +380,7 @@
374380
style: "margin-top: 3px; margin-left: 10px;"
375381
});
376382
propList.appendTo(row);
383+
opts.propertyRow = true;
377384
var typeRow = generateTypeRow(opts, true).appendTo(propList);
378385
return row;
379386
}
@@ -854,33 +861,13 @@
854861
Recursive function used to generate the items object that is required for array objects
855862
*/
856863
var getArrayItems = function (row){
857-
console.log(row);
858864
var items = {};
859865
var type = row.find('.node-swagger-type-select').val();
860866
items.type = type;
861867
if(type == 'array'){
862868
var collFormat = row.find('.node-swagger-type-collection-format').val();
863-
items.collectionFormat = collFormat;
864-
var nextRow = row.children(".node-swagger-type-row");
865-
items.items = getArrayItems(nextRow);
866-
} else{
867-
var format = row.find('.node-swagger-type-format').val();
868-
items.format = format;
869-
}
870-
return items;
871-
}
872-
873-
/**
874-
Temporary placeholder to remove collectionFormat since swagger does not allow it
875-
*/
876-
var getArrayItemsSchema = function (row){
877-
console.log(row);
878-
var items = {};
879-
var type = row.find('.node-swagger-type-select').val();
880-
items.type = type;
881-
if(type == 'array'){
882-
//var collFormat = row.find('.node-swagger-type-collection-format').val();
883-
//items.collectionFormat = collFormat;
869+
if(collFormat)
870+
items.collectionFormat = collFormat;
884871
var nextRow = row.children(".node-swagger-type-row");
885872
items.items = getArrayItems(nextRow);
886873
} else{
@@ -922,13 +909,13 @@
922909
current.type = ctype;
923910
if (current.type == "array") {
924911

925-
//commented out until we figure out what to do with collectionFormat in schema objects
926-
//var collFormat = row.children(".node-swagger-type-collection-format").val();
927-
//current.collectionFormat = collFormat;
912+
var collFormat = row.children(".node-swagger-type-collection-format").val();
913+
if(collFormat)
914+
current.collectionFormat = collFormat;
928915

929916
var nextRow = row.children(".node-swagger-type-row");
930917

931-
current.items = getArrayItemsSchema(nextRow);
918+
current.items = getArrayItems(nextRow);
932919

933920
} else {
934921
var format = row.children(".node-swagger-type-format").val();
@@ -1012,13 +999,13 @@
1012999
current.type = ctype;
10131000
if (current.type == "array") {
10141001

1015-
//commented out until we figure out what to do with collectionFormat in schema objects
1016-
//var collFormat = row.children(".node-swagger-type-collection-format").val();
1017-
//current.collectionFormat = collFormat;
1002+
var collFormat = row.children(".node-swagger-type-collection-format").val();
1003+
if(collFormat)
1004+
current.collectionFormat = collFormat;
10181005

10191006
var nextRow = row.children(".node-swagger-type-row");
10201007

1021-
current.items = getArrayItemsSchema(nextRow);
1008+
current.items = getArrayItems(nextRow);
10221009

10231010
} else {
10241011
var format = row.children(".node-swagger-type-format").val();

swagger/swagger.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,19 @@ module.exports = function(RED) {
148148
}
149149
RED.nodes.registerType("swagger-doc",SwaggerDoc);
150150

151+
152+
RED.httpAdmin.get('/swagger-ui/reqs/i18next.min.js', function(req, res){
153+
var filename = path.join(__dirname , '../node_modules/i18next-client/i18next.min.js');
154+
res.sendfile(filename);
155+
});
151156
RED.httpAdmin.get('/swagger-ui/reqs/*', function(req, res){
152157
var filename = path.join(__dirname , '../node_modules/swagger-ui/dist', req.params[0]);
153158
res.sendfile(filename);
154159
});
160+
RED.httpAdmin.get('/swagger-ui/nls/*', function(req, res){
161+
var filename = path.join(__dirname , 'locales', req.params[0]);
162+
res.sendfile(filename);
163+
});
155164
RED.httpAdmin.get('/swagger-ui/*', function(req, res){
156165
var filename = path.join(__dirname , 'swagger-ui', req.params[0]);
157166
res.sendfile(filename);

0 commit comments

Comments
 (0)