Merge pull request #948 from getmaxun/swagger-fix
fix: swagger api routes display
This commit is contained in:
@@ -2,14 +2,26 @@ import swaggerJSDoc from 'swagger-jsdoc';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
// Dynamically determine API file paths
|
const apiDir = path.join(__dirname, '../api');
|
||||||
const jsFiles = [path.join(__dirname, '../api/*.js')]
|
const jsGlobPattern = path.join(__dirname, '../api/*.js');
|
||||||
const tsFiles = [path.join(__dirname, '../api/*.ts')]
|
const tsGlobPattern = path.join(__dirname, '../api/*.ts');
|
||||||
|
|
||||||
let apis = fs.existsSync(jsFiles[0]) ? jsFiles : tsFiles;
|
let apis: string[];
|
||||||
|
|
||||||
if (!apis) {
|
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.');
|
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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
|||||||
Reference in New Issue
Block a user