|
| 1 | +FAQ |
| 2 | +=== |
| 3 | + |
| 4 | +How do I use check-jsonschema in my application? |
| 5 | +------------------------------------------------ |
| 6 | + |
| 7 | +``check-jsonschema`` is only a CLI application, not a library for import and |
| 8 | +use within python applications. |
| 9 | + |
| 10 | +It is powered by the |
| 11 | +`jsonschema <https://python-jsonschema.readthedocs.io/en/stable/>`_ library. |
| 12 | +Most users looking to integrate JSON Schema in their applications should look |
| 13 | +into using ``jsonschema`` directly. |
| 14 | + |
| 15 | +It is also safe and supported to run ``check-jsonschema`` in a process, invoking |
| 16 | +it with correct CLI arguments and checking the output. |
| 17 | + |
| 18 | +Python Subprocess Invocation |
| 19 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 20 | + |
| 21 | +The following snippet for python applications ensures that you are running with |
| 22 | +the current interpreter and runs the equivalent of |
| 23 | +``check-jsonschema --version``: |
| 24 | + |
| 25 | +.. code-block:: python |
| 26 | +
|
| 27 | + import subprocess |
| 28 | + import sys |
| 29 | +
|
| 30 | + result = subprocess.check_output([sys.executable, "-m", "check_jsonschema", "--version"]) |
| 31 | + print(result.decode()) |
| 32 | +
|
| 33 | +Non-Python Considerations |
| 34 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 35 | + |
| 36 | +When invoking ``check-jsonschema`` from another language in a process, make |
| 37 | +sure you control the installation of ``check-jsonschema``. For example, the |
| 38 | +following Ruby snippet may look safe: |
| 39 | + |
| 40 | +.. code-block:: ruby |
| 41 | +
|
| 42 | + require 'json' |
| 43 | +
|
| 44 | + raw_data = `check-jsonschema -o JSON --schemafile #{schema} #{instance}` |
| 45 | + data = JSON.parse(raw_data) |
| 46 | +
|
| 47 | +However, it could be problematic if run in environments with different |
| 48 | +versions of ``check-jsonschema`` installed. |
| 49 | + |
| 50 | +One way to handle this is to install ``check-jsonschema`` into a virtualenv and |
| 51 | +always invoke it explicitly from that virtualenv, as in |
| 52 | + |
| 53 | +.. code-block:: ruby |
| 54 | +
|
| 55 | + require 'json' |
| 56 | +
|
| 57 | + raw_data = `venv/bin/check-jsonschema -o JSON --schemafile #{schema} #{instance}` |
| 58 | + data = JSON.parse(raw_data) |
| 59 | +
|
| 60 | +GitHub Actions Workflows |
| 61 | +------------------------ |
| 62 | + |
| 63 | +Using Self-Hosted Runners |
| 64 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 65 | + |
| 66 | +The GitHub Actions Workflow schema defined in SchemaStore does not allow all |
| 67 | +valid workflows, but rather a specific subset of workflows. |
| 68 | + |
| 69 | +For self-hosted runners, the schema will reject ``runs-on`` with an unrecognized |
| 70 | +string value. In order to use a custom runner ``runs-on`` value, put it into an |
| 71 | +array with ``self-hosted``, like so: |
| 72 | + |
| 73 | +.. code-block:: yaml |
| 74 | +
|
| 75 | + name: self-hosted job |
| 76 | + on: |
| 77 | + push: |
| 78 | +
|
| 79 | + jobs: |
| 80 | + myjob: |
| 81 | + runs-on: [self-hosted, spot-self-hosted] |
| 82 | + steps: |
| 83 | + - run: echo 'hi' |
0 commit comments