mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-28 09:03:53 +00:00
chore: Jest Testing structure (#2707)
* deps: add jest deps * chore: mock * feat: use mocinggoose * feat: jest * chore: remove babel.config.js
This commit is contained in:
49
scripts/openapi/index.js
Normal file
49
scripts/openapi/index.js
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var utils_1 = require("./utils");
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var openapi_1 = require("./openapi");
|
||||
var rootPath = 'projects/app/src/pages/api';
|
||||
var exclude = ['/admin', '/proApi'];
|
||||
function getAllFiles(dir) {
|
||||
var files = [];
|
||||
var stat = fs.statSync(dir);
|
||||
if (stat.isDirectory()) {
|
||||
var list = fs.readdirSync(dir);
|
||||
list.forEach(function (item) {
|
||||
var fullPath = path.join(dir, item);
|
||||
if (!exclude.some(function (excluded) { return fullPath.includes(excluded); })) {
|
||||
files = files.concat(getAllFiles(fullPath));
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
files.push(dir);
|
||||
}
|
||||
return files;
|
||||
}
|
||||
var searchPath = process.env.SEARCH_PATH || '';
|
||||
var files = getAllFiles(path.join(rootPath, searchPath));
|
||||
// console.log(files)
|
||||
var apis = files.map(function (file) {
|
||||
return (0, utils_1.parseAPI)({ path: file, rootPath: rootPath });
|
||||
});
|
||||
var openapi = (0, openapi_1.convertOpenApi)({
|
||||
apis: apis,
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
title: 'FastGPT OpenAPI',
|
||||
version: '1.0.0',
|
||||
author: 'FastGPT'
|
||||
},
|
||||
servers: [
|
||||
{
|
||||
url: 'http://localhost:4000'
|
||||
}
|
||||
]
|
||||
});
|
||||
var json = JSON.stringify(openapi, null, 2);
|
||||
fs.writeFileSync('./scripts/openapi/openapi.json', json);
|
||||
fs.writeFileSync('./scripts/openapi/openapi.out', JSON.stringify(apis, null, 2));
|
||||
console.log('Total APIs:', files.length);
|
Reference in New Issue
Block a user