Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extra funcionality to register porgress #144

Merged
merged 13 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apisgatewayservice/apis-gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ app.get('/usersStats', async (req, res) => {
}
})

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


// Read the OpenAPI YAML file synchronously
const 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, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down
109 changes: 109 additions & 0 deletions apisgatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
openapi: 3.0.0
info:
title: Sample API
version: 1.0.0
paths:
/users:
get:
summary: Get users
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
type: object
properties:
username:
type: string
description: User ID
example: student
createdAt:
type: string
description: Creation date.
example: '2024-03-17T20:47:23.935Z'
'500':
description: Internal server error
content:
application/json:
schema:
type: object
properties:
error:
type: string
/history/questions:
get:
summary: Get history questions
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
type: object
properties:
pregunta:
type: string
description: The question.
example: ¿Cual es la capital de España?
respuesta_correcta:
type: string
description: The correct answer.
example: Madrid
respuestas_incorrectas:
type: array
items:
type: string
description: The other possible answers.
example: [Paris, Roma, Londres]
createdAt:
type: string
description: Creation date.
example: '2024-03-17T20:47:23.935Z'
'500':
description: Internal server error
content:
application/json:
schema:
type: object
properties:
error:
type: string
/usersStats:
get:
summary: Get users stats
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
type: object
properties:
username:
type: string
tpoints:
type: integer
avgpoints:
type: number
ttime:
type: integer
avgtime:
type: number
createdAt:
type: string
'500':
description: Internal server error
content:
application/json:
schema:
type: object
properties:
error:
type: string
Loading