Skip to content

Commit

Permalink
Merge pull request #326 from seriousme/validator-v2
Browse files Browse the repository at this point in the history
Support @seriousme/openapi-schema-validator v2.0.0
  • Loading branch information
seriousme authored Apr 25, 2022
2 parents 006da5b + 010c694 commit b342876
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
### Changed
- Migrated to ES Modules format

## [2.6.8] - 25-04-2022
### Changed
- Updated dependencies:
@seriousme/openapi-schema-validator ^1.7.1 → ^2.0.0
tap ^16.0.1 → ^16.1.0

## [2.6.7] - 22-04-2022
### Changed
- Deprecation of Nodejs < 14
Expand Down
2 changes: 1 addition & 1 deletion examples/generatedProject/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"devDependencies": {
"fastify": "^3.28.0",
"fastify-cli": "^2.15.0",
"tap": "^16.0.1"
"tap": "^16.1.0"
}
}
18 changes: 9 additions & 9 deletions lib/parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// this class is to bridge various parser versions
const Validator = require("@seriousme/openapi-schema-validator");
const ParserV2 = require("./parser.v2");
const ParserV3 = require("./parser.v3");

Expand All @@ -24,31 +23,32 @@ class parser {
*/

async preProcessSpec(specification) {
const { Validator } = await import("@seriousme/openapi-schema-validator");
const validator = new Validator();
try {
const res = await validator.validate(specification);
if(res.valid){
if (res.valid) {
// clone the original specification as resolveRefs modifies the schema
this.original = JSON.parse(JSON.stringify(validator.specification, null, 2));
return {
return {
valid: true,
version: validator.version,
spec: validator.resolveRefs()
}
}
throw Error(JSON.stringify(res.errors,null,2));
throw Error(JSON.stringify(res.errors, null, 2));
} catch (e) {
// eslint-disable-next-line
console.log(e.message);
return { valid: false};
return { valid: false };
}
}

async parse(specification) {
const supportedVersions = new Set(["2.0", "3.0", "3.1"]);

const res = await this.preProcessSpec(specification);
if (!res.valid || !supportedVersions.has(res.version)){
if (!res.valid || !supportedVersions.has(res.version)) {
throw new Error(
"'specification' parameter must contain a valid version 2.0 or 3.0.x or 3.1.x specification"
);
Expand All @@ -57,8 +57,8 @@ class parser {
if (res.version === "2.0") {
const parserV2 = new ParserV2();
return parserV2.parse(res.spec);
}
}

const parserV3 = new ParserV3();
return parserV3.parse(res.spec);
}
Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"openapi-glue": "./bin/openapi-glue-cli.js"
},
"dependencies": {
"@seriousme/openapi-schema-validator": "^1.7.1",
"@seriousme/openapi-schema-validator": "^2.0.0",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"fastify-plugin": "^3.0.1",
Expand All @@ -39,7 +39,7 @@
"devDependencies": {
"fastify": "^3.28.0",
"fastify-cli": "^2.15.0",
"tap": "^16.0.1"
"tap": "^16.1.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit b342876

Please sign in to comment.