forked from octokit/webhooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
48 lines (42 loc) · 949 Bytes
/
test.ts
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
48
import Ajv, { ErrorObject } from "ajv";
import { JSONSchema7 } from "json-schema";
import webhooks from "./payload-examples/api.github.com/index.json";
const ajv = new Ajv();
const schema: JSONSchema7 = {
type: "object",
required: ["name", "description", "actions", "examples"],
properties: {
name: {
type: "string",
},
description: {
type: "string",
},
actions: {
type: "array",
items: { type: "string" },
},
examples: {
type: "array",
items: { type: "object" },
},
},
};
interface WebhookError {
webhookName: string;
errors: ErrorObject[];
}
const errors: WebhookError[] = [];
webhooks.forEach((webhook) => {
const valid = ajv.validate(schema, webhook);
if (!valid) {
errors.push({
webhookName: webhook.name,
errors: ajv.errors ?? [],
});
}
});
if (errors.length) {
console.log(JSON.stringify(errors, null, 2));
process.exit(1);
}