|
| 1 | +import { readdirSync, readFileSync } from "node:fs"; |
| 2 | +import YAML from "yaml"; |
| 3 | +import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-1"; |
| 4 | +import { BASIC } from "@hyperjump/json-schema/experimental"; |
| 5 | +import { describe, test, expect } from "vitest"; |
| 6 | + |
| 7 | + |
| 8 | +const parseYamlFromFile = (filePath) => { |
| 9 | + const schemaYaml = readFileSync(filePath, "utf8"); |
| 10 | + return YAML.parse(schemaYaml, { prettyErrors: true }); |
| 11 | +}; |
| 12 | + |
| 13 | +setMetaSchemaOutputFormat(BASIC); |
| 14 | +// setShouldValidateSchema(false); |
| 15 | + |
| 16 | +const validateOpenApi = await validate("./schemas/v3.1/schema.json"); |
| 17 | + |
| 18 | +describe("v3.1", () => { |
| 19 | + describe("Pass", () => { |
| 20 | + readdirSync(`./tests/v3.1/pass`, { withFileTypes: true }) |
| 21 | + .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) |
| 22 | + .forEach((entry) => { |
| 23 | + test(entry.name, () => { |
| 24 | + const instance = parseYamlFromFile(`./tests/v3.1/pass/${entry.name}`); |
| 25 | + const output = validateOpenApi(instance, BASIC); |
| 26 | + expect(output.valid).to.equal(true); |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + describe("Fail", () => { |
| 32 | + readdirSync(`./tests/v3.1/fail`, { withFileTypes: true }) |
| 33 | + .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) |
| 34 | + .forEach((entry) => { |
| 35 | + test(entry.name, () => { |
| 36 | + const instance = parseYamlFromFile(`./tests/v3.1/fail/${entry.name}`); |
| 37 | + const output = validateOpenApi(instance, BASIC); |
| 38 | + expect(output.valid).to.equal(false); |
| 39 | + }); |
| 40 | + }); |
| 41 | + }); |
| 42 | +}); |
0 commit comments