forked from holidayextras/jsonapi-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swaggerValidator.js
47 lines (39 loc) · 1.26 KB
/
swaggerValidator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const jsonApiTestServer = require("./example/server.js");
const request = require("request");
const assert = require("assert");
describe("Use a tool to validate the generated swagger document", () => {
it("should not contain any errors", done => {
const validator = require("swagger-tools").specs.v2;
const uri = "http://localhost:16006/rest/swagger.json";
request(uri, (meh, res, swaggerObject) => {
swaggerObject = JSON.parse(swaggerObject);
validator.validate(swaggerObject, (err, result) => {
assert.ifError(err);
if (!result) {
console.log("Swagger document is valid");
return done();
}
if (result.errors.length > 0) {
console.log("The Swagger document is invalid...");
console.log("");
console.log("Errors");
console.log("------");
console.log(result.errors);
console.log("");
}
if (result.warnings.length > 0) {
console.log("Warnings");
console.log("--------");
console.log(result.warnings);
}
done(new Error("Invalid swagger.json!"));
});
});
});
before(() => {
jsonApiTestServer.start();
});
after(() => {
jsonApiTestServer.close();
});
});