@sourcemeta/jsonschema 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ ![JSON Schema](./assets/banner.png)
2
+
3
+ The command-line tool for working with [JSON Schema](https://json-schema.org),
4
+ the world most popular schema language. It is a comprehensive solution for
5
+ maintaining **repositories of schemas** and ensuring their quality, both during
6
+ local development and when running on CI/CD pipelines. For example:
7
+
8
+ - Ensure your schemas are valid
9
+ - Unit test your schemas against valid and invalid instances
10
+ - Enforce consistent indentation and keyword ordering in your schema files
11
+ - Detect and fix common JSON Schema anti-patterns
12
+ - Inline external references for conveniently distributing your schemas
13
+
14
+ [**Check out the documentation to learn more**](#usage)
15
+
16
+ ***
17
+
18
+ > [!TIP]
19
+ > Do you want to level up your JSON Schema skills? Check out
20
+ > [learnjsonschema.com](https://www.learnjsonschema.com), our growing JSON
21
+ > Schema documentation website, and our O'Reilly book [Unifying Business, Data,
22
+ > and Code: Designing Data Products with JSON
23
+ > Schema](https://www.oreilly.com/library/view/unifying-business-data/9781098144999/).
24
+
25
+ Version support
26
+ ---------------
27
+
28
+ We aim to fully support _every_ version of JSON Schema and combinations between them.
29
+
30
+ | Dialect | Support |
31
+ |---------------------|------------------------------------------------------------------|
32
+ | JSON Schema 2020-12 | **Full** |
33
+ | JSON Schema 2019-09 | **Full** |
34
+ | JSON Schema Draft 7 | **Full** |
35
+ | JSON Schema Draft 6 | **Full** |
36
+ | JSON Schema Draft 4 | **Full** |
37
+ | JSON Schema Draft 3 | Partial (except `validate`, `test`, `metaschema`, and `compile`) |
38
+ | JSON Schema Draft 2 | Partial (except `validate`, `test`, `metaschema`, and `compile`) |
39
+ | JSON Schema Draft 1 | Partial (except `validate`, `test`, `metaschema`, and `compile`) |
40
+ | JSON Schema Draft 0 | Partial (except `validate`, `test`, `metaschema`, and `compile`) |
41
+
42
+ What our users are saying
43
+ -------------------------
44
+
45
+ > Amazing product. Very useful for formatting and bundling my schemas, plus it
46
+ > surfaced various referencing issues. 10 out of 10!
47
+
48
+ [@alombarte](https://github.com/alombarte), co-founder of the
49
+ [KrakenD](https://www.krakend.io) API Gateway.
50
+
51
+ Usage
52
+ -----
53
+
54
+ The functionality provided by the JSON Schema CLI is divided into commands. The
55
+ following pages describe each command in detail. Additionally, running the JSON
56
+ Schema CLI without passing a command will print convenient reference
57
+ documentation:
58
+
59
+ - [`jsonschema validate`](./docs/validate.markdown)
60
+ - [`jsonschema metaschema`](./docs/metaschema.markdown) (ensure a schema is valid)
61
+ - [`jsonschema test`](./docs/test.markdown) (write unit tests for your schemas)
62
+ - [`jsonschema fmt`](./docs/format.markdown)
63
+ - [`jsonschema lint`](./docs/lint.markdown)
64
+ - [`jsonschema bundle`](./docs/bundle.markdown) (for inlining remote references in a schema)
65
+ - [`jsonschema frame`](./docs/frame.markdown) (for debugging references)
66
+ - [`jsonschema compile`](./docs/compile.markdown) (for internal debugging)
67
+ - [`jsonschema identify`](./docs/identify.markdown)
68
+
69
+ Installation
70
+ ------------
71
+
72
+ The JSON Schema CLI is written using C++ and [CMake](https://cmake.org/), and
73
+ supports macOS, Windows, and GNU/Linux. Under the hood, it relies on the
74
+ powerful [JSON Toolkit](https://github.com/sourcemeta/jsontoolkit) library.
75
+
76
+ ### From Homebrew
77
+
78
+ ```sh
79
+ brew install sourcemeta/apps/jsonschema
80
+ ```
81
+
82
+ ### From GitHub Actions
83
+
84
+ ```yaml
85
+ - uses: sourcemeta/jsonschema@vX.Y.Z
86
+ ```
87
+
88
+ Where `X.Y.Z` is replaced with the desired version. For example:
89
+
90
+ ```yaml
91
+ - uses: sourcemeta/jsonschema@v4.0.0
92
+ # Then use as usual
93
+ - run: jsonschema fmt path/to/schemas --check
94
+ ```
95
+
96
+ ### From NPM
97
+
98
+ ```sh
99
+ npm install --global @sourcemeta/jsonschema
100
+ ```
101
+
102
+ ### From GitHub Releases
103
+
104
+ We publish precompiled binaries for every supported platform to [GitHub
105
+ Releases](https://github.com/sourcemeta/jsonschema/releases), including a
106
+ [continuous](https://github.com/sourcemeta/jsonschema/releases/tag/continuous)
107
+ that is updated on every commit from the main branch.
108
+
109
+ For convenience, we also provide a POSIX shell script capable of installing the
110
+ latest pre-built binaries, which you can run as follows:
111
+
112
+ ```sh
113
+ /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/sourcemeta/jsonschema/main/install -H "Cache-Control: no-cache, no-store, must-revalidate")"
114
+ ```
115
+
116
+ ### From Dockerfile
117
+
118
+ You can compile the JSON Schema CLI inside a container and run it with Docker
119
+ as follows:
120
+
121
+ ```sh
122
+ docker build -t jsonschema .
123
+ ```
124
+
125
+ Then, you run the JSON Schema CLI by mounting the desired directory as
126
+ `/workspace` as follows:
127
+
128
+ ```sh
129
+ docker run --interactive --volume "$PWD:/workspace" jsonschema lint --verbose myschema.json
130
+
131
+ # You can optionally add this to your .alias (or similar) file:
132
+ # alias jsonschema="docker run --interactive --volume \"$PWD:/workspace\" jsonschema"
133
+ ```
134
+
135
+ > [!WARNING]
136
+ > Make sure to NOT allocate a pseudo-TTY when running the CLI through Docker
137
+ > (i.e. the `--tty`/`-t` option) as it might result in line ending
138
+ > incompatibilities between the container and host, which will affect
139
+ > formatting. Plus a TTY is not required for running a tool like the JSON
140
+ > Schema CLI.
141
+
142
+ ### Building from source
143
+
144
+ ```sh
145
+ git clone https://github.com/sourcemeta/jsonschema
146
+ cd jsonschema
147
+ cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=Release
148
+ cmake --build ./build --config Release --parallel 4
149
+ cmake --install ./build --prefix <prefix> \
150
+ --config Release --verbose --component sourcemeta_jsonschema
151
+ ```
152
+
153
+ Where `<prefix>` can be any destination prefix of your choosing, such as `/opt`
154
+ or `/usr/local`.
155
+
156
+ Coming Soon
157
+ -----------
158
+
159
+ This project is under heavy development, and we have a lot of cool things in
160
+ the oven. In the mean-time, star the project to show your support!
161
+
162
+ | Feature | Description | Status |
163
+ |-----------------------|------------------------------------------------------------------------------------|-------------|
164
+ | Debugging | Validate a JSON instance against a JSON Schema step by step, like LLDB and GDB | Not started |
165
+ | Upgrading/Downgrading | Convert a JSON Schema into a later or older dialect | Not started |
166
+
167
+ License
168
+ -------
169
+
170
+ This project is governed by the [AGPL-3.0](./LICENSE) copyleft license.
package/cli.js ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ const os = require('os');
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const child_process = require('child_process');
6
+
7
+ const PLATFORM = os.platform() === 'win32' ? 'windows' : os.platform();
8
+ const ARCH = os.arch() === 'x64' ? 'x86_64' : os.arch();
9
+ const EXECUTABLE = PLATFORM === 'windows'
10
+ ? path.join(__dirname, `jsonschema-${PLATFORM}-${ARCH}.exe`)
11
+ : path.join(__dirname, `jsonschema-${PLATFORM}-${ARCH}`);
12
+
13
+ if (!fs.existsSync(EXECUTABLE)) {
14
+ console.error(`The JSON Schema CLI NPM package does not support ${os.platform()} for ${ARCH} yet`);
15
+ console.error('Please open a GitHub issue at https://github.com/sourcemeta/jsonschema');
16
+ process.exit(1);
17
+ }
18
+
19
+ if (PLATFORM === 'darwin') {
20
+ child_process.spawnSync('/usr/bin/xattr', [ '-c', EXECUTABLE ], { stdio: 'inherit' });
21
+ }
22
+
23
+ const result = child_process.spawnSync(EXECUTABLE,
24
+ process.argv.slice(2), { stdio: 'inherit' });
25
+ process.exit(result.status);
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@sourcemeta/jsonschema",
3
+ "version": "4.0.0",
4
+ "description": "The CLI for working with JSON Schema. Covers formatting, linting, testing, and much more for both local development and CI/CD pipelines",
5
+ "main": "cli.js",
6
+ "bin": {
7
+ "jsonschema": "cli.js"
8
+ },
9
+ "license": "AGPL-3.0",
10
+ "homepage": "https://github.com/sourcemeta/jsonschema",
11
+ "author": "Juan Cruz Viotti <jviotti@sourcemeta.com>",
12
+ "keywords": [
13
+ "jsonschema", "json", "schema", "json-schema",
14
+ "cli", "$ref", "dereference", "reference", "resolve",
15
+ "json-pointer", "validator", "bundle",
16
+ "lint", "format"
17
+ ],
18
+ "bugs": {
19
+ "url": "https://github.com/sourcemeta/jsonschema/issues"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/sourcemeta/jsonschema.git"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ }
28
+ }