diff --git a/.env b/.env index 83ebdaaa7b09c7d7d020bde04293cbb67915c785..0efeaa73b19403be4d206de6b8274dfc447b4926 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ -PORT=8000 \ No newline at end of file +PORT=8000 +INSTANCE=PROD \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 745228effc130cdf098f6d387f0a660a0c90e13a..7b430bf65ec95b867c05df5dfc1a041350cc15a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1142,6 +1142,12 @@ "winston": "*" } }, + "@types/yamljs": { + "version": "0.2.31", + "resolved": "https://registry.npmjs.org/@types/yamljs/-/yamljs-0.2.31.tgz", + "integrity": "sha512-QcJ5ZczaXAqbVD3o8mw/mEBhRvO5UAdTtbvgwL/OgoWubvNBh6/MxLBAigtcgIFaq3shon9m3POIxQaLQt4fxQ==", + "dev": true + }, "@types/yargs": { "version": "16.0.4", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz", @@ -7739,6 +7745,15 @@ "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", "dev": true }, + "yamljs": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/yamljs/-/yamljs-0.3.0.tgz", + "integrity": "sha512-C/FsVVhht4iPQYXOInoxUM/1ELSf9EsgKH34FofQOp6hwCPrW4vG4w5++TED3xRUo8gD7l0P1J1dLlDYzODsTQ==", + "requires": { + "argparse": "^1.0.7", + "glob": "^7.0.5" + } + }, "yargs": { "version": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", diff --git a/package.json b/package.json index 7d902a4dcc4d055b5d75d20b68f762e0e41d35de..985296ea3b0886f726419db47b99c6c858cfc649 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "swagger-ui-express": "^4.1.6", "tsconfig.json": "^1.0.10", "winston": "^3.3.3", - "xlsx": "^0.17.1" + "xlsx": "^0.17.1", + "yamljs": "^0.3.0" }, "devDependencies": { "@types/cors": "^2.8.12", @@ -24,6 +25,7 @@ "@types/swagger-jsdoc": "^6.0.1", "@types/swagger-ui-express": "^4.1.3", "@types/winston": "^2.4.4", + "@types/yamljs": "^0.2.31", "@typescript-eslint/eslint-plugin": "^2.34.0", "@typescript-eslint/parser": "^2.0.0", "eslint": "^7.32.0", diff --git a/src/Controllers/SwaggerEndpoints b/src/Controllers/SwaggerEndpoints deleted file mode 100644 index 3ce392d10684c1aa7b4ffa149b9defd129d6b2b9..0000000000000000000000000000000000000000 --- a/src/Controllers/SwaggerEndpoints +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @swagger - * /excelParser: - * post: - * tags: - * - parser - * description: Sheet Parser - * requestBody: - * required: true - * content: - * application/octet-stream: - * type: binary - * responses: - * '200': - * description: returns the parsed JSON of the excel file provided - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/SheetParserResponse' - */ - - /** - * @swagger - * /excelParser2: - * post: - * tags: - * - parser - * description: Sheet Parser - * requestBody: - * required: true - * content: - * application/octet-stream: - * type: binary - * responses: - * '200': - * description: returns the parsed JSON of the excel file provided - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/SheetParserResponse' - */ \ No newline at end of file diff --git a/src/Controllers/SwaggerSchemas b/src/Controllers/SwaggerSchemas deleted file mode 100644 index 65d51f47a5c1dca0d8598e6c7e8dadb89d41ec8c..0000000000000000000000000000000000000000 --- a/src/Controllers/SwaggerSchemas +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @swagger - * components: - * schemas: - * Menores: - * type: object - * properties: - * edad: - * type: integer - * peso: - * type: integer - * Mayores: - * type: object - * required: ["edad"] - * properties: - * edad: - * type: integer - * peso: - * type: integer - * talla: - * type: integer - * SheetParserResponse: - * type: object - * properties: - * hombresMenores: - * type: array - * items: - * $ref: '#/components/schemas/Menores' - * mujeresMenores: - * type: array - * items: - * $ref: '#/components/schemas/Menores' - * hombres: - * type: array - * items: - * $ref: '#/components/schemas/Mayores' - * mujeres: - * type: array - * items: - * $ref: '#/components/schemas/Mayores' - */ \ No newline at end of file diff --git a/src/Logger/logger.ts b/src/Logger/logger.ts index 56648e1130ac6e2eb80f8e57e46e77aa5633fa73..17715492a1df299bada6501b3b1a713c91957b09 100644 --- a/src/Logger/logger.ts +++ b/src/Logger/logger.ts @@ -3,7 +3,7 @@ import { } from 'winston'; const { - combine, timestamp, label, printf, + combine, timestamp, } = format; const logger: Logger = createLogger({ diff --git a/src/index.ts b/src/index.ts index c728db64b751d1f4a49d90329e713aeb37a65e75..30dad1b806cb360a6b93e61524f8477ef8616086 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,9 +2,9 @@ import express, { Application } from 'express'; import 'dotenv/config'; import cors from 'cors'; -import swaggerJsDoc, { Options } from 'swagger-jsdoc'; import swaggerUi from 'swagger-ui-express'; import helmet from 'helmet'; +import YAML from 'yamljs'; import Routes from './routes'; import logger from './Logger/logger'; @@ -12,22 +12,9 @@ const app: Application = express(); const PORT = process.env.PORT || 8000; app.use(helmet.hidePoweredBy()); // swagger init -const swaggerOptions: Options = { - swaggerDefinition: { - openapi: '3.0.0', - info: { - title: 'REPP Rest API', - version: '1.0.0', - description: '', - servers: ['http://localhost:3000'], - }, - }, - apis: ['src/Controllers/*'], -}; -const swaggerDocs = swaggerJsDoc(swaggerOptions); - +const swaggerDocument = YAML.load('./swagger.yaml'); // middlewares -app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs)); +app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); app.use(express.json({ limit: '50mb', diff --git a/swagger.yaml b/swagger.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b424dc77f3b74ba186b84b58830e3557723265d0 --- /dev/null +++ b/swagger.yaml @@ -0,0 +1,90 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: REPP Backend + description: '' +security: + - BearerAuth: [] +tags: + - name: Auth + - name: Parser + - name: Calculation +paths: + + /login: + post: + tags: + - Auth + summary: Login to get an access token + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/UserCredentials' + + responses: + '200': + description: Ok. + security: [] + + /sheetParser: + post: + tags: + - Parser + summary: Given a sheet returns SheetParserResponse + requestBody: + content: + application/octet-stream: + schema: + format: binary + required: true + responses: + '200': + description: Ok. + security: + - BearerAuth: [] +components: + securitySchemes: + BearerAuth: + type: http + scheme: bearer + schemas: + Menores: + properties: + edad: + type: integer + peso: + type: integer + Mayores: + properties: + edad: + type: integer + peso: + type: integer + talla: + type: integer + SheetParserResponse: + properties: + hombresMenores: + type: array + items: + $ref: '#/components/schemas/Menores' + mujeresMenores: + type: array + items: + $ref: '#/components/schemas/Menores' + hombres: + type: array + items: + $ref: '#/components/schemas/Mayores' + mujeres: + type: array + items: + $ref: '#/components/schemas/Mayores' + UserCredentials: + properties: + user: + type: string + pass: + type: string