From 337ad21577b5ec90ffcb6bd687f82f4fde6737b4 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 11 Dec 2024 14:53:18 +0530 Subject: [PATCH 1/3] feat: update description --- server/src/swagger/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/swagger/config.ts b/server/src/swagger/config.ts index c9c122104..2c7c588e3 100644 --- a/server/src/swagger/config.ts +++ b/server/src/swagger/config.ts @@ -7,7 +7,7 @@ const options = { info: { title: 'Maxun API Documentation', version: '1.0.0', - description: 'API documentation for Maxun (https://github.com/getmaxun/maxun)', + description: 'Maxun lets you get the data your robot extracted and run robots via API. All you need to do is input the Maxun API key by clicking Authorize below.', }, components: { securitySchemes: { From 2025d09e1e8240fd921e4d4dc6a722d630eeb42c Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 11 Dec 2024 14:53:54 +0530 Subject: [PATCH 2/3] feat: rename to website to api --- server/src/swagger/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/swagger/config.ts b/server/src/swagger/config.ts index 2c7c588e3..5f267053d 100644 --- a/server/src/swagger/config.ts +++ b/server/src/swagger/config.ts @@ -5,7 +5,7 @@ const options = { definition: { openapi: '3.0.0', info: { - title: 'Maxun API Documentation', + title: 'Website to API', version: '1.0.0', description: 'Maxun lets you get the data your robot extracted and run robots via API. All you need to do is input the Maxun API key by clicking Authorize below.', }, From 319f9fce24e22576b98639f91a09e7075edf0940 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Wed, 11 Dec 2024 15:16:45 +0530 Subject: [PATCH 3/3] feat: ensure swagger is accessible with or without build --- server/src/swagger/config.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/src/swagger/config.ts b/server/src/swagger/config.ts index 5f267053d..bf115ed10 100644 --- a/server/src/swagger/config.ts +++ b/server/src/swagger/config.ts @@ -1,5 +1,16 @@ import swaggerJSDoc from 'swagger-jsdoc'; import path from 'path'; +import fs from 'fs'; + +// Dynamically determine API file paths +const jsFiles = [path.join(__dirname, '../api/*.js')] +const tsFiles = [path.join(__dirname, '../api/*.ts')] + +let apis = fs.existsSync(jsFiles[0]) ? jsFiles : tsFiles; + +if (!apis) { + throw new Error('No valid API files found! Ensure either .js or .ts files exist in the ../api/ directory.'); +} const options = { definition: { @@ -7,7 +18,8 @@ const options = { info: { title: 'Website to API', version: '1.0.0', - description: 'Maxun lets you get the data your robot extracted and run robots via API. All you need to do is input the Maxun API key by clicking Authorize below.', + description: + 'Maxun lets you get the data your robot extracted and run robots via API. All you need to do is input the Maxun API key by clicking Authorize below.', }, components: { securitySchemes: { @@ -15,7 +27,8 @@ const options = { type: 'apiKey', in: 'header', name: 'x-api-key', - description: 'API key for authorization. You can find your API key in the "API Key" section on Maxun Dashboard.', + description: + 'API key for authorization. You can find your API key in the "API Key" section on Maxun Dashboard.', }, }, }, @@ -25,7 +38,7 @@ const options = { }, ], }, - apis: process.env.NODE_ENV === 'production' ? [path.join(__dirname, '../api/*.js')] : [path.join(__dirname, '../api/*.ts')] + apis, }; const swaggerSpec = swaggerJSDoc(options);