Skip to content

Commit

Permalink
[WIP] Add a --trace option for validation-related commands
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Nov 7, 2024
1 parent 4db93a1 commit cc5a235
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ jsontoolkit https://github.com/sourcemeta/jsontoolkit 7a398224cc2e76ea9ae8541a87
hydra https://github.com/sourcemeta/hydra a4a74f3cabd32f2f829f449d67339dac33f9910e
alterschema https://github.com/sourcemeta/alterschema 92e370ce9c1f0582014b54d43e388ee012dfe13d
jsonbinpack https://github.com/sourcemeta/jsonbinpack d777179441d3c703e1fda1187742541aa26836b5
blaze https://github.com/sourcemeta/blaze cf0c89cd419ffb70cc334d395ac5ab1035702e30
blaze https://github.com/sourcemeta/blaze a5b3c8e4d77a0b88e4a93f304ae75e711b30a2e6
8 changes: 7 additions & 1 deletion docs/metaschema.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Metaschema
```sh
jsonschema metaschema [schemas-or-directories...]
[--verbose/-v] [--http/-h] [--extension/-e <extension>]
[--ignore/-i <schemas-or-directories>]
[--ignore/-i <schemas-or-directories>] [--trace/-t]
```

Ensure that a schema or a set of schemas are considered valid with regards to
Expand Down Expand Up @@ -76,3 +76,9 @@ jsonschema metaschema path/to/schemas/ --ignore path/to/schemas/nested
```sh
jsonschema metaschema --extension .schema.json
```

### Validate the metaschema of a JSON Schema with trace information

```sh
jsonschema metaschema path/to/my/schema.json --trace
```
8 changes: 7 additions & 1 deletion docs/test.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Testing
```sh
jsonschema test [schemas-or-directories...]
[--http/-h] [--verbose/-v] [--resolve/-r <schemas-or-directories> ...]
[--extension/-e <extension>] [--ignore/-i <schemas-or-directories>]
[--extension/-e <extension>] [--ignore/-i <schemas-or-directories>] [--trace/-t]
```

Schemas are code. As such, you should run an automated unit testing suite
Expand Down Expand Up @@ -109,3 +109,9 @@ jsonschema test path/to/test.json --resolve path/to/external.json
```sh
jsonschema test path/to/test.json --resolve path/to/schemas --extension schema.json
```

### Run a single test definition with trace information

```sh
jsonschema test path/to/test.json --trace
```
8 changes: 7 additions & 1 deletion docs/validate.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Validating
```sh
jsonschema validate <schema.json> <instance.json|.jsonl...> [--http/-h]
[--verbose/-v] [--resolve/-r <schemas-or-directories> ...] [--benchmark/-b]
[--extension/-e <extension>] [--ignore/-i <schemas-or-directories>]
[--extension/-e <extension>] [--ignore/-i <schemas-or-directories>] [--trace/-t]
```

The most popular use case of JSON Schema is to validate JSON documents. The
Expand Down Expand Up @@ -94,3 +94,9 @@ jsonschema validate path/to/my/schema.json path/to/my/instance.json \
```sh
jsonschema validate path/to/my/schema.json path/to/my/instance.json --benchmark
```

### Validate a JSON instance against a schema with trace information

```sh
jsonschema validate path/to/my/schema.json path/to/my/instance.json --trace
```
2 changes: 1 addition & 1 deletion src/command_metaschema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// TODO: Add a flag to emit output using the standard JSON Schema output format
auto sourcemeta::jsonschema::cli::metaschema(
const std::span<const std::string> &arguments) -> int {
const auto options{parse_options(arguments, {"h", "http"})};
const auto options{parse_options(arguments, {"h", "http", "t", "trace"})};
const auto custom_resolver{
resolver(options, options.contains("h") || options.contains("http"))};
bool result{true};
Expand Down
2 changes: 1 addition & 1 deletion src/command_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static auto get_data(const sourcemeta::jsontoolkit::JSON &test_case,

auto sourcemeta::jsonschema::cli::test(
const std::span<const std::string> &arguments) -> int {
const auto options{parse_options(arguments, {"h", "http"})};
const auto options{parse_options(arguments, {"h", "http", "t", "trace"})};
bool result{true};
const auto test_resolver{
resolver(options, options.contains("h") || options.contains("http"))};
Expand Down
3 changes: 2 additions & 1 deletion src/command_validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
// TODO: Add a flag to take a pre-compiled schema as input
auto sourcemeta::jsonschema::cli::validate(
const std::span<const std::string> &arguments) -> int {
const auto options{parse_options(arguments, {"h", "http", "b", "benchmark"})};
const auto options{
parse_options(arguments, {"h", "http", "b", "benchmark", "t", "trace"})};

if (options.at("").size() < 1) {
std::cerr
Expand Down
6 changes: 3 additions & 3 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ Global Options:
validate <schema.json> <instance.json|.jsonl...> [--http/-h]
[--benchmark/-b] [--extension/-e <extension>]
[--ignore/-i <schemas-or-directories>]
[--ignore/-i <schemas-or-directories>] [--trace/-t]
Validate one of more instances against the given schema.
metaschema [schemas-or-directories...] [--http/-h]
[--extension/-e <extension>]
[--ignore/-i <schemas-or-directories>]
[--ignore/-i <schemas-or-directories>] [--trace/-t]
Validate that a schema or a set of schemas are valid with respect
to their metaschemas.
test [schemas-or-directories...] [--http/-h] [--extension/-e <extension>]
[--ignore/-i <schemas-or-directories>]
[--ignore/-i <schemas-or-directories>] [--trace/-t]
Run a set of unit tests against a schema.
Expand Down
3 changes: 2 additions & 1 deletion vendor/blaze/src/compiler/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
79 changes: 79 additions & 0 deletions vendor/blaze/src/compiler/compile_output_trace.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 103 additions & 5 deletions vendor/blaze/src/compiler/include/sourcemeta/blaze/compiler_output.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc5a235

Please sign in to comment.