From b8802487a51f663530a50af078e405e80974323b Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 14 Jan 2025 14:30:09 -0400 Subject: [PATCH] Remove the `canonicalize` and `identify` niche commands (#209) These are very specialised commands that pretty much nobody seems to be using right now. Signed-off-by: Juan Cruz Viotti --- README.markdown | 2 - docs/canonicalize.markdown | 83 ----------- docs/identify.markdown | 48 ------- src/CMakeLists.txt | 2 - src/command.h | 2 - src/command_canonicalize.cc | 30 ---- src/command_identify.cc | 132 ------------------ src/main.cc | 14 -- test/CMakeLists.txt | 21 --- test/canonicalize/fail_no_schema.sh | 19 --- test/canonicalize/fail_schema_invalid_json.sh | 25 ---- test/canonicalize/fail_unknown_metaschema.sh | 26 ---- test/canonicalize/pass_1.sh | 68 --------- test/identify/fail_invalid_base_uri.sh | 26 ---- test/identify/fail_invalid_id.sh | 25 ---- test/identify/fail_invalid_id_uri.sh | 25 ---- test/identify/fail_no_id.sh | 24 ---- test/identify/fail_no_schema.sh | 19 --- test/identify/fail_resolve_from_equal.sh | 26 ---- test/identify/fail_resolve_from_no_match.sh | 26 ---- test/identify/pass_with_official_dialect.sh | 27 ---- .../pass_with_official_dialect_verbose.sh | 27 ---- test/identify/pass_with_resolve_from.sh | 28 ---- .../pass_with_resolve_from_verbose.sh | 30 ---- test/identify/pass_with_unknown_dialect.sh | 28 ---- .../pass_with_unknown_dialect_verbose.sh | 28 ---- 26 files changed, 811 deletions(-) delete mode 100644 docs/canonicalize.markdown delete mode 100644 docs/identify.markdown delete mode 100644 src/command_canonicalize.cc delete mode 100644 src/command_identify.cc delete mode 100755 test/canonicalize/fail_no_schema.sh delete mode 100755 test/canonicalize/fail_schema_invalid_json.sh delete mode 100755 test/canonicalize/fail_unknown_metaschema.sh delete mode 100755 test/canonicalize/pass_1.sh delete mode 100755 test/identify/fail_invalid_base_uri.sh delete mode 100755 test/identify/fail_invalid_id.sh delete mode 100755 test/identify/fail_invalid_id_uri.sh delete mode 100755 test/identify/fail_no_id.sh delete mode 100755 test/identify/fail_no_schema.sh delete mode 100755 test/identify/fail_resolve_from_equal.sh delete mode 100755 test/identify/fail_resolve_from_no_match.sh delete mode 100755 test/identify/pass_with_official_dialect.sh delete mode 100755 test/identify/pass_with_official_dialect_verbose.sh delete mode 100755 test/identify/pass_with_resolve_from.sh delete mode 100755 test/identify/pass_with_resolve_from_verbose.sh delete mode 100755 test/identify/pass_with_unknown_dialect.sh delete mode 100755 test/identify/pass_with_unknown_dialect_verbose.sh diff --git a/README.markdown b/README.markdown index 40ce2e20..8bf1a380 100644 --- a/README.markdown +++ b/README.markdown @@ -63,8 +63,6 @@ documentation: - [`jsonschema lint`](./docs/lint.markdown) - [`jsonschema bundle`](./docs/bundle.markdown) (for inlining remote references in a schema) - [`jsonschema frame`](./docs/frame.markdown) (for debugging references) -- [`jsonschema identify`](./docs/identify.markdown) -- [`jsonschema canonicalize`](./docs/canonicalize.markdown) (for static analysis) - [`jsonschema encode`](./docs/encode.markdown) (for binary compression) - [`jsonschema decode`](./docs/decode.markdown) diff --git a/docs/canonicalize.markdown b/docs/canonicalize.markdown deleted file mode 100644 index 49727312..00000000 --- a/docs/canonicalize.markdown +++ /dev/null @@ -1,83 +0,0 @@ -Canonicalize -============ - -```sh -jsonschema canonicalize -``` - -JSON Schema is an extremely expressive schema language. As such, schema authors -can express the same constraints in a variety of ways, making the process of -statically analyzing schemas complex. This command attempts to tackle the -problem by transforming a given JSON Schema into a simpler (but more verbose) -normalized form referred to as _canonical_. - -> Refer to [Juan Cruz Viotti's dissertation on JSON -> BinPack](https://www.jviotti.com/dissertation.pdf) for how JSON Schema -> canonicalization was originally defined. - -Examples --------- - -For example, consider the following simple schema: - -```json -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - } -} -``` - -The canonicalization process will result in something like this: - -``` -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "enum": [ - null - ] - }, - { - "enum": [ - false, - true - ] - }, - { - "type": "object", - "minProperties": 0, - "properties": { - "foo": { - "type": "string", - "minLength": 0 - } - } - }, - { - "type": "array", - "minItems": 0 - }, - { - "type": "string", - "minLength": 0 - }, - { - "type": "number", - "multipleOf": 1 - }, - { - "type": "integer", - "multipleOf": 1 - } - ] -} -``` - -### Canonicalize a JSON Schema - -```sh -jsonschema canonicalize path/to/my/schema.json -``` diff --git a/docs/identify.markdown b/docs/identify.markdown deleted file mode 100644 index d8971b94..00000000 --- a/docs/identify.markdown +++ /dev/null @@ -1,48 +0,0 @@ -Identify -======== - -```sh -jsonschema identify [--relative-to/-t ] [--verbose/-v] -``` - -A schema may be associated with a URI through the use of keywords like `$id` or -its predecessor `id`. This command takes a JSON Schema as input and prints to -standard output the identifying URI of the schema. This command heuristically -handles the case where you don't know the base dialect of the schema. For -convenience, you may provide a base URI to resolve the schema identity URI -against. - -Examples --------- - -For example, consider the following schema identified as -`https://example.com/foo/bar`. - -```json -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/foo/bar" -} -``` - -We can interact with the identifier URI of this schema as follows: - -```sh -$ jsonschema identify schema.json -https://example.com/foo/bar - -$ jsonschema identify schema.json --relative-to "https://example.com" -/foo/bar -``` - -### Identify a JSON Schema - -```sh -jsonschema identify path/to/my/schema.json -``` - -### Identify a JSON Schema resolving the URI relative to a given base - -```sh -jsonschema identify path/to/my/schema.json --relative-to "https://example.com" -``` diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index afa14806..2c7a7524 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,8 +8,6 @@ add_executable(jsonschema_cli command_lint.cc command_metaschema.cc command_validate.cc - command_identify.cc - command_canonicalize.cc command_encode.cc command_decode.cc) diff --git a/src/command.h b/src/command.h index 56a20e39..e69e4d10 100644 --- a/src/command.h +++ b/src/command.h @@ -12,8 +12,6 @@ auto test(const std::span &arguments) -> int; auto lint(const std::span &arguments) -> int; auto validate(const std::span &arguments) -> int; auto metaschema(const std::span &arguments) -> int; -auto identify(const std::span &arguments) -> int; -auto canonicalize(const std::span &arguments) -> int; auto encode(const std::span &arguments) -> int; auto decode(const std::span &arguments) -> int; } // namespace sourcemeta::jsonschema::cli diff --git a/src/command_canonicalize.cc b/src/command_canonicalize.cc deleted file mode 100644 index f9a61bf8..00000000 --- a/src/command_canonicalize.cc +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include - -#include // EXIT_SUCCESS -#include // std::cout, std::endl - -#include "command.h" -#include "utils.h" - -auto sourcemeta::jsonschema::cli::canonicalize( - const std::span &arguments) -> int { - const auto options{parse_options(arguments, {})}; - - if (options.at("").size() < 1) { - std::cerr - << "error: This command expects a path to a schema. For example:\n\n" - << " jsonschema canonicalize path/to/schema.json\n"; - return EXIT_FAILURE; - } - - auto schema{sourcemeta::jsontoolkit::from_file(options.at("").front())}; - sourcemeta::jsonbinpack::canonicalize( - schema, sourcemeta::jsontoolkit::default_schema_walker, - resolver(options, options.contains("h") || options.contains("http"))); - sourcemeta::jsontoolkit::prettify( - schema, std::cout, sourcemeta::jsontoolkit::schema_format_compare); - std::cout << std::endl; - return EXIT_SUCCESS; -} diff --git a/src/command_identify.cc b/src/command_identify.cc deleted file mode 100644 index ec0c5cc3..00000000 --- a/src/command_identify.cc +++ /dev/null @@ -1,132 +0,0 @@ -#include -#include -#include - -#include // EXIT_SUCCESS, EXIT_FAILURE -#include // std::cout - -#include "command.h" -#include "utils.h" - -static auto -find_relative_to(const std::map> &options) - -> std::optional { - if (options.contains("relative-to") && !options.at("relative-to").empty()) { - return options.at("relative-to").front(); - } else if (options.contains("t") && !options.at("t").empty()) { - return options.at("t").front(); - } - - return std::nullopt; -} - -auto sourcemeta::jsonschema::cli::identify( - const std::span &arguments) -> int { - const auto options{parse_options(arguments, {})}; - if (options.at("").size() < 1) { - std::cerr - << "error: This command expects a path to a schema. For example:\n\n" - << " jsonschema identify path/to/schema.json\n"; - return EXIT_FAILURE; - } - - const sourcemeta::jsontoolkit::JSON schema{ - sourcemeta::jsontoolkit::from_file(options.at("").front())}; - - // Just to print a nice warning - try { - const auto base_dialect{sourcemeta::jsontoolkit::base_dialect( - schema, sourcemeta::jsontoolkit::official_resolver)}; - if (!base_dialect.has_value()) { - std::cerr << "warning: Cannot determine the base dialect of the schema, " - "but will attempt to guess\n"; - } - } catch (const sourcemeta::jsontoolkit::SchemaResolutionError &) { - std::cerr << "warning: Cannot determine the base dialect of the schema, " - "but will attempt to guess\n"; - } - - std::optional identifier; - - try { - identifier = sourcemeta::jsontoolkit::identify( - schema, sourcemeta::jsontoolkit::official_resolver, - sourcemeta::jsontoolkit::IdentificationStrategy::Loose); - } catch (const sourcemeta::jsontoolkit::SchemaError &error) { - std::cerr - << "error: " << error.what() << "\n " - << std::filesystem::weakly_canonical(options.at("").front()).string() - << "\n"; - return EXIT_FAILURE; - } - - if (!identifier.has_value()) { - std::cerr - << "error: Could not determine schema identifier\n " - << std::filesystem::weakly_canonical(options.at("").front()).string() - << "\n"; - return EXIT_FAILURE; - } - - std::string result; - - try { - result = sourcemeta::jsontoolkit::URI{identifier.value()} - .canonicalize() - .recompose(); - } catch (const sourcemeta::jsontoolkit::URIParseError &error) { - std::cerr - << "error: Invalid schema identifier URI at column " << error.column() - << "\n " - << std::filesystem::weakly_canonical(options.at("").front()).string() - << "\n"; - return EXIT_FAILURE; - } - - const auto relative_to{find_relative_to(options)}; - if (relative_to.has_value()) { - log_verbose(options) << "Resolving identifier against: " - << relative_to.value() << "\n"; - std::string base; - - try { - base = sourcemeta::jsontoolkit::URI{relative_to.value()} - .canonicalize() - .recompose(); - } catch (const sourcemeta::jsontoolkit::URIParseError &error) { - std::cerr << "error: Invalid base URI at column " << error.column() - << "\n " << relative_to.value() << "\n"; - return EXIT_FAILURE; - } - - sourcemeta::jsontoolkit::URI base_uri{base}; - base_uri.canonicalize(); - sourcemeta::jsontoolkit::URI uri{result}; - uri.canonicalize(); - uri.relative_to(base_uri); - - if (!uri.is_absolute()) { - if (uri.recompose().empty()) { - std::cerr << "error: the base URI cannot be equal to the schema " - "identifier\n " - << std::filesystem::weakly_canonical(options.at("").front()) - .string() - << "\n"; - return EXIT_FAILURE; - } - - std::cout << uri.recompose() << "\n"; - } else { - std::cerr - << "error: the schema identifier " << result - << " is not resolvable from " << base << "\n " - << std::filesystem::weakly_canonical(options.at("").front()).string() - << "\n"; - return EXIT_FAILURE; - } - } else { - std::cout << result << "\n"; - } - - return EXIT_SUCCESS; -} diff --git a/src/main.cc b/src/main.cc index 55a5e715..e4a158fc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -60,16 +60,6 @@ Global Options: Statically analyse a schema to display schema locations and references in a human-readable manner. - identify [--relative-to/-t ] - - Print the URI of the given schema to standard output, optionally - relative to a given base URI. - - canonicalize - - Pre-process a JSON Schema into JSON BinPack's canonical form - for static analysis. - encode Encode a JSON document or JSONL dataset using JSON BinPack. @@ -97,10 +87,6 @@ auto jsonschema_main(const std::string &program, const std::string &command, return sourcemeta::jsonschema::cli::metaschema(arguments); } else if (command == "test") { return sourcemeta::jsonschema::cli::test(arguments); - } else if (command == "identify") { - return sourcemeta::jsonschema::cli::identify(arguments); - } else if (command == "canonicalize") { - return sourcemeta::jsonschema::cli::canonicalize(arguments); } else if (command == "encode") { return sourcemeta::jsonschema::cli::encode(arguments); } else if (command == "decode") { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a2459c38..27704d6c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -144,32 +144,11 @@ add_jsonschema_test_unix(frame/fail_no_schema) add_jsonschema_test_unix(frame/fail_schema_invalid_json) add_jsonschema_test_unix(frame/fail_unknown_metaschema) -# Identify -add_jsonschema_test_unix(identify/fail_resolve_from_no_match) -add_jsonschema_test_unix(identify/fail_resolve_from_equal) -add_jsonschema_test_unix(identify/fail_invalid_id) -add_jsonschema_test_unix(identify/fail_invalid_id_uri) -add_jsonschema_test_unix(identify/fail_invalid_base_uri) -add_jsonschema_test_unix(identify/fail_no_id) -add_jsonschema_test_unix(identify/fail_no_schema) -add_jsonschema_test_unix(identify/pass_with_official_dialect) -add_jsonschema_test_unix(identify/pass_with_official_dialect_verbose) -add_jsonschema_test_unix(identify/pass_with_resolve_from) -add_jsonschema_test_unix(identify/pass_with_resolve_from_verbose) -add_jsonschema_test_unix(identify/pass_with_unknown_dialect) -add_jsonschema_test_unix(identify/pass_with_unknown_dialect_verbose) - # Lint add_jsonschema_test_unix(lint/pass_lint_fix) add_jsonschema_test_unix(lint/pass_lint_no_fix) add_jsonschema_test_unix(lint/fail_lint) -# Canonicalize -add_jsonschema_test_unix(canonicalize/pass_1) -add_jsonschema_test_unix(canonicalize/fail_no_schema) -add_jsonschema_test_unix(canonicalize/fail_schema_invalid_json) -add_jsonschema_test_unix(canonicalize/fail_unknown_metaschema) - # Encode add_jsonschema_test_unix(encode/pass_schema_less) add_jsonschema_test_unix(encode/pass_schema_less_jsonl) diff --git a/test/canonicalize/fail_no_schema.sh b/test/canonicalize/fail_no_schema.sh deleted file mode 100755 index 02986405..00000000 --- a/test/canonicalize/fail_no_schema.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -"$1" canonicalize 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << 'EOF' > "$TMP/expected.txt" -error: This command expects a path to a schema. For example: - - jsonschema canonicalize path/to/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/canonicalize/fail_schema_invalid_json.sh b/test/canonicalize/fail_schema_invalid_json.sh deleted file mode 100755 index a76bcc41..00000000 --- a/test/canonicalize/fail_schema_invalid_json.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "type" string -} -EOF - -"$1" canonicalize "$TMP/schema.json" 2>"$TMP/stderr.txt" \ - && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: Failed to parse the JSON document at line 2 and column 10 - $(realpath "$TMP")/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/canonicalize/fail_unknown_metaschema.sh b/test/canonicalize/fail_unknown_metaschema.sh deleted file mode 100755 index b642564c..00000000 --- a/test/canonicalize/fail_unknown_metaschema.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://example.com/unknown", - "$id": "https://example.com", - "$ref": "nested" -} -EOF - -"$1" canonicalize "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: Could not resolve the requested schema - at https://example.com/unknown -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/canonicalize/pass_1.sh b/test/canonicalize/pass_1.sh deleted file mode 100755 index 2e433967..00000000 --- a/test/canonicalize/pass_1.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - } -} -EOF - -"$1" canonicalize "$TMP/schema.json" > "$TMP/result.json" - -cat "$TMP/result.json" - -cat << 'EOF' > "$TMP/expected.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "enum": [ - null - ] - }, - { - "enum": [ - false, - true - ] - }, - { - "type": "object", - "minProperties": 0, - "properties": { - "foo": { - "type": "string", - "minLength": 0 - } - } - }, - { - "type": "array", - "minItems": 0 - }, - { - "type": "string", - "minLength": 0 - }, - { - "type": "number", - "multipleOf": 1 - }, - { - "type": "integer", - "multipleOf": 1 - } - ] -} -EOF - -diff "$TMP/result.json" "$TMP/expected.json" diff --git a/test/identify/fail_invalid_base_uri.sh b/test/identify/fail_invalid_base_uri.sh deleted file mode 100755 index 4ed8938d..00000000 --- a/test/identify/fail_invalid_base_uri.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema" -} -EOF - -"$1" identify "$TMP/schema.json" \ - --relative-to "111https://////" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: Invalid base URI at column 9 - 111https:////// -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/identify/fail_invalid_id.sh b/test/identify/fail_invalid_id.sh deleted file mode 100755 index 60e9e341..00000000 --- a/test/identify/fail_invalid_id.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$id": 1, - "$schema": "https://json-schema.org/draft/2020-12/schema" -} -EOF - -"$1" identify "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: The value of the \$id property is not valid - $(realpath "$TMP")/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/identify/fail_invalid_id_uri.sh b/test/identify/fail_invalid_id_uri.sh deleted file mode 100755 index 1e861d91..00000000 --- a/test/identify/fail_invalid_id_uri.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$id": "111https://////", - "$schema": "https://json-schema.org/draft/2020-12/schema" -} -EOF - -"$1" identify "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: Invalid schema identifier URI at column 9 - $(realpath "$TMP")/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/identify/fail_no_id.sh b/test/identify/fail_no_id.sh deleted file mode 100755 index 5219246a..00000000 --- a/test/identify/fail_no_id.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema" -} -EOF - -"$1" identify "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: Could not determine schema identifier - $(realpath "$TMP")/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/identify/fail_no_schema.sh b/test/identify/fail_no_schema.sh deleted file mode 100755 index 08ecbdb4..00000000 --- a/test/identify/fail_no_schema.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -"$1" identify 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << 'EOF' > "$TMP/expected.txt" -error: This command expects a path to a schema. For example: - - jsonschema identify path/to/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/identify/fail_resolve_from_equal.sh b/test/identify/fail_resolve_from_equal.sh deleted file mode 100755 index f8242514..00000000 --- a/test/identify/fail_resolve_from_equal.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$id": "https://foo.com", - "$schema": "https://json-schema.org/draft/2020-12/schema" -} -EOF - -"$1" identify "$TMP/schema.json" \ - --relative-to "https://foo.com" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: the base URI cannot be equal to the schema identifier - $(realpath "$TMP")/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/identify/fail_resolve_from_no_match.sh b/test/identify/fail_resolve_from_no_match.sh deleted file mode 100755 index 453d5f58..00000000 --- a/test/identify/fail_resolve_from_no_match.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$id": "https://foo.com", - "$schema": "https://json-schema.org/draft/2020-12/schema" -} -EOF - -"$1" identify "$TMP/schema.json" \ - --relative-to "https://bar.com" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?" -test "$CODE" = "1" || exit 1 - -cat << EOF > "$TMP/expected.txt" -error: the schema identifier https://foo.com is not resolvable from https://bar.com - $(realpath "$TMP")/schema.json -EOF - -diff "$TMP/stderr.txt" "$TMP/expected.txt" diff --git a/test/identify/pass_with_official_dialect.sh b/test/identify/pass_with_official_dialect.sh deleted file mode 100755 index 148b3e03..00000000 --- a/test/identify/pass_with_official_dialect.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com", - "$ref": "#/$defs/string", - "$defs": { - "string": { "type": "string" } - } -} -EOF - -"$1" identify "$TMP/schema.json" > "$TMP/result.txt" 2>&1 - -cat << 'EOF' > "$TMP/expected.txt" -https://example.com -EOF - -diff "$TMP/result.txt" "$TMP/expected.txt" diff --git a/test/identify/pass_with_official_dialect_verbose.sh b/test/identify/pass_with_official_dialect_verbose.sh deleted file mode 100755 index 29ac3037..00000000 --- a/test/identify/pass_with_official_dialect_verbose.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com", - "$ref": "#/$defs/string", - "$defs": { - "string": { "type": "string" } - } -} -EOF - -"$1" identify --verbose "$TMP/schema.json" > "$TMP/result.txt" 2>&1 - -cat << 'EOF' > "$TMP/expected.txt" -https://example.com -EOF - -diff "$TMP/result.txt" "$TMP/expected.txt" diff --git a/test/identify/pass_with_resolve_from.sh b/test/identify/pass_with_resolve_from.sh deleted file mode 100755 index e8c9a699..00000000 --- a/test/identify/pass_with_resolve_from.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/foo/bar/baz", - "$ref": "#/$defs/string", - "$defs": { - "string": { "type": "string" } - } -} -EOF - -"$1" identify "$TMP/schema.json" \ - --relative-to "https://example.com/foo" > "$TMP/result.txt" 2>&1 - -cat << 'EOF' > "$TMP/expected.txt" -bar/baz -EOF - -diff "$TMP/result.txt" "$TMP/expected.txt" diff --git a/test/identify/pass_with_resolve_from_verbose.sh b/test/identify/pass_with_resolve_from_verbose.sh deleted file mode 100755 index cc3b178d..00000000 --- a/test/identify/pass_with_resolve_from_verbose.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/foo/bar/baz", - "$ref": "#/$defs/string", - "$defs": { - "string": { "type": "string" } - } -} -EOF - -"$1" identify "$TMP/schema.json" \ - --verbose \ - --relative-to "https://example.com/foo" > "$TMP/result.txt" 2>&1 - -cat << 'EOF' > "$TMP/expected.txt" -Resolving identifier against: https://example.com/foo -bar/baz -EOF - -diff "$TMP/result.txt" "$TMP/expected.txt" diff --git a/test/identify/pass_with_unknown_dialect.sh b/test/identify/pass_with_unknown_dialect.sh deleted file mode 100755 index f63f587a..00000000 --- a/test/identify/pass_with_unknown_dialect.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://example.com/foo", - "$id": "https://example.com", - "$ref": "#/$defs/string", - "$defs": { - "string": { "type": "string" } - } -} -EOF - -"$1" identify "$TMP/schema.json" > "$TMP/result.txt" 2>&1 - -cat << 'EOF' > "$TMP/expected.txt" -warning: Cannot determine the base dialect of the schema, but will attempt to guess -https://example.com -EOF - -diff "$TMP/result.txt" "$TMP/expected.txt" diff --git a/test/identify/pass_with_unknown_dialect_verbose.sh b/test/identify/pass_with_unknown_dialect_verbose.sh deleted file mode 100755 index 6e777f58..00000000 --- a/test/identify/pass_with_unknown_dialect_verbose.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -set -o errexit -set -o nounset - -TMP="$(mktemp -d)" -clean() { rm -rf "$TMP"; } -trap clean EXIT - -cat << 'EOF' > "$TMP/schema.json" -{ - "$schema": "https://example.com/foo", - "$id": "https://example.com", - "$ref": "#/$defs/string", - "$defs": { - "string": { "type": "string" } - } -} -EOF - -"$1" identify --verbose "$TMP/schema.json" > "$TMP/result.txt" 2>&1 - -cat << 'EOF' > "$TMP/expected.txt" -warning: Cannot determine the base dialect of the schema, but will attempt to guess -https://example.com -EOF - -diff "$TMP/result.txt" "$TMP/expected.txt"