Skip to content

Commit

Permalink
Merge pull request #124 from Arquisoft/Api
Browse files Browse the repository at this point in the history
Api documentation
  • Loading branch information
pelazas authored Apr 29, 2024
2 parents 8a40efb + 423ea76 commit aa99462
Show file tree
Hide file tree
Showing 5 changed files with 787 additions and 9 deletions.
21 changes: 21 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const axios = require('axios');
const cors = require('cors');
const promBundle = require('express-prom-bundle');

// libraries required for OpenAPI-Swagger
const swaggerUI = require('swagger-ui-express');
const fs = require("fs");
const YAML = require('yaml');

const app = express();
const port = 8000;

Expand Down Expand Up @@ -182,6 +187,22 @@ app.get('/getGroups', async (req, res) => {
}
})

// Read the OpenAPI YAML file synchronously
openapiPath='./openapi.yaml'
if (fs.existsSync(openapiPath)) {
const file = fs.readFileSync(openapiPath, 'utf8');

// Parse the YAML content into a JavaScript object representing the Swagger document
const swaggerDocument = YAML.parse(file);

// Serve the Swagger UI documentation at the '/api-doc' endpoint
// This middleware serves the Swagger UI files and sets up the Swagger UI page
// It takes the parsed Swagger document as input
app.use('/api-doc', swaggerUI.serve, swaggerUI.setup(swaggerDocument));
} else {
console.log("Not configuring OpenAPI. Configuration file not present.")
}


// Start the gateway service
const server = app.listen(port, () => {
Expand Down
Loading

0 comments on commit aa99462

Please sign in to comment.