Skip to content

Commit 21e2c2e

Browse files
authored
Merge pull request #3568 from jdesrosiers/fix-validation-script
Fix validate script
2 parents 617f3d9 + 0e3f97e commit 21e2c2e

File tree

2 files changed

+38
-58
lines changed

2 files changed

+38
-58
lines changed

scripts/validate.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

scripts/validate.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env node
2+
3+
import { readFile } from "node:fs/promises";
4+
import yaml from "yaml";
5+
import { setMetaSchemaOutputFormat, validate } from "@hyperjump/json-schema/openapi-3-1";
6+
import { BASIC } from "@hyperjump/json-schema/experimental";
7+
8+
9+
const defaultOutputFormat = BASIC;
10+
11+
if (process.argv.length < 3) {
12+
console.log(`Usage: validate [--schema=schema] [--format=${defaultOutputFormat}] path-to-file.yaml`);
13+
console.log("\t--schema: (schema (default) | schema-base) The name of the schema file to use");
14+
console.log(`\t--format: (Default: ${defaultOutputFormat}) The JSON Schema output format to use. Options: FLAG, BASIC, DETAILED, VERBOSE`);
15+
process.exit(1);
16+
}
17+
18+
const args = process.argv.reduce((acc, arg) => {
19+
if (!arg.startsWith("--")) return acc;
20+
21+
const [argName, argValue] = arg.substring(2).split("=", 2);
22+
return { ...acc, [argName]: argValue };
23+
}, {});
24+
25+
const schemaType = args.schema || "schema";
26+
const outputFormat = args.format || defaultOutputFormat;
27+
28+
// Config
29+
setMetaSchemaOutputFormat(outputFormat);
30+
31+
// Compile / meta-validate
32+
const validateOpenApi = await validate(`./schemas/v3.1/${schemaType}.json`);
33+
34+
// Validate instance
35+
const instanceYaml = await readFile(`${process.argv[process.argv.length - 1]}`, "utf8");
36+
const instance = yaml.parse(instanceYaml);
37+
const results = validateOpenApi(instance, outputFormat);
38+
console.log(JSON.stringify(results, null, " "));

0 commit comments

Comments
 (0)