Skip to content

Commit

Permalink
feat(#390): Enable swagger on restful services
Browse files Browse the repository at this point in the history
  • Loading branch information
tholulomo committed May 16, 2023
1 parent f881d0f commit 1489671
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions resfulservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"graphql-ws": "^5.8.2",
"helmet": "^4.6.0",
"jsonwebtoken": "^8.5.1",
"luxon": "^2.2.0",
"mongodb": "^4.2.1",
"mongoose": "^6.1.4",
"morgan": "^1.10.0",
Expand All @@ -33,13 +32,14 @@
"read-excel-file": "^5.6.1",
"sinon": "^14.0.0",
"ssh2": "^1.11.0",
"swagger-ui-express": "^4.2.0",
"swagger-ui-express": "^4.6.3",
"ua-parser-js": "^1.0.33",
"unique-names-generator": "^4.7.1",
"winston": "^3.5.1",
"ws": "^8.7.0",
"xlsx": "^0.18.5",
"xml-formatter": "^3.3.2"
"xml-formatter": "^3.3.2",
"yamljs": "^0.3.0"
},
"scripts": {
"start": "nodemon src/server.js --inspect",
Expand Down
8 changes: 4 additions & 4 deletions resfulservice/src/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ router

router.route('/populate-datasets-properties')
.get(AdminController.getDatasetProperties)
.post(AdminController.populateDatasetProperties);
.post(isAuth, AdminController.populateDatasetProperties);

router.route('/populate-datasets')
.post(isAuth, AdminController.populateDatasetIds);

router
.route('/es')
.get(AdminController.pingElasticSearch)
.post(AdminController.initializeElasticSearch)
.get(isAuth, AdminController.pingElasticSearch)
.post(isAuth, AdminController.initializeElasticSearch)
.put(isAuth, AdminController.loadElasticSearch)
.delete(AdminController.loadElasticSearch);
.delete(isAuth, AdminController.loadElasticSearch);

// Note: Not in use. Deprecated for authService.js route.
router.route('/login').post(loginController.login);
Expand Down
8 changes: 8 additions & 0 deletions resfulservice/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const mongoose = require('mongoose');
const { createServer: createHttpServer } = require('http');
const { WebSocketServer } = require('ws');
const { useServer: useWsServer } = require('graphql-ws/lib/use/ws');
const path = require('path');
const swaggerUi = require('swagger-ui-express');
const yaml = require('yamljs');
const { globalMiddleWare, log } = require('./middlewares');
const adminRoutes = require('./routes/admin');
const authRoutes = require('./routes/authService');
Expand All @@ -20,12 +23,17 @@ const typeDefs = require('./graphql');
const getHttpContext = require('./graphql/context/getHttpContext');
const getWsContext = require('./graphql/context/getWsContext');

const swaggerDocumentPath = path.resolve(__dirname, './api-docs/swagger.yaml');
const env = process.env;

const app = express();
globalMiddleWare(app);
elasticSearch.ping(log);

// Serve the Swagger UI
const swaggerDocument = yaml.load(swaggerDocumentPath);
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, { explorer: true }));

app.use('/admin', adminRoutes);
app.use('/curate', curationRoutes);
app.use('/secure', authRoutes);
Expand Down

0 comments on commit 1489671

Please sign in to comment.