Skip to content

Commit 6a5b91e

Browse files
committed
NLS Swagger Help Box
Fixes #22
1 parent 0ad20ec commit 6a5b91e

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
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 & 7 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({
@@ -35,6 +36,14 @@
3536
console.log("Unable to Load SwaggerUI");
3637
},
3738
});
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+
});
3847
</script>
3948
<style>
4049
.empty-swagger-doc {
@@ -66,13 +75,13 @@ <h2><span class="fa-stack fa-lg">
6675
<i class="fa fa-circle-thin fa-stack-2x"></i>
6776
<i class="fa fa-question fa-stack-1x"></i>
6877
</span></h2>
69-
<h2>I see you're lacking Swagger doc...</h2>
70-
<p>Swagger is a simple yet powerful way to document your REST API.</p>
71-
<p>The Swagger plug-in dynamically generates Swagger documentation based on input provided when setting up your HTTP endpoint nodes.</p>
72-
<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>
73-
<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>
74-
<p>Once your flow is deployed, this tab will be automatically populated by a visual representation of your API.</p>
75-
<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>
7685
</div>
7786
<div id="swagger-ui-container" class="swagger-ui-wrap" style="margin: 10px"></div>
7887

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)