Auto-update by eslint --fix
This commit is contained in:
parent
144fc8000d
commit
2987655479
|
@ -7,13 +7,13 @@ var User = loopback.Model.extend('user', {
|
||||||
username: 'string',
|
username: 'string',
|
||||||
email: 'string',
|
email: 'string',
|
||||||
sensitiveInternalProperty: 'string',
|
sensitiveInternalProperty: 'string',
|
||||||
}, {hidden: ['sensitiveInternalProperty']});
|
}, { hidden: ['sensitiveInternalProperty'] });
|
||||||
|
|
||||||
User.attachTo(loopback.memory());
|
User.attachTo(loopback.memory());
|
||||||
app.model(User);
|
app.model(User);
|
||||||
|
|
||||||
var apiPath = '/api';
|
var apiPath = '/api';
|
||||||
app.use('/explorer', explorer(app, {basePath: apiPath}));
|
app.use('/explorer', explorer(app, { basePath: apiPath }));
|
||||||
app.use(apiPath, loopback.rest());
|
app.use(apiPath, loopback.rest());
|
||||||
console.log('Explorer mounted at localhost:' + port + '/explorer');
|
console.log('Explorer mounted at localhost:' + port + '/explorer');
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,15 @@ var explorer = require('../');
|
||||||
var port = 3000;
|
var port = 3000;
|
||||||
|
|
||||||
var Product = loopback.PersistedModel.extend('product', {
|
var Product = loopback.PersistedModel.extend('product', {
|
||||||
foo: {type: 'string', required: true},
|
foo: { type: 'string', required: true },
|
||||||
bar: 'string',
|
bar: 'string',
|
||||||
aNum: {type: 'number', min: 1, max: 10, required: true, default: 5}
|
aNum: { type: 'number', min: 1, max: 10, required: true, default: 5 },
|
||||||
});
|
});
|
||||||
Product.attachTo(loopback.memory());
|
Product.attachTo(loopback.memory());
|
||||||
app.model(Product);
|
app.model(Product);
|
||||||
|
|
||||||
var apiPath = '/api';
|
var apiPath = '/api';
|
||||||
app.use('/explorer', explorer(app, {basePath: apiPath}));
|
app.use('/explorer', explorer(app, { basePath: apiPath }));
|
||||||
app.use(apiPath, loopback.rest());
|
app.use(apiPath, loopback.rest());
|
||||||
console.log('Explorer mounted at http://localhost:' + port + '/explorer');
|
console.log('Explorer mounted at http://localhost:' + port + '/explorer');
|
||||||
|
|
||||||
|
|
40
index.js
40
index.js
|
@ -2,17 +2,17 @@
|
||||||
/*!
|
/*!
|
||||||
* Adds dynamically-updated docs as /explorer
|
* Adds dynamically-updated docs as /explorer
|
||||||
*/
|
*/
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var urlJoin = require('./lib/url-join');
|
var urlJoin = require('./lib/url-join');
|
||||||
var _defaults = require('lodash').defaults;
|
var _defaults = require('lodash').defaults;
|
||||||
var cors = require('cors');
|
var cors = require('cors');
|
||||||
var createSwaggerObject = require('loopback-swagger').generateSwaggerSpec;
|
var createSwaggerObject = require('loopback-swagger').generateSwaggerSpec;
|
||||||
var SWAGGER_UI_ROOT = require('strong-swagger-ui/index').dist;
|
var SWAGGER_UI_ROOT = require('strong-swagger-ui/index').dist;
|
||||||
var STATIC_ROOT = path.join(__dirname, 'public');
|
var STATIC_ROOT = path.join(__dirname, 'public');
|
||||||
|
|
||||||
module.exports = explorer;
|
module.exports = explorer;
|
||||||
explorer.routes = routes;
|
explorer.routes = routes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example usage:
|
* Example usage:
|
||||||
|
@ -21,13 +21,13 @@ explorer.routes = routes;
|
||||||
* explorer(app, options);
|
* explorer(app, options);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function explorer(loopbackApplication, options) {
|
function explorer(loopbackApplication, options) {
|
||||||
options = _defaults({}, options, { mountPath: '/explorer' });
|
options = _defaults({}, options, { mountPath: '/explorer' });
|
||||||
loopbackApplication.use(options.mountPath, routes(loopbackApplication, options));
|
loopbackApplication.use(options.mountPath, routes(loopbackApplication, options));
|
||||||
loopbackApplication.set('loopback-component-explorer', options);
|
loopbackApplication.set('loopback-component-explorer', options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function routes(loopbackApplication, options) {
|
function routes(loopbackApplication, options) {
|
||||||
var loopback = loopbackApplication.loopback;
|
var loopback = loopbackApplication.loopback;
|
||||||
var loopbackMajor = loopback && loopback.version &&
|
var loopbackMajor = loopback && loopback.version &&
|
||||||
loopback.version.split('.')[0] || 1;
|
loopback.version.split('.')[0] || 1;
|
||||||
|
@ -39,7 +39,7 @@ function routes(loopbackApplication, options) {
|
||||||
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();
|
||||||
|
@ -57,7 +57,7 @@ function routes(loopbackApplication, options) {
|
||||||
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),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ function routes(loopbackApplication, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup Swagger documentation on the given express app.
|
* Setup Swagger documentation on the given express app.
|
||||||
|
@ -95,7 +95,7 @@ function routes(loopbackApplication, options) {
|
||||||
* swagger documentation.
|
* swagger documentation.
|
||||||
* @param {Object} opts Options.
|
* @param {Object} opts Options.
|
||||||
*/
|
*/
|
||||||
function mountSwagger(loopbackApplication, swaggerApp, opts) {
|
function mountSwagger(loopbackApplication, swaggerApp, opts) {
|
||||||
var swaggerObject = createSwaggerObject(loopbackApplication, opts);
|
var swaggerObject = createSwaggerObject(loopbackApplication, opts);
|
||||||
|
|
||||||
// listening to modelRemoted event for updating the swaggerObject
|
// listening to modelRemoted event for updating the swaggerObject
|
||||||
|
@ -113,12 +113,12 @@ function mountSwagger(loopbackApplication, swaggerApp, opts) {
|
||||||
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) {
|
||||||
var corsOptions = remotes.options && remotes.options.cors ||
|
var corsOptions = remotes.options && remotes.options.cors ||
|
||||||
{ origin: true, credentials: true };
|
{ origin: true, credentials: true };
|
||||||
|
|
||||||
// TODO(bajtos) Skip CORS when remotes.options.cors === false
|
// TODO(bajtos) Skip CORS when remotes.options.cors === false
|
||||||
swaggerApp.use(cors(corsOptions));
|
swaggerApp.use(cors(corsOptions));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
/*global SwaggerUi, log, ApiKeyAuthorization, hljs, window, $ */
|
/*global SwaggerUi, log, ApiKeyAuthorization, hljs, window, $ */
|
||||||
$(function() {
|
$(function() {
|
||||||
// Pre load translate...
|
// Pre load translate...
|
||||||
if(window.SwaggerTranslator) {
|
if (window.SwaggerTranslator) {
|
||||||
window.SwaggerTranslator.translate();
|
window.SwaggerTranslator.translate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ $(function() {
|
||||||
log(swaggerApi);
|
log(swaggerApi);
|
||||||
log(swaggerUi);
|
log(swaggerUi);
|
||||||
|
|
||||||
if(window.SwaggerTranslator) {
|
if (window.SwaggerTranslator) {
|
||||||
window.SwaggerTranslator.translate();
|
window.SwaggerTranslator.translate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ $(function() {
|
||||||
return pathCompare !== 0 ?
|
return pathCompare !== 0 ?
|
||||||
pathCompare :
|
pathCompare :
|
||||||
methodOrder.indexOf(a.method) - methodOrder.indexOf(b.method);
|
methodOrder.indexOf(a.method) - methodOrder.indexOf(b.method);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#explore').click(setAccessToken);
|
$('#explore').click(setAccessToken);
|
||||||
|
@ -71,7 +71,7 @@ $(function() {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var key = $('#input_accessToken')[0].value;
|
var key = $('#input_accessToken')[0].value;
|
||||||
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);
|
||||||
|
|
|
@ -117,7 +117,7 @@ describe('explorer', function() {
|
||||||
beforeEach(function setupExplorerWithUiDirs() {
|
beforeEach(function setupExplorerWithUiDirs() {
|
||||||
app = loopback();
|
app = loopback();
|
||||||
explorer(app, {
|
explorer(app, {
|
||||||
uiDirs: [path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')]
|
uiDirs: [path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ describe('explorer', function() {
|
||||||
beforeEach(function setupExplorerWithoutUI() {
|
beforeEach(function setupExplorerWithoutUI() {
|
||||||
app = loopback();
|
app = loopback();
|
||||||
explorer(app, {
|
explorer(app, {
|
||||||
swaggerUI: false
|
swaggerUI: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ describe('explorer', function() {
|
||||||
|
|
||||||
it('should allow `uiDirs` to be defined as an Array', function(done) {
|
it('should allow `uiDirs` to be defined as an Array', function(done) {
|
||||||
explorer(app, {
|
explorer(app, {
|
||||||
uiDirs: [path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')]
|
uiDirs: [path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')],
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app).get('/explorer/')
|
request(app).get('/explorer/')
|
||||||
|
@ -212,7 +212,7 @@ describe('explorer', function() {
|
||||||
|
|
||||||
it('should allow `uiDirs` to be defined as an String', function(done) {
|
it('should allow `uiDirs` to be defined as an String', function(done) {
|
||||||
explorer(app, {
|
explorer(app, {
|
||||||
uiDirs: path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')
|
uiDirs: path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui'),
|
||||||
});
|
});
|
||||||
|
|
||||||
request(app).get('/explorer/')
|
request(app).get('/explorer/')
|
||||||
|
@ -238,7 +238,7 @@ describe('explorer', function() {
|
||||||
|
|
||||||
it('can be disabled by configuration', function(done) {
|
it('can be disabled by configuration', function(done) {
|
||||||
var app = loopback();
|
var app = loopback();
|
||||||
app.set('remoting', { cors: { origin: false } });
|
app.set('remoting', { cors: { origin: false }});
|
||||||
configureRestApiAndExplorer(app, '/explorer');
|
configureRestApiAndExplorer(app, '/explorer');
|
||||||
|
|
||||||
request(app)
|
request(app)
|
||||||
|
|
Loading…
Reference in New Issue