|
| 1 | +Installing Dependencies |
| 2 | +======================= |
| 3 | + |
| 4 | +```sh |
| 5 | +jsonschema install |
| 6 | + [--force/-f] [--verbose/-v] [--debug/-g] [--json/-j] |
| 7 | +``` |
| 8 | + |
| 9 | +Many applications rely on consuming schemas authored and maintained by others. |
| 10 | +These schemas are typically published over HTTP(S) through registries like |
| 11 | +[schemas.sourcemeta.com](https://schemas.sourcemeta.com) (a free public |
| 12 | +registry) or self-hosted solutions like [Sourcemeta |
| 13 | +One](https://one.sourcemeta.com). While you could manually download these |
| 14 | +schemas or write a custom fetching script, doing so quickly gets complicated: |
| 15 | +schemas often reference other schemas that also need to be fetched, and the |
| 16 | +results need to be |
| 17 | +[bundled](https://json-schema.org/blog/posts/bundling-json-schema-compound-documents) |
| 18 | +to inline those references for local consumption. The `install` command solves |
| 19 | +this in a single step. |
| 20 | + |
| 21 | +To get started, create a |
| 22 | +[`jsonschema.json`](./configuration.markdown) configuration file in your |
| 23 | +project and declare your dependencies as a mapping of schema URIs to local file |
| 24 | +paths. For example, to pull in the [JSON-RPC 2.0 |
| 25 | +Response](https://schemas.sourcemeta.com/sourcemeta/std/v0/jsonrpc/v2.0/response) |
| 26 | +schema from the public registry: |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "dependencies": { |
| 31 | + "https://schemas.sourcemeta.com/sourcemeta/std/v0/jsonrpc/v2.0/response": "./vendor/response.json" |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Then run `jsonschema install`. Each dependency is fetched, bundled, and written |
| 37 | +to the specified path. A `jsonschema.lock.json` lock file is created alongside |
| 38 | +`jsonschema.json` to record the hash of each installed dependency. On |
| 39 | +subsequent runs, only dependencies that are missing, modified, or not yet |
| 40 | +tracked in the lock file are fetched again. |
| 41 | + |
| 42 | +> [!TIP] |
| 43 | +> We recommend committing `jsonschema.lock.json` to version control (similar to |
| 44 | +> `package-lock.json`) to enable reproducible installs across environments. |
| 45 | +
|
| 46 | +> [!WARNING] |
| 47 | +> If a dependency uses a custom meta-schema that is itself an external |
| 48 | +> dependency, make sure to list both the meta-schema and the schema that uses |
| 49 | +> it in the `dependencies` map. The install command will resolve the |
| 50 | +> meta-schema during bundling regardless of processing order. We are working |
| 51 | +> on resolving this automatically in a future release. |
| 52 | +
|
| 53 | +Examples |
| 54 | +-------- |
| 55 | + |
| 56 | +### Install all dependencies |
| 57 | + |
| 58 | +```sh |
| 59 | +jsonschema install |
| 60 | +``` |
| 61 | + |
| 62 | +### Force re-fetch all dependencies |
| 63 | + |
| 64 | +```sh |
| 65 | +jsonschema install --force |
| 66 | +``` |
| 67 | + |
| 68 | +### Install with verbose output |
| 69 | + |
| 70 | +```sh |
| 71 | +jsonschema install --verbose |
| 72 | +``` |
0 commit comments