-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add --path Option to Target Specific Schema Parts in validate Command #220
base: main
Are you sure you want to change the base?
Feat: Add --path Option to Target Specific Schema Parts in validate Command #220
Conversation
Awesome! Great first step. Can you fix the formatting issues and add a couple of test cases (at least one where the pointer exists and one where it doesn't)? |
c14a91b
to
7647e43
Compare
Signed-off-by: karan-palan <[email protected]>
Signed-off-by: karan-palan <[email protected]>
7647e43
to
c39d4c2
Compare
Signed-off-by: karan-palan <[email protected]>
Signed-off-by: karan-palan <[email protected]>
Thanks! |
@Karan-Palan I think you forgot to actually register the tests, so they are not really running right now. You can do so like this: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 0f9840b..a3baa6d 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -74,6 +74,8 @@ add_jsonschema_test_unix(validate/pass_many_verbose)
add_jsonschema_test_unix(validate/fail_many)
add_jsonschema_test_unix(validate/fail_many_verbose)
add_jsonschema_test_unix(validate/fail_yaml)
+add_jsonschema_test_unix(validate/pass_pointer_exists)
+add_jsonschema_test_unix(validate/fail_pointer_not_exists)
# Metaschema
add_jsonschema_test_unix(metaschema/pass_trace) With that, running |
src/command_validate.cc
Outdated
const auto &arg = *it; | ||
|
||
// a) --path=/something | ||
if (arg.rfind("--path=", 0) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe options.at("p")
and options.at("path")
will give you what you want? Look at how we take options in other commands, like for --resolve
test/validate/pass_pointer_exists.sh
Outdated
if ! "$1" validate \ | ||
"$TMP/schema.json" \ | ||
"$TMP/instance.json" \ | ||
--path=/properties/nested \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of accessing a subschema of the schema, to make the test more representative, can you make the schema a very concise OpenAPI spec (in JSON) and access one of its schema components?
test/validate/pass_pointer_exists.sh
Outdated
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
cleanup() { rm -rf "$TMP"; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing, but other commands call this prelude clean
. Can you do the same for consistency?
test/validate/pass_pointer_exists.sh
Outdated
} | ||
EOF | ||
|
||
if ! "$1" validate \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you don't need the explicit if
check. Because of set -o errexit
, the entire script will fail if any of its commands fail. See how we do it for other "pass" tests
test/validate/pass_pointer_exists.sh
Outdated
exit 1 | ||
fi | ||
|
||
echo "pass_pointer_exists.sh: PASS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to print these things. ctest
will already nicely report the specific test cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a test where the JSON Pointer passed to --path
is indeed valid, but it's not an actual schema? Maybe /type
or something like that?
Signed-off-by: karan-palan <[email protected]>
…hema references Signed-off-by: karan-palan <[email protected]>
Signed-off-by: KaranPalan <[email protected]>
What kind of change does this PR introduce?
--path
(or-p
) option in thevalidate
command to allow targeting specific parts of a JSON schema using JSON Pointers.Issue Number:
--path
option to commands likevalidate
#218Screenshots/videos:
Screencast.from.2025-02-02.12-53-07.webm
If relevant, did you update the documentation?
Not yet
Summary
This PR introduces the
--path
(-p
) option to thevalidate
command, enabling users to specify a JSON Pointer for validating a sub-schema within a larger JSON schema. This is especially useful for OpenAPI specs and complex JSON structures where validation may be needed for specific nested sections.Key changes:
--path
/-p
option to CLI parser.Does this PR introduce a breaking change?
--path
option will continue to function as expected.