Skip to content

Commit

Permalink
fix(various):
Browse files Browse the repository at this point in the history
 - deduplicate alias from moleculer-web
 - set full path from alias on autoalias
 - remove debugger
  • Loading branch information
thib3113 committed Nov 27, 2023
1 parent d4ff2f2 commit fc103c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
15 changes: 5 additions & 10 deletions src/MoleculerOpenAPIGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,11 @@ export class MoleculerOpenAPIGenerator {

const routesParser = new MoleculerWebRoutesParser(this.logger);

try {
return (
await Promise.all(
apiServices.map(async (svc) => await routesParser.parse(ctx, svc, this.settings.skipUnresolvedActions, services))
)
).flat();
} catch (e) {
this.logger.error(e);
debugger;
}
return (
await Promise.all(
apiServices.map(async (svc) => await routesParser.parse(ctx, svc, this.settings.skipUnresolvedActions, services))
)
).flat();
}

public async generateSchema(ctx: Context<OA_GENERATE_DOCS_INPUT>): Promise<OA_GENERATE_DOCS_OUTPUT> {
Expand Down
14 changes: 11 additions & 3 deletions src/MoleculerWebRoutesParser/MoleculerWebRoutesParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ export class MoleculerWebRoutesParser {
routes.set(route.path, route);
});

const autoAliases = await this.fetchAliasesForService(ctx, serviceName);
//autoAliases are returned X times depending on the services started
const autoAliases = ((await this.fetchAliasesForService(ctx, serviceName)) ?? []).filter(
(alias, index, self) => index === self.findIndex((a) => a.fullPath === alias.fullPath)
);

return (autoAliases ?? [])
return autoAliases
.flatMap((alias: routeAlias) => {
this.logger.debug(`RoutesParser.parse() - checking alias ${alias.path} for path ${alias.fullPath}`);

Expand All @@ -76,7 +79,7 @@ export class MoleculerWebRoutesParser {

this.logger.debug(`RoutesParser.parse() - alias ${alias.fullPath} seems to use autoAliases`);

return new Alias(
const newAlias = new Alias(
{
path: alias.path,
method: alias.methods,
Expand All @@ -85,6 +88,11 @@ export class MoleculerWebRoutesParser {
},
route
);

if (alias.fullPath) {
newAlias.fullPath = alias.fullPath;
}
return newAlias;
}

if (routeAlias.skipped) {
Expand Down
2 changes: 1 addition & 1 deletion src/objects/Alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'path/posix';
import { ValidationSchema } from 'fastest-validator';

export class Alias {
public readonly fullPath: string;
public fullPath: string;
get path(): string {
return this._path;
}
Expand Down

0 comments on commit fc103c5

Please sign in to comment.