30 lines
867 B
JavaScript
30 lines
867 B
JavaScript
// @ts-check
|
|
import path from "node:path";
|
|
import fs from "node:fs/promises";
|
|
import { cwd } from "node:process";
|
|
import { validate } from "@hyperjump/json-schema/openapi-3-1";
|
|
import YAML from "yaml";
|
|
|
|
const schemaPath = path.join(cwd(), "..", "src", "pages", "api", "schema.yaml");
|
|
|
|
run().catch((error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|
|
|
|
async function run() {
|
|
const fileContent = await fs.readFile(schemaPath, { encoding: "utf8" });
|
|
const parsedSchema = YAML.parse(fileContent)
|
|
const output = await validate(
|
|
"https://spec.openapis.org/oas/3.1/schema-base",
|
|
parsedSchema,
|
|
// the library doesn't support values beyond `"FLAG"` and `"BASIC"`
|
|
// but it's the only library in js which can validate OpenAPI 3.1 schemas
|
|
"BASIC"
|
|
);
|
|
|
|
if (!output.valid) {
|
|
throw new Error("Failed to validate OpenAPI Schema.")
|
|
}
|
|
}
|