Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02
core https://github.com/sourcemeta/core d0bf624114232b8397bddad9a0c0e192c7315deb
core https://github.com/sourcemeta/core 9889529cd1d863eb39fc77289581414a183cce19
jsonbinpack https://github.com/sourcemeta/jsonbinpack 147050385dce7086a28ce93e18a4c3baa9719136
blaze https://github.com/sourcemeta/blaze 1b09fa0898cc986cc501322db2680d3fd6f093bf
blaze https://github.com/sourcemeta/blaze 53b3d89652504c1d61f908c8eb25ee3b46921e0b
ctrf https://github.com/ctrf-io/ctrf 93ea827d951390190171d37443bff169cf47c808
11 changes: 11 additions & 0 deletions src/command_codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ auto sourcemeta::jsonschema::codegen(const sourcemeta::core::Options &options)

throw sourcemeta::core::FileError<
sourcemeta::core::SchemaDialectImpossibleError>(schema_path, error);
} catch (const sourcemeta::core::SchemaReferenceError &error) {
const auto position{parsed_schema.positions.get(error.location())};
if (position.has_value()) {
throw PositionError<
sourcemeta::core::FileError<sourcemeta::core::SchemaReferenceError>>(
std::get<0>(position.value()), std::get<1>(position.value()),
schema_path, error.identifier(), error.location(), error.what());
}

throw sourcemeta::core::FileError<sourcemeta::core::SchemaReferenceError>(
schema_path, error.identifier(), error.location(), error.what());
} catch (const sourcemeta::core::SchemaResolutionError &error) {
throw sourcemeta::core::FileError<sourcemeta::core::SchemaResolutionError>(
schema_path, error);
Expand Down
10 changes: 8 additions & 2 deletions src/command_encode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ auto sourcemeta::jsonschema::encode(const sourcemeta::core::Options &options)
std::println(stderr, "compression ratio: {}%",
total_size * 100 / original_size);
} else {
const auto entry{
sourcemeta::core::read_yaml_or_json(options.positional().front())};
auto parsed{read_file(options.positional().front())};
if (parsed.multidocument) {
throw MultiDocumentInputError{
"This command does not support input with multiple documents",
options.positional().front()};
}

const auto entry{std::move(parsed.document)};
std::ofstream output_stream(
sourcemeta::core::weakly_canonical(options.positional().at(1)),
std::ios::binary);
Expand Down
10 changes: 9 additions & 1 deletion src/command_upgrade.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,15 @@ auto sourcemeta::jsonschema::upgrade(const sourcemeta::core::Options &options)
sourcemeta::jsonschema::default_id(schema_path, schema_from_stdin),
schema_display_path, parsed_schema.positions);

sourcemeta::jsonschema::format_schema(schema, custom_resolver, dialect);
// A boolean schema is the one shape an upgrade hands over without framing it
// first, as there is nothing in it to rewrite, so ordering it is where a
// dialect that could never be determined is first asked for
try {
sourcemeta::jsonschema::format_schema(schema, custom_resolver, dialect);
} catch (const sourcemeta::core::SchemaUnknownBaseDialectError &) {
throw sourcemeta::core::FileError<
sourcemeta::core::SchemaUnknownBaseDialectError>(schema_display_path);
}

sourcemeta::jsonschema::write_schema(schema, std::cout, indentation,
parsed_schema.roundtrip);
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ add_jsonschema_test(codegen/fail_invalid_target)
add_jsonschema_test(codegen/fail_schema_invalid_json)
add_jsonschema_test(codegen/fail_schema_invalid_yaml)
add_jsonschema_test(codegen/fail_yaml_multidocument)
add_jsonschema_test(codegen/fail_dangling_ref)
add_jsonschema_test(codegen/fail_unknown_metaschema)
add_jsonschema_test(codegen/fail_default_dialect_config_extension_mismatch)
add_jsonschema_test(codegen/fail_unsupported_vocabulary)
Expand Down Expand Up @@ -1438,6 +1439,7 @@ add_jsonschema_test(upgrade/pass_openapi_3_2_to_openapi_3_1_unchanged)
add_jsonschema_test(upgrade/pass_openapi_3_2_to_2020_12_unchanged)
add_jsonschema_test(upgrade/pass_2020_12_to_openapi_3_1_promoted_keywords)
add_jsonschema_test(upgrade/fail_no_dialect)
add_jsonschema_test(upgrade/fail_boolean_no_dialect)
add_jsonschema_test(upgrade/fail_no_schema)
add_jsonschema_test(upgrade/fail_stdin_invalid_json)
add_jsonschema_test(upgrade/fail_invalid_path)
Expand Down Expand Up @@ -1608,6 +1610,7 @@ add_jsonschema_test(encode/pass_schema_less_jsonl)
add_jsonschema_test(encode/pass_schema_less_jsonl_verbose)
add_jsonschema_test(encode/fail_no_document)
add_jsonschema_test(encode/fail_no_output)
add_jsonschema_test(encode/fail_yaml_multidocument)

# Decode
add_jsonschema_test(decode/pass_schema_less)
Expand Down
41 changes: 41 additions & 0 deletions test/codegen/fail_dangling_ref.clitest
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
WRITE schema.json UNTIL EOF
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/dangling",
"$ref": "#/$defs/missing"
}
EOF

// Schema input error
RUN codegen schema.json --target typescript STDIN /dev/null IN . INTO result.txt EXPECTING 4

REPLACE $CWD WITH '[CWD]' IN result.txt

WRITE expected_0.txt UNTIL EOF
2> error: Could not resolve schema reference
2> at identifier https://example.com/dangling#/$defs/missing
2> at line 4
2> at column 3
2> at file path [CWD]/schema.json
2> at location "/$ref"
EOF

COMPARE result.txt AGAINST expected_0.txt

// Schema input error
RUN codegen schema.json --target typescript --json STDIN /dev/null IN . INTO result_json.txt EXPECTING 4

REPLACE $CWD WITH '[CWD]' IN result_json.txt

WRITE expected_1.txt UNTIL EOF
1> {
1> "error": "Could not resolve schema reference",
1> "identifier": "https://example.com/dangling#/$defs/missing",
1> "line": 4,
1> "column": 3,
1> "filePath": "[CWD]/schema.json",
1> "location": "/$ref"
1> }
EOF

COMPARE result_json.txt AGAINST expected_1.txt
35 changes: 35 additions & 0 deletions test/encode/fail_yaml_multidocument.clitest
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
WRITE document.yaml UNTIL EOF
$schema: https://json-schema.org/draft/2020-12/schema
type: string
---
$schema: https://json-schema.org/draft/2020-12/schema
type: integer
EOF

// Not supported
RUN encode document.yaml output.bin STDIN /dev/null IN . INTO result.txt EXPECTING 3

REPLACE $CWD WITH '[CWD]' IN result.txt

WRITE expected_0.txt UNTIL EOF
2> original file size: 139 bytes
2> error: This command does not support input with multiple documents
2> at file path [CWD]/document.yaml
EOF

COMPARE result.txt AGAINST expected_0.txt

// Not supported
RUN encode document.yaml output.bin --json STDIN /dev/null IN . INTO result_json.txt EXPECTING 3

REPLACE $CWD WITH '[CWD]' IN result_json.txt

WRITE expected_1.txt UNTIL EOF
1> {
1> "error": "This command does not support input with multiple documents",
1> "filePath": "[CWD]/document.yaml"
1> }
2> original file size: 139 bytes
EOF

COMPARE result_json.txt AGAINST expected_1.txt
33 changes: 33 additions & 0 deletions test/upgrade/fail_boolean_no_dialect.clitest
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
WRITE schema.json UNTIL EOF
true
EOF

// Schema input error
RUN upgrade schema.json STDIN /dev/null IN . INTO result.txt EXPECTING 4

REPLACE $CWD WITH '[CWD]' IN result.txt

WRITE expected.txt UNTIL EOF
2> error: Could not determine the base dialect of the schema
2> at file path [CWD]/schema.json
2>
2> Are you sure the input is a valid JSON Schema and its base dialect is known?
2> If the input does not declare the `$schema` keyword, you might want to
2> explicitly declare a default dialect using `--default-dialect/-d`
EOF

COMPARE result.txt AGAINST expected.txt

// Schema input error
RUN upgrade schema.json --json STDIN /dev/null IN . INTO result_json.txt EXPECTING 4

REPLACE $CWD WITH '[CWD]' IN result_json.txt

WRITE expected_json.txt UNTIL EOF
1> {
1> "error": "Could not determine the base dialect of the schema",
1> "filePath": "[CWD]/schema.json"
1> }
EOF

COMPARE result_json.txt AGAINST expected_json.txt
9 changes: 9 additions & 0 deletions vendor/blaze/CMakeLists.txt

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

2 changes: 1 addition & 1 deletion vendor/blaze/DEPENDENCIES

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

10 changes: 9 additions & 1 deletion vendor/blaze/config.cmake.in

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

Loading
Loading