Skip to content

Commit b800283

Browse files
authored
More prominently warn at runtime against using --without-id when bundling (#310)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 211746f commit b800283

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

src/command_bundle.cc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,28 @@ auto sourcemeta::jsonschema::cli::bundle(
2020
return EXIT_FAILURE;
2121
}
2222

23+
const auto custom_resolver{resolver(
24+
options, options.contains("h") || options.contains("http"), dialect)};
2325
auto schema{sourcemeta::jsonschema::cli::read_file(options.at("").front())};
2426

25-
sourcemeta::core::bundle(
26-
schema, sourcemeta::core::schema_official_walker,
27-
resolver(options, options.contains("h") || options.contains("http"),
28-
dialect),
29-
dialect);
27+
sourcemeta::core::bundle(schema, sourcemeta::core::schema_official_walker,
28+
custom_resolver, dialect);
3029

3130
if (options.contains("w") || options.contains("without-id")) {
32-
log_verbose(options) << "Removing schema identifiers\n";
33-
sourcemeta::core::unidentify(
34-
schema, sourcemeta::core::schema_official_walker,
35-
resolver(options, options.contains("h") || options.contains("http"),
36-
dialect),
37-
dialect);
31+
std::cerr << "warning: You are opting in to remove schema identifiers in "
32+
"the bundled schema.\n";
33+
std::cerr << "The only legit use case of this advanced feature we know of "
34+
"it to workaround\n";
35+
std::cerr << "non-compliant JSON Schema implementations such as Visual "
36+
"Studio Code.\n";
37+
std::cerr << "In other case, this is not needed and may harm other use "
38+
"cases. For example,\n";
39+
std::cerr << "you will be unable to reference the resulting schema from "
40+
"other schemas\n";
41+
std::cerr << "using the --resolve/-r option.\n";
42+
sourcemeta::core::unidentify(schema,
43+
sourcemeta::core::schema_official_walker,
44+
custom_resolver, dialect);
3845
}
3946

4047
sourcemeta::core::prettify(schema, std::cout,

test/bundle/pass_without_id.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cat << 'EOF' > "$TMP/schemas/remote.json"
2424
}
2525
EOF
2626

27-
"$1" bundle "$TMP/schema.json" --resolve "$TMP/schemas" --without-id > "$TMP/result.json"
27+
"$1" bundle "$TMP/schema.json" --resolve "$TMP/schemas" --without-id > "$TMP/result.json" 2> "$TMP/stderr.txt"
2828

2929
cat << 'EOF' > "$TMP/expected.json"
3030
{
@@ -39,7 +39,17 @@ cat << 'EOF' > "$TMP/expected.json"
3939
}
4040
EOF
4141

42+
cat << 'EOF' > "$TMP/expected-stderr.txt"
43+
warning: You are opting in to remove schema identifiers in the bundled schema.
44+
The only legit use case of this advanced feature we know of it to workaround
45+
non-compliant JSON Schema implementations such as Visual Studio Code.
46+
In other case, this is not needed and may harm other use cases. For example,
47+
you will be unable to reference the resulting schema from other schemas
48+
using the --resolve/-r option.
49+
EOF
50+
4251
diff "$TMP/result.json" "$TMP/expected.json"
52+
diff "$TMP/stderr.txt" "$TMP/expected-stderr.txt"
4353

4454
# Must come out formatted
4555
"$1" fmt "$TMP/result.json" --check

test/bundle/pass_without_id_verbose.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ EOF
2828

2929
cat << EOF > "$TMP/expected.json"
3030
Importing schema into the resolution context: $(realpath "$TMP")/schemas/remote.json
31-
Removing schema identifiers
32-
Importing schema into the resolution context: $(realpath "$TMP")/schemas/remote.json
31+
warning: You are opting in to remove schema identifiers in the bundled schema.
32+
The only legit use case of this advanced feature we know of it to workaround
33+
non-compliant JSON Schema implementations such as Visual Studio Code.
34+
In other case, this is not needed and may harm other use cases. For example,
35+
you will be unable to reference the resulting schema from other schemas
36+
using the --resolve/-r option.
3337
{
3438
"\$schema": "https://json-schema.org/draft/2020-12/schema",
3539
"\$ref": "#/\$defs/https%3A~1~1example.com~1nested",
@@ -42,6 +46,4 @@ Importing schema into the resolution context: $(realpath "$TMP")/schemas/remote.
4246
}
4347
EOF
4448

45-
cat "$TMP/result.json"
46-
4749
diff "$TMP/result.json" "$TMP/expected.json"

0 commit comments

Comments
 (0)