Skip to content

Commit

Permalink
Used schemasafe library for validating all OAS version including OAS …
Browse files Browse the repository at this point in the history
…3.1.0 and code refactoring
  • Loading branch information
rahul-eminds committed Oct 14, 2024
1 parent 28b8aca commit 5c410bc
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 263 deletions.
1 change: 0 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ const main = async () => {
getConfig().app.gateway.mode.toLocaleUpperCase().substring(0, 1) +
getConfig().app.gateway.mode.toLocaleUpperCase().substring(1)
);
await OpenApiValidatorMiddleware.getInstance().initOpenApiMiddleware();
await Validator.getInstance().initialize();
logger.info('Initialized openapi validator middleware');
} catch (err) {
Expand Down
18 changes: 7 additions & 11 deletions src/middlewares/schemaValidator.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,11 @@ export const openApiValidatorMiddleware = async (
}
const apiSpecYAML = fs.readFileSync(specFile, "utf8");
const apiSpec = YAML.parse(apiSpecYAML);
if (apiSpec.openapi === '3.1.0') {
const ajvValidatorInstance = Validator.getInstance();
const openApiValidator = await ajvValidatorInstance.getValidationMiddleware(specFile, specFileName);
(await openApiValidator)(req, res, () => {
logger.info('Validation Success');
next()
});
} else {
const openApiValidator = OpenApiValidatorMiddleware.getInstance().getOpenApiMiddleware(specFile);
walkSubstack([...openApiValidator], req, res, next);
}
const ajvValidatorInstance = Validator.getInstance();
const openApiValidator = await ajvValidatorInstance.getValidationMiddleware(specFile, specFileName);
(await openApiValidator)(req, res, () => {
logger.info('Validation Success');
next()
});

};
Loading

0 comments on commit 5c410bc

Please sign in to comment.