hyperjump-io / json-schema

JSON Schema Validation, Annotation, and Bundling. Supports Draft 04, 06, 07, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1
https://json-schema.hyperjump.io/
MIT License
216 stars 22 forks source link

Support command line interface #49

Open doganulus opened 7 months ago

doganulus commented 7 months ago

I like to use the Hyperjump's bundle functionality like this one: https://libraries.io/npm/@skriptfabrik%2Fjson-schema-bundler

Does the library currently support the command line interface?

jdesrosiers commented 7 months ago

There isn't a CLI, but it wouldn't be hard to make one. Unfortunately, I don't have to time to work on something like that at the moment. I'd be thrilled if someone wanted to contribute a proper cli wrapper, but here's a quick and dirty example if you something urgently.

import "@hyperjump/json-schema/draft-2020-12";
import { bundle } from "@hyperjump/json-schema/bundle";

const mainSchema = process.argv[2];

const result = await bundle(mainSchema);
console.log(JSON.stringify(result, null, "  "));

Just pass the initial schema and it will send the bundled schema to stdout: node bundle-cli.js main.schema.json. This example works for file-based schemas. If you need to register schemas that use $id, you'd have to expand on the script.