Skip to content

Add --keywords option to inspect command - #828

Open
Nariman-Sayed wants to merge 2 commits into
sourcemeta:mainfrom
Nariman-Sayed:feature/inspect-keywords
Open

Add --keywords option to inspect command#828
Nariman-Sayed wants to merge 2 commits into
sourcemeta:mainfrom
Nariman-Sayed:feature/inspect-keywords

Conversation

@Nariman-Sayed

@Nariman-Sayed Nariman-Sayed commented Aug 22, 2026

Copy link
Copy Markdown

Closes #227

Adds a --keywords flag to inspect that counts keyword occurrences in a schema grouped by vocabulary, based on the approach in https://github.com/sourcemeta-research/jsonschema-keywords

jsonschema inspect schema.json --keywords

Uses SchemaIterator to walk the schema and count keywords per vocabulary. Made it conflict with --json since I wasn't sure how to combine keyword stats with the existing json output format, let me know if you had something else in mind.

Added tests for the normal case and the --json conflict, and updated the docs.

Review in cubic

@cla-assistant

cla-assistant Bot commented Aug 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Aug 22, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/command_inspect.cc Outdated
Comment thread src/main.cc
@Nariman-Sayed
Nariman-Sayed force-pushed the feature/inspect-keywords branch from 8c15b64 to a9a26a8 Compare August 23, 2026 03:24
Count and print the occurrences of each JSON Schema keyword in a
schema, grouped by vocabulary, using the existing SchemaIterator
utility. The --keywords option cannot be combined with --json.

Ref: sourcemeta#227
Signed-off-by: Nariman Sayed <narimansayed28@gmail.com>
Comment thread test/inspect/fail_keywords_with_json.sh Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that on main we largely replaced the shell tests with a new .clitest runner format. Can you adopt those?

Comment thread test/inspect/pass_keywords.sh Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have tests for this in conjunction with --json?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have tests for this in conjunction with --json?

I added fail_keywords_with_json.clitest for the --keywords + --json conflict case - let me know if you meant something else here.

@jviotti

jviotti commented Aug 24, 2026

Copy link
Copy Markdown
Member

Seems like CI is failing on a few OSes!

Replace the old shell-script tests with the new .clitest DSL format
used across the rest of the test suite, per review feedback. Also
update the three help output .clitest fixtures to include the new
--keywords/-k flag documentation.

Signed-off-by: Nariman Sayed <narimansayed28@gmail.com>
@Nariman-Sayed
Nariman-Sayed force-pushed the feature/inspect-keywords branch from a9a26a8 to 326fee2 Compare August 25, 2026 03:50
Comment thread src/command_inspect.cc
}

if (options.contains("keywords") && options.contains("json")) {
throw OptionConflictError{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nariman-Sayed Can we actually support --json? The entire command does support it (as almost every other command in the tool). In this case, we can present the same keyword summary, but print it as a JSON object or something like that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a test showing the schema from standard input too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also maybe one that has unknown keywords. Also one where you pass a boolean schema, or a schema that is the empty object (in conjunction with --default-dialect). Overall thinking edge cases. Let's try to actually cover this feature in tests to try to surface any bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend the inspect command with --keywords to count JSON Schema keyword occurrences

2 participants