Files
parcer/server/src/swagger/config.ts

59 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-10-28 23:27:40 +05:30
import swaggerJSDoc from 'swagger-jsdoc';
import path from 'path';
import fs from 'fs';
2026-01-19 00:50:06 +05:30
const apiDir = path.join(__dirname, '../api');
const jsGlobPattern = path.join(__dirname, '../api/*.js');
const tsGlobPattern = path.join(__dirname, '../api/*.ts');
2026-01-19 00:50:06 +05:30
let apis: string[];
2026-01-19 00:50:06 +05:30
if (fs.existsSync(apiDir)) {
const files = fs.readdirSync(apiDir);
const hasJsFiles = files.some(file => file.endsWith('.js'));
const hasTsFiles = files.some(file => file.endsWith('.ts'));
if (hasJsFiles) {
apis = [jsGlobPattern];
} else if (hasTsFiles) {
apis = [tsGlobPattern];
} else {
throw new Error('No valid API files found! Ensure either .js or .ts files exist in the ../api/ directory.');
}
} else {
throw new Error('API directory not found! Ensure the ../api/ directory exists.');
}
2024-10-28 23:27:40 +05:30
const options = {
definition: {
openapi: '3.0.0',
info: {
2024-12-11 14:53:54 +05:30
title: 'Website to API',
2024-10-28 23:27:40 +05:30
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.',
2024-10-28 23:27:40 +05:30
},
2024-10-28 23:45:15 +05:30
components: {
securitySchemes: {
2024-10-28 23:59:07 +05:30
api_key: {
2024-10-28 23:45:15 +05:30
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.',
2024-10-28 23:45:15 +05:30
},
},
},
security: [
{
2024-10-28 23:59:07 +05:30
api_key: [], // Apply this security scheme globally
2024-10-28 23:45:15 +05:30
},
],
2024-10-28 23:27:40 +05:30
},
apis,
2024-10-28 23:27:40 +05:30
};
const swaggerSpec = swaggerJSDoc(options);
export default swaggerSpec;