python-jsonschema / check-jsonschema

A CLI and set of pre-commit hooks for jsonschema validation with built-in support for GitHub Workflows, Renovate, Azure Pipelines, and more!
https://check-jsonschema.readthedocs.io/en/stable
Other
192 stars 38 forks source link

--verbose doesn't seem to be anymore verbose than without it #266

Closed cidrbl0ck closed 1 year ago

cidrbl0ck commented 1 year ago

First time using this tool so here goes: Syntax as follows


Schema validation errors were encountered.
  /tmp/inventory.json::$: 'all', 'firewalls', 'not_set', 'routers', 'switches', 'ups', 'wlc' do not match any of the regexes: '^\\w$', '_meta'```

```check-jsonschema -v --schemafile ./inventory_script_schema.json /tmp/inventory.json
Schema validation errors were encountered.
  /tmp/inventory.json::$: 'all', 'firewalls', 'not_set', 'routers', 'switches', 'ups', 'wlc' do not match any of the regexes: '^\\w$', '_meta'```

So Ill admit, I'n entirely clueless as to what the root problem is in my schema file, however unless I'm doing it wrong I expected more information from a `-v/--verbose`

Adding the `-v/--verbose` to the end did not return anything different.
sirosen commented 1 year ago

I'n entirely clueless as to what the root problem is in my schema file, however unless I'm doing it wrong I expected more information from a -v/--verbose

This puts me in a difficult position with respect to answering your question or regarding it as resolved.

-v/--verbose has significant impact on output in some cases, but not in others. If schema validation encountered multiple errors, not all of them would be printed. But --verbose enables full output of all errors.

Let me break down the error message for you a little bit to help:

/tmp/inventory.json::$: 'all', 'firewalls', 'not_set', 'routers', 'switches', 'ups', 'wlc' do not match any of the regexes: '^\w$', '_meta'

  1. /tmp/inventory.json is the instance being checked.
  2. :: is a delimiter
  3. $ is the JSON Path within the instance to the failing component. $ in JSON Path means "the root of the document"
  4. : is another delimiter
  5. The rest of this is the message from the validation library, unmodified a. 'all', 'firewalls', 'not_set', 'routers', 'switches', 'ups', 'wlc' do not match any of the regexes might indicate a failure to match patternProperties? I'm guessing without seeing the schema or instance b. '^\\w$', '_meta' these two strings are apparently regexes in your schema (again, I'm guessing patternProperties)

-v or -vv could be made to turn on other behaviors, and I'm open to suggestions. It's only really been tuned for a couple of use-cases thusfar. The only constraint I'll note is that I don't think we want it to reformat the existing output -- it should only add new lines of output.

cidrbl0ck commented 1 year ago

Thanks @sirosen I know this is not an appropriate place to ask for help in resolving the problem with my json or schema files. I just wanted to ensure that either: A: I was invoking verbosity correctly or B: That the flag was working at is should.

Not having any prior experience using the tool makes me a poor source of suggestions for really anything potential changes. So I guess in this case, if you believe that -v is doing what it should then my question is solved, and now I just need to dig elsewhere.

sirosen commented 1 year ago

Okay, I'm going to close this. If you continue using check-jsonschema (and I hope you do!) and have ideas later for more output that you'd like from --verbose, feel free to circle back with a new feature request. I'm always open to ideas.

If you're looking for a place to learn more about JSON Schema, you might want to visit the community Slack, which is very active. Spec maintainers often answer questions about how to structure schemas there. There are also other validators you could try out to get another view of your schema and data. For example, there's a very cool fully in-browser one: https://json-everything.net/ (json-everything is made by one of the JSON Schema maintainers)