mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
feat: add openapi gen to core
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {Command} from 'commander';
|
||||
import {existsSync, readFileSync, writeFileSync} from 'fs';
|
||||
import {copy} from 'fs-extra';
|
||||
import path from 'path';
|
||||
import {lightweightDefinitionsFromPath, lightweightProjectFromPath} from '@openstapps/easy-ast';
|
||||
import {openapi3Template} from './resources/openapi-303-template.js';
|
||||
@@ -57,7 +56,7 @@ commander
|
||||
// get absolute paths
|
||||
const sourcePath = path.resolve(relativeSourceBundlePath);
|
||||
const outDirectoryPath = path.resolve(relativeOutDirectoryPath);
|
||||
const outDirectorySchemasPath = path.join(outDirectoryPath, 'schemas');
|
||||
const outDirectorySchemasPath = path.join(outDirectoryPath, 'schema');
|
||||
|
||||
// get information about routes
|
||||
const routes = await gatherRouteInformation(sourcePath);
|
||||
@@ -82,9 +81,6 @@ commander
|
||||
// initialize json output
|
||||
const output = openapi3Template;
|
||||
|
||||
// names of the schemas to copy
|
||||
const schemasToCopy: string[] = [];
|
||||
|
||||
// generate documentation for all routes
|
||||
for (const routeWithMetaInformation of routes) {
|
||||
routeWithMetaInformation.tags = [capitalize(routeWithMetaInformation.route.urlPath.split('/')[1])];
|
||||
@@ -92,29 +88,10 @@ commander
|
||||
output.paths[routeWithMetaInformation.route.urlPath] = generateOpenAPIForRoute(
|
||||
routeWithMetaInformation,
|
||||
path.relative(relativeOutDirectoryPath, outDirectorySchemasPath),
|
||||
schemasToCopy,
|
||||
tagsToKeep,
|
||||
);
|
||||
}
|
||||
|
||||
// copy schema json schema files
|
||||
try {
|
||||
if (!existsSync(outDirectorySchemasPath)) {
|
||||
await mkdir(outDirectorySchemasPath, {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
for (const fileName of schemasToCopy) {
|
||||
await copy(
|
||||
path.join(sourcePath, 'schema', `${fileName}.json`),
|
||||
path.join(outDirectorySchemasPath, `${fileName}.json`),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
await Logger.error(error);
|
||||
process.exit(-2);
|
||||
}
|
||||
|
||||
// write openapi object to file (prettified)
|
||||
writeFileSync(path.join(outDirectoryPath, 'openapi.json'), JSON.stringify(output, undefined, 2));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user