Skip to content

CLI does not accept a schema without instance any longer #889

@krassowski

Description

@krassowski

Hi, thanks for maintaining jsonschema! We were using jsonschema to validate the integrity of the schema itself (i.e. is it a valid schema) as an early step in CI in https://github.com/python-lsp/python-lsp-server/ (if schema is not valid, we want to short-circuit early). When upgrading CI from Python 3.6 (which was pulling jsonschema 3.2.0) to a newer Python version (resolving jsonschema to 4.2.1) on python-lsp/python-lsp-server#130 the CI started failing:

jsonschema pylsp/config/schema.json
Failed to parse <stdin>: Expecting value: line 1 column 1 (char 0)

I did not find a changelog entry warning about to this change, but comparing jsonschema -h between versions I see that -i option is no longer really optional (i.e. it is now implicitly required):

3.2.0:

usage: jsonschema [-h] [-i INSTANCES] [-F ERROR_FORMAT] [-V VALIDATOR] [--version] schema

JSON Schema Validation CLI

positional arguments:
  schema                the JSON Schema to validate with (i.e. schema.json)

optional arguments:
  -h, --help            show this help message and exit
  -i INSTANCES, --instance INSTANCES
                        a path to a JSON instance (i.e. filename.json) to validate (may be specified multiple times)

4.2.1:

usage: jsonschema [-h] [-i INSTANCES] [-F ERROR_FORMAT] [-o {plain,pretty}] [-V VALIDATOR] [--base-uri BASE_URI] [--version] schema

JSON Schema Validation CLI

positional arguments:
  schema                the path to a JSON Schema to validate with (i.e. schema.json)

optional arguments:
  -h, --help            show this help message and exit
  -i INSTANCES, --instance INSTANCES
                        a path to a JSON instance (i.e. filename.json) to validate (may be specified multiple times).
                        If no instances are provided via this option, one will be expected on standard input.

the addition of If no instances are provided via this option, one will be expected on standard input. forces users to always pass a valid instance via standard input if they want to validate the schema itself.

One solution could be to add --no-instances optional argument (in 4.x). Another would be to just pass if no instance is given. What do you think?

For posterity coming here from search engines, I will cross-reference #888 (although not asking about CLI, this issue could answer the question from the title of the other one).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething doesn't work the way it should.Help WantedAn enhancement or bug for which a pull request is welcomed and which should have a clear definition.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions