mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-06 21:42:49 +00:00
@@ -55,7 +55,7 @@ export interface RouteWithMetaInformation {
|
||||
* Instance of the route
|
||||
*/
|
||||
route: {
|
||||
errorNames: string[];
|
||||
errorNames: Error[];
|
||||
method: string;
|
||||
obligatoryParameters: {
|
||||
[k: string]: string;
|
||||
|
||||
@@ -13,10 +13,8 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {asyncPool} from 'async-pool-native/dist/async-pool';
|
||||
import humanizeString = require('humanize-string');
|
||||
import {ProjectReflection} from 'typedoc';
|
||||
import {logger, NodesWithMetaInformation, NodeWithMetaInformation} from './common';
|
||||
import {RouteWithMetaInformation} from './common';
|
||||
import {logger, NodesWithMetaInformation, NodeWithMetaInformation, RouteWithMetaInformation} from './common';
|
||||
|
||||
/**
|
||||
* Gather relevant information of routes
|
||||
@@ -33,20 +31,25 @@ export async function gatherRouteInformation(reflection: ProjectReflection): Pro
|
||||
throw new Error('Project reflection doesn\'t contain any modules.');
|
||||
}
|
||||
|
||||
await asyncPool(2, reflection.children, async (module: any) => {
|
||||
await asyncPool(2, reflection.children, async (module) => {
|
||||
if (Array.isArray(module.children) && module.children.length > 0) {
|
||||
await asyncPool(2, module.children, (async (node: any) => {
|
||||
await asyncPool(2, module.children, (async (node) => {
|
||||
if (Array.isArray(node.extendedTypes) && node.extendedTypes.length > 0) {
|
||||
if (node.extendedTypes.some((extendedType: any) => {
|
||||
return extendedType.name === 'SCAbstractRoute';
|
||||
if (node.extendedTypes.some((extendedType) => {
|
||||
return (extendedType as any).name === 'SCAbstractRoute';
|
||||
})) {
|
||||
logger.info(`Found ${node.name} in ${module.originalName}.`);
|
||||
|
||||
if (module.originalName.match(/\.d\.ts$/)) {
|
||||
module.originalName = module.originalName.substr(0, module.originalName.length - 5);
|
||||
logger.info(`Using compiled version of module in ${module.originalName}.`);
|
||||
}
|
||||
|
||||
const importedModule = await import(module.originalName);
|
||||
|
||||
const route = new importedModule[node.name]();
|
||||
|
||||
routes.push({description: node.comment, name: node.name, route});
|
||||
routes.push({description: node.comment!, name: node.name, route});
|
||||
}
|
||||
}
|
||||
}));
|
||||
@@ -68,6 +71,8 @@ export async function gatherRouteInformation(reflection: ProjectReflection): Pro
|
||||
* @param humanize Whether to humanize the name or not
|
||||
*/
|
||||
export function getLinkedNameForNode(name: string, node: NodeWithMetaInformation, humanize: boolean = false): string {
|
||||
const humanizeString = require('humanize-string');
|
||||
|
||||
let printableName = name;
|
||||
|
||||
if (humanize) {
|
||||
@@ -137,8 +142,8 @@ export function generateDocumentationForRoute(routeWithInfo: RouteWithMetaInform
|
||||
| request | ${getLinkedNameForNode(route.requestBodyName, nodes[route.requestBodyName])} |
|
||||
| response | ${getLinkedNameForNode(route.responseBodyName, nodes[route.responseBodyName])} |
|
||||
| success code | ${route.statusCodeSuccess} |
|
||||
| errors | ${route.errorNames.map((errorName) => {
|
||||
return getLinkedNameForNode(errorName, nodes[errorName]);
|
||||
| errors | ${route.errorNames.map((error) => {
|
||||
return getLinkedNameForNode(error.name, nodes[error.name]);
|
||||
}).join('<br>')} |
|
||||
`;
|
||||
if (typeof route.obligatoryParameters === 'object' && Object.keys(route.obligatoryParameters).length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user