Skip to content

Commit

Permalink
Added: Feature For load OpenAPIValidator Cache on app boot
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyvishal committed Jun 18, 2024
1 parent 7897d9a commit 1b1c85b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const main = async () => {
await ClientUtils.initializeConnection();
await GatewayUtils.getInstance().initialize();
await OpenApiValidatorMiddleware.getInstance().initOpenApiMiddleware();
console.log("After Open API middleware");
if (getConfig().responseCache.enabled) {
await ResponseCache.getInstance().initialize();
}
Expand Down
9 changes: 6 additions & 3 deletions src/middlewares/schemaValidator.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class OpenApiValidatorMiddleware {
return apiSpec;
}

public initOpenApiMiddleware(): void {
public async initOpenApiMiddleware() {
try {
const files = fs.readdirSync(specFolder);
const fileNames = files.filter(
Expand Down Expand Up @@ -78,7 +78,7 @@ export class OpenApiValidatorMiddleware {
count: 0,
requestHandler: requestHandler
};
initializeOpenApiValidatorCache(requestHandler);
await initializeOpenApiValidatorCache(requestHandler);
}
}
} catch (err) {
Expand Down Expand Up @@ -194,7 +194,10 @@ const initializeOpenApiValidatorCache = async (stack: any) => {
} as any;
return req;
};
const reqObj = mockRequest({ context: {}, message: {} });
const reqObj = mockRequest({
context: { action: `${action}` },
message: {}
});
walkSubstack(stack, reqObj, {}, () => {
return;
});
Expand Down

0 comments on commit 1b1c85b

Please sign in to comment.