feat(validate): add --path option to target sub-schema via JSON Pointer#696
feat(validate): add --path option to target sub-schema via JSON Pointer#696Vaibhav701161 wants to merge 3 commits intosourcemeta:mainfrom
Conversation
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
|
Hi @jviotti, could you take a look when you have time? Would love your thoughts, especially if there are any edge cases I missed. |
There was a problem hiding this comment.
Pull request overview
Adds a --path option to the validate CLI command so users can target and validate a sub-schema inside a larger JSON/YAML document via JSON Pointer (e.g., OpenAPI documents).
Changes:
- Adds
--path <pointer>to thevalidatecommand and documents it in CLI help. - Extracts the pointed sub-schema before running the existing validation pipeline and blocks
--path+--templatetogether. - Adds new
validateCLI tests for success and failure cases involving--path.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/command_validate.cc |
Implements --path extraction logic and adds --path/--template conflict handling. |
src/main.cc |
Registers the new validate option and updates CLI help text. |
test/CMakeLists.txt |
Adds the new validate --path shell tests to the test suite. |
test/validate/pass_path_openapi.sh |
Validates extracting a schema embedded in an OpenAPI-like document. |
test/validate/fail_path_not_found.sh |
Asserts failure when the pointer doesn’t resolve. |
test/validate/fail_path_not_schema.sh |
Asserts failure when the pointed value isn’t a schema. |
test/validate/fail_path_with_template.sh |
Asserts CLI argument conflict handling for --path with --template. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🤖 Augment PR SummarySummary: This PR adds a Changes:
Technical Notes: The implementation copies the pointed-to sub-schema before reassigning to avoid aliasing/use-after-free when the pointer references the same underlying JSON storage. 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
1 issue found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="test/CMakeLists.txt">
<violation number="1" location="test/CMakeLists.txt:232">
P2: New `--path` failure tests are registered without JSON-error assertions for two failure modes, leaving structured error output untested.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
…ests, and behavior documentation) Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
There was a problem hiding this comment.
2 issues found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="test/validate/fail_path_ref_outside_subtree.sh">
<violation number="1" location="test/validate/fail_path_ref_outside_subtree.sh:32">
P2: New failure test lacks a companion `--json` assertion, so structured error output for this scenario is not covered.</violation>
<violation number="2" location="test/validate/fail_path_ref_outside_subtree.sh:36">
P2: Failure test is too broad: it suppresses output and only checks for any non-zero exit code, so unrelated errors can falsely pass.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Description
This PR adds support for a
--pathoption to thevalidatecommand. It allows validating a specific sub-schema inside a larger JSON document using a JSON Pointer.Reference #218
Motivation
In practice, most schemas are not standalone. They are often embedded inside larger documents such as OpenAPI specs. Right now, validating those requires manually extracting the schema first, which is inconvenient.
This change makes that workflow much simpler. You can directly point to the part of the document you want to validate.
Example:
This also fits with the direction discussed in #80, where the goal is to make it easier to work with embedded schemas without needing full OpenAPI parsing.
What this does
--path <pointer>option tovalidateto_pointer,try_get) to resolve the JSON Pointer--pathtogether with--templateError handling
--entrypointNo new error types are introduced. Existing ones are reused to stay consistent with current CLI behavior.
Tests
Added a small set of tests following existing patterns:
pass_path_openapichecks validating a schema inside an OpenAPI documentfail_path_not_foundchecks when the pointer does not resolvefail_path_not_schemachecks when the resolved value is not a schemafail_path_with_templatechecks the CLI option conflictTests focus on exit codes and stable output to avoid fragile assertions.
Notes
This change is intentionally scoped to
validateas a first step. It keeps the implementation simple and consistent with existing patterns.It also provides a practical way to work with embedded schemas today, while leaving room for broader OpenAPI support in the future.