Skip to content

Commit 1dc2851

Browse files
committed
validate via redocly
1 parent ee2f4d1 commit 1dc2851

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/definitionGenerator.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
const path = require("path");
44

5+
const {
6+
Config,
7+
lintFromString,
8+
stringifyYaml,
9+
createConfig,
10+
} = require("@redocly/openapi-core");
511
const isEqual = require("lodash.isequal");
6-
const validator = require("oas-validator");
712
const { v4: uuid } = require("uuid");
813

914
const SchemaHandler = require("./schemaHandler");
@@ -971,9 +976,35 @@ class DefinitionGenerator {
971976
}
972977

973978
async validate() {
974-
return await validator.validateInner(this.openAPI, {}).catch((err) => {
979+
const config = await createConfig({
980+
apis: {},
981+
// styleguide: {
982+
rules: {
983+
spec: "error",
984+
"path-parameters-defined": "error",
985+
"operation-2xx-response": "error",
986+
"operation-4xx-response": "error",
987+
"operation-operationId-unique": "error",
988+
"path-declaration-must-exist": "error",
989+
},
990+
// },
991+
});
992+
993+
const apiDesc = stringifyYaml(this.openAPI);
994+
995+
const results = await lintFromString({
996+
source: apiDesc,
997+
config: config,
998+
}).catch((err) => {
999+
console.error(err);
9751000
throw err;
9761001
});
1002+
1003+
if (results.length) {
1004+
throw results;
1005+
}
1006+
1007+
return true;
9771008
}
9781009
}
9791010

0 commit comments

Comments
 (0)