Permalink
Browse files

(flavor) custom-swagger v2.2.0

  • Loading branch information...
devinivy committed Dec 15, 2018
1 parent 8e24c92 commit df7374b4a5f0b3d8314e68dbd1398778276619a0
Showing with 206 additions and 2 deletions.
  1. +6 −2 package.json
  2. +3 −0 server/manifest.js
  3. +39 −0 server/plugins/swagger/index.js
  4. +158 −0 server/plugins/swagger/swagger.html
@@ -4,7 +4,7 @@
"main": "lib/index.js",
"scripts": {
"start": "node server",
"test": "lab -a code -L",
"test": "lab -a code -I 'core,__core-js_shared__' -L",
"lint": "eslint ."
},
"dependencies": {
@@ -20,9 +20,13 @@
"eslint-config-hapi": "12.x.x",
"eslint-plugin-hapi": "4.x.x",
"glue": "5.x.x",
"handlebars": "4.x.x",
"hapi": "17.x.x",
"hapi-swagger": "9.x.x",
"hpal-debug": "1.x.x",
"inert": "5.x.x",
"lab": "18.x.x",
"toys": "2.x.x"
"toys": "2.x.x",
"vision": "5.x.x"
}
}
@@ -33,6 +33,9 @@ module.exports = new Confidence.Store({
plugin: '../lib', // Main plugin
options: {}
},
{
plugin: './plugins/swagger'
},
{
plugin: {
$filter: { $env: 'NODE_ENV' },
@@ -0,0 +1,39 @@
'use strict';

const Inert = require('inert');
const Vision = require('vision');
const Handlebars = require('handlebars');
const HapiSwagger = require('hapi-swagger');
const Package = require('../../../package.json');

module.exports = {
name: 'app-swagger',
async register(server) {

await server.register([
Inert,
Vision,
{
plugin: HapiSwagger,
options: {
documentationPage: false,
validatorUrl: null,
info: {
version: Package.version
}
}
}
]);

server.views({
engines: { html: Handlebars },
path: __dirname
});

server.route({
method: 'get',
path: '/documentation',
handler: { view: { template: 'swagger' } }
});
}
};
@@ -0,0 +1,158 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{{hapiSwagger.info.title}}</title>
<link rel="icon" type="image/png" href="{{hapiSwagger.swaggerUIPath}}images/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="{{hapiSwagger.swaggerUIPath}}images/favicon-16x16.png" sizes="16x16" />
<link href='{{hapiSwagger.swaggerUIPath}}css/typography.css' media='screen' rel='stylesheet' type='text/css' />
<link href='{{hapiSwagger.swaggerUIPath}}css/reset.css' media='screen' rel='stylesheet' type='text/css' />
<link href='{{hapiSwagger.swaggerUIPath}}css/screen.css' media='screen' rel='stylesheet' type='text/css' />
<link href='{{hapiSwagger.swaggerUIPath}}css/reset.css' media='print' rel='stylesheet' type='text/css' />
<link href='{{hapiSwagger.swaggerUIPath}}css/print.css' media='print' rel='stylesheet' type='text/css' />
<script src='{{hapiSwagger.swaggerUIPath}}lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/handlebars-2.0.0.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/js-yaml.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/lodash.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/backbone-min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}swagger-ui.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/jsoneditor.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/marked.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lib/swagger-oauth.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}extend.js' type='text/javascript'></script>

<!-- Some basic translations -->
<script src='{{hapiSwagger.swaggerUIPath}}lang/translator.js' type='text/javascript'></script>
<script src='{{hapiSwagger.swaggerUIPath}}lang/{{hapiSwagger.lang}}.js' type='text/javascript'></script>

<script type="text/javascript">
// List tags in the order they where created
var tags = [];
{{#each hapiSwagger.tags}}
tags.push('{{name}}');
{{/each}}
$(function () {
$('#input_apiKey').hide();
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "{{{hapiSwagger.jsonPath}}}";
}
// Pre-load translate
if(window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
// Pull validatorUrl string or null
var validatorUrl = null;
{{#if hapiSwagger.validatorUrl}}
validatorUrl = '{{hapiSwagger.validatorUrl}}';
{{/if}}
window.swaggerUi = new SwaggerUi({
url: url,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
onComplete: function (swaggerApi, swaggerUi) {
if (typeof initOAuth == "function") {
initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret",
realm: "your-realms",
appName: "your-app-name",
scopeSeparator: ","
});
}
if (window.SwaggerTranslator) {
window.SwaggerTranslator.translate();
}
$('pre code').each(function (i, e) {
hljs.highlightBlock(e)
});
if (Array.isArray(swaggerApi.auths) && swaggerApi.auths.length > 0 && swaggerApi.auths[0].type === "apiKey") {
auth = swaggerApi.auths[0].value;
$('#input_apiKey').show();
}
addApiKeyAuthorization();
// Load custom js
{{#if hapiSwagger.uiCompleteScript}}
{{{hapiSwagger.uiCompleteScript}}}
{{/if}}
},
onFailure: function (data) {
log("Unable to Load SwaggerUI", data);
},
docExpansion: "{{hapiSwagger.expanded}}",
apisSorter: apisSorter.{{hapiSwagger.sortTags}},
operationsSorter: operationsSorter.{{hapiSwagger.sortEndpoints}},
showRequestHeaders: false,
validatorUrl: validatorUrl,
jsonEditor: {{#if hapiSwagger.jsonEditor}}true{{else}}false{{/if}}
});
function addApiKeyAuthorization() {
if($('#input_apiKey')){
var key = $('#input_apiKey')[0].value;
if (key && key.trim() != "") {
if('{{{hapiSwagger.keyPrefix}}}' !== ''){
key = '{{{hapiSwagger.keyPrefix}}}' + key;
}
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization(auth.name, key, auth.in);
window.swaggerUi.api.clientAuthorizations.add(auth.name, apiKeyAuth);
log("Added key " + key);
}
}
}
$('#input_apiKey').change(addApiKeyAuthorization);
/*
* Pre-populate an API key
*
var apiKey = "Bearer 12345";
$('#input_apiKey').val(apiKey);
*
*/
window.swaggerUi.load();
function log() {
if ('console' in window) {
console.log.apply(console, arguments);
}
}
});
</script>
</head>
<body class="swagger-section">
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.io">swagger</a>
<form id='api_selector' onsubmit="return false">
<div class='input'><input placeholder="api_key" id="input_apiKey" style="display:none" name="apiKey" type="text"/></div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" style="display:none" name="baseUrl" type="text"/></div>
<!--<div class='input'><a id="explore" href="#" data-sw-translate>Explore</a></div>-->
</form>
</div>
</div>

<div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
</body>
</html>

0 comments on commit df7374b

Please sign in to comment.