Fix linting errors
This commit is contained in:
parent
2987655479
commit
c923710ce2
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"extends": "loopback",
|
"extends": "loopback",
|
||||||
"rules": {
|
"rules": {
|
||||||
"max-len": ["error", 80, 4, {
|
"max-len": ["error", 90, 4, {
|
||||||
"ignoreComments": true,
|
"ignoreComments": true,
|
||||||
"ignoreUrls": true,
|
"ignoreUrls": true,
|
||||||
"ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)"
|
"ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)"
|
||||||
|
|
56
index.js
56
index.js
|
@ -33,14 +33,14 @@
|
||||||
loopback.version.split('.')[0] || 1;
|
loopback.version.split('.')[0] || 1;
|
||||||
|
|
||||||
if (loopbackMajor < 2) {
|
if (loopbackMajor < 2) {
|
||||||
throw new Error('loopback-component-explorer requires loopback 2.0 or newer');
|
throw new Error('loopback-component-explorer requires loopback 2.0 or newer');
|
||||||
}
|
}
|
||||||
|
|
||||||
options = _defaults({}, options, {
|
options = _defaults({}, options, {
|
||||||
resourcePath: 'swagger.json',
|
resourcePath: 'swagger.json',
|
||||||
apiInfo: loopbackApplication.get('apiInfo') || {},
|
apiInfo: loopbackApplication.get('apiInfo') || {},
|
||||||
swaggerUI: true,
|
swaggerUI: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
var router = new loopback.Router();
|
var router = new loopback.Router();
|
||||||
|
|
||||||
|
@ -51,37 +51,37 @@
|
||||||
router.get('/config.json', function(req, res) {
|
router.get('/config.json', function(req, res) {
|
||||||
// Get the path we're mounted at. It's best to get this from the referer
|
// Get the path we're mounted at. It's best to get this from the referer
|
||||||
// in case we're proxied at a deep path.
|
// in case we're proxied at a deep path.
|
||||||
var source = url.parse(req.headers.referer || '').pathname;
|
var source = url.parse(req.headers.referer || '').pathname;
|
||||||
// If no referer is available, use the incoming url.
|
// If no referer is available, use the incoming url.
|
||||||
if (!source) {
|
if (!source) {
|
||||||
source = req.originalUrl.replace(/\/config.json(\?.*)?$/, '');
|
source = req.originalUrl.replace(/\/config.json(\?.*)?$/, '');
|
||||||
}
|
}
|
||||||
res.send({
|
res.send({
|
||||||
url: urlJoin(source, '/' + options.resourcePath),
|
url: urlJoin(source, '/' + options.resourcePath),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (options.swaggerUI) {
|
if (options.swaggerUI) {
|
||||||
// Allow specifying a static file roots for swagger files. Any files in
|
// Allow specifying a static file roots for swagger files. Any files in
|
||||||
// these folders will override those in the swagger-ui distribution.
|
// these folders will override those in the swagger-ui distribution.
|
||||||
// In this way one could e.g. make changes to index.html without having
|
// In this way one could e.g. make changes to index.html without having
|
||||||
// to worry about constantly pulling in JS updates.
|
// to worry about constantly pulling in JS updates.
|
||||||
if (options.uiDirs) {
|
if (options.uiDirs) {
|
||||||
if (typeof options.uiDirs === 'string') {
|
if (typeof options.uiDirs === 'string') {
|
||||||
router.use(loopback.static(options.uiDirs));
|
router.use(loopback.static(options.uiDirs));
|
||||||
} else if (Array.isArray(options.uiDirs)) {
|
} else if (Array.isArray(options.uiDirs)) {
|
||||||
options.uiDirs.forEach(function(dir) {
|
options.uiDirs.forEach(function(dir) {
|
||||||
router.use(loopback.static(dir));
|
router.use(loopback.static(dir));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// File in node_modules are overridden by a few customizations
|
// File in node_modules are overridden by a few customizations
|
||||||
router.use(loopback.static(STATIC_ROOT));
|
router.use(loopback.static(STATIC_ROOT));
|
||||||
|
|
||||||
// Swagger UI distribution
|
// Swagger UI distribution
|
||||||
router.use(loopback.static(SWAGGER_UI_ROOT));
|
router.use(loopback.static(SWAGGER_UI_ROOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,8 @@
|
||||||
// listening to modelRemoted event for updating the swaggerObject
|
// listening to modelRemoted event for updating the swaggerObject
|
||||||
// with the newly created model to appear in the Swagger UI.
|
// with the newly created model to appear in the Swagger UI.
|
||||||
loopbackApplication.on('modelRemoted', function() {
|
loopbackApplication.on('modelRemoted', function() {
|
||||||
swaggerObject = createSwaggerObject(loopbackApplication, opts);
|
swaggerObject = createSwaggerObject(loopbackApplication, opts);
|
||||||
});
|
});
|
||||||
|
|
||||||
var resourcePath = opts && opts.resourcePath || 'swagger.json';
|
var resourcePath = opts && opts.resourcePath || 'swagger.json';
|
||||||
if (resourcePath[0] !== '/') resourcePath = '/' + resourcePath;
|
if (resourcePath[0] !== '/') resourcePath = '/' + resourcePath;
|
||||||
|
@ -111,8 +111,8 @@
|
||||||
setupCors(swaggerApp, remotes);
|
setupCors(swaggerApp, remotes);
|
||||||
|
|
||||||
swaggerApp.get(resourcePath, function sendSwaggerObject(req, res) {
|
swaggerApp.get(resourcePath, function sendSwaggerObject(req, res) {
|
||||||
res.status(200).send(swaggerObject);
|
res.status(200).send(swaggerObject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupCors(swaggerApp, remotes) {
|
function setupCors(swaggerApp, remotes) {
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
"description": "Browse and test your LoopBack app's APIs",
|
"description": "Browse and test your LoopBack app's APIs",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha"
|
"lint": "eslint .",
|
||||||
|
"test": "mocha",
|
||||||
|
"posttest": "npm run lint"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -17,6 +17,7 @@ $(function() {
|
||||||
var accessToken;
|
var accessToken;
|
||||||
function loadSwaggerUi(config) {
|
function loadSwaggerUi(config) {
|
||||||
var methodOrder = ['get', 'head', 'options', 'put', 'post', 'delete'];
|
var methodOrder = ['get', 'head', 'options', 'put', 'post', 'delete'];
|
||||||
|
/* eslint-disable camelcase */
|
||||||
window.swaggerUi = new SwaggerUi({
|
window.swaggerUi = new SwaggerUi({
|
||||||
validatorUrl: null,
|
validatorUrl: null,
|
||||||
url: config.url || '/swagger/resources',
|
url: config.url || '/swagger/resources',
|
||||||
|
@ -58,6 +59,7 @@ $(function() {
|
||||||
methodOrder.indexOf(a.method) - methodOrder.indexOf(b.method);
|
methodOrder.indexOf(a.method) - methodOrder.indexOf(b.method);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
$('#explore').click(setAccessToken);
|
$('#explore').click(setAccessToken);
|
||||||
$('#api_selector').submit(setAccessToken);
|
$('#api_selector').submit(setAccessToken);
|
||||||
|
@ -73,7 +75,8 @@ $(function() {
|
||||||
log('key: ' + key);
|
log('key: ' + key);
|
||||||
if (key && key.trim() !== '') {
|
if (key && key.trim() !== '') {
|
||||||
log('added accessToken ' + key);
|
log('added accessToken ' + key);
|
||||||
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization('access_token', key, 'query');
|
var apiKeyAuth =
|
||||||
|
new SwaggerClient.ApiKeyAuthorization('access_token', key, 'query');
|
||||||
window.swaggerUi.api.clientAuthorizations.add('key', apiKeyAuth);
|
window.swaggerUi.api.clientAuthorizations.add('key', apiKeyAuth);
|
||||||
accessToken = key;
|
accessToken = key;
|
||||||
$('.accessTokenDisplay').text('Token Set.').addClass('set');
|
$('.accessTokenDisplay').text('Token Set.').addClass('set');
|
||||||
|
@ -83,10 +86,9 @@ $(function() {
|
||||||
if (window.localStorage) {
|
if (window.localStorage) {
|
||||||
window.localStorage.setItem(lsKey, key);
|
window.localStorage.setItem(lsKey, key);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
// If submitted with an empty token, remove the current token. Can be
|
// If submitted with an empty token, remove the current token. Can be
|
||||||
// useful to intentionally remove authorization.
|
// useful to intentionally remove authorization.
|
||||||
else {
|
|
||||||
log('removed accessToken.');
|
log('removed accessToken.');
|
||||||
$('.accessTokenDisplay').text('Token Not Set.').removeClass('set');
|
$('.accessTokenDisplay').text('Token Not Set.').removeClass('set');
|
||||||
$('.accessTokenDisplay').removeAttr('data-tooltip');
|
$('.accessTokenDisplay').removeAttr('data-tooltip');
|
||||||
|
@ -116,5 +118,3 @@ $(function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ var urlJoin = require('../lib/url-join');
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
|
|
||||||
describe('explorer', function() {
|
describe('explorer', function() {
|
||||||
|
|
||||||
describe('with default config', function() {
|
describe('with default config', function() {
|
||||||
beforeEach(givenLoopBackAppWithExplorer());
|
beforeEach(givenLoopBackAppWithExplorer());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue