Skip to content

Commit e60a113

Browse files
committed
Validate examples for v3.0
1 parent 983e12e commit e60a113

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/v3.0/examples.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { readdirSync, readFileSync } from "node:fs";
2+
import YAML from "yaml";
3+
import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-0";
4+
import { BASIC } from "@hyperjump/json-schema/experimental";
5+
import { describe, test, expect } from "vitest";
6+
7+
const parseYamlFromFile = (filePath) => {
8+
const schemaYaml = readFileSync(filePath, "utf8");
9+
return YAML.parse(schemaYaml, { prettyErrors: true });
10+
};
11+
12+
setMetaSchemaOutputFormat(BASIC);
13+
14+
const validateOpenApi = await validate("./schemas/v3.0/schema.json");
15+
const folder = './examples/v3.0/';
16+
17+
describe("v3.0 - Validate examples", async () => {
18+
readdirSync(folder, { withFileTypes: true })
19+
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))
20+
.forEach((entry) => {
21+
test(entry.name, () => {
22+
const instance = parseYamlFromFile(folder + entry.name);
23+
const output = validateOpenApi(instance, BASIC);
24+
expect(output.valid).to.equal(true);
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)