diff --git a/tests/v3.0/examples.test.js b/tests/v3.0/examples.test.js new file mode 100644 index 0000000000..9513cbc9e3 --- /dev/null +++ b/tests/v3.0/examples.test.js @@ -0,0 +1,27 @@ +import { readdirSync, readFileSync } from "node:fs"; +import YAML from "yaml"; +import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-0"; +import { BASIC } from "@hyperjump/json-schema/experimental"; +import { describe, test, expect } from "vitest"; + +const parseYamlFromFile = (filePath) => { + const schemaYaml = readFileSync(filePath, "utf8"); + return YAML.parse(schemaYaml, { prettyErrors: true }); +}; + +setMetaSchemaOutputFormat(BASIC); + +const validateOpenApi = await validate("./schemas/v3.0/schema.json"); +const folder = './examples/v3.0/'; + +describe("v3.0 - Validate examples", async () => { + readdirSync(folder, { withFileTypes: true }) + .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) + .forEach((entry) => { + test(entry.name, () => { + const instance = parseYamlFromFile(folder + entry.name); + const output = validateOpenApi(instance, BASIC); + expect(output.valid).to.equal(true); + }); + }); +}); diff --git a/tests/v3.1/examples.test.js b/tests/v3.1/examples.test.js new file mode 100644 index 0000000000..49057fb537 --- /dev/null +++ b/tests/v3.1/examples.test.js @@ -0,0 +1,27 @@ +import { readdirSync, readFileSync } from "node:fs"; +import YAML from "yaml"; +import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-1"; +import { BASIC } from "@hyperjump/json-schema/experimental"; +import { describe, test, expect } from "vitest"; + +const parseYamlFromFile = (filePath) => { + const schemaYaml = readFileSync(filePath, "utf8"); + return YAML.parse(schemaYaml, { prettyErrors: true }); +}; + +setMetaSchemaOutputFormat(BASIC); + +const validateOpenApi = await validate("./schemas/v3.1/schema.json"); +const folder = './examples/v3.1/'; + +describe("v3.1 - Validate examples", async () => { + readdirSync(folder, { withFileTypes: true }) + .filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name)) + .forEach((entry) => { + test(entry.name, () => { + const instance = parseYamlFromFile(folder + entry.name); + const output = validateOpenApi(instance, BASIC); + expect(output.valid).to.equal(true); + }); + }); +}); diff --git a/tests/v3.1/schema.test.mjs b/tests/v3.1/schema.test.mjs index c879b6b457..76d83258b2 100644 --- a/tests/v3.1/schema.test.mjs +++ b/tests/v3.1/schema.test.mjs @@ -4,14 +4,12 @@ import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/open import { BASIC } from "@hyperjump/json-schema/experimental"; import { describe, test, expect } from "vitest"; - const parseYamlFromFile = (filePath) => { const schemaYaml = readFileSync(filePath, "utf8"); return YAML.parse(schemaYaml, { prettyErrors: true }); }; setMetaSchemaOutputFormat(BASIC); -// setShouldValidateSchema(false); const validateOpenApi = await validate("./schemas/v3.1/schema.json");