diff --git a/.github/workflows/website-build.yml b/.github/workflows/website-build.yml index 74c9587aa..9db5581ed 100644 --- a/.github/workflows/website-build.yml +++ b/.github/workflows/website-build.yml @@ -38,7 +38,6 @@ jobs: -DSOURCEMETA_CORE_YAML:BOOL=OFF -DSOURCEMETA_CORE_SEMVER:BOOL=OFF -DSOURCEMETA_CORE_HTML:BOOL=OFF - -DSOURCEMETA_CORE_EXTENSION_ALTERSCHEMA:BOOL=OFF -DSOURCEMETA_CORE_EXTENSION_EDITORSCHEMA:BOOL=OFF -DSOURCEMETA_CORE_DOCS:BOOL=ON - run: cmake --build ./build --config Release --target doxygen diff --git a/.github/workflows/website-deploy.yml b/.github/workflows/website-deploy.yml index 7d1b040bf..f4b7b78cf 100644 --- a/.github/workflows/website-deploy.yml +++ b/.github/workflows/website-deploy.yml @@ -48,7 +48,6 @@ jobs: -DSOURCEMETA_CORE_YAML:BOOL=OFF -DSOURCEMETA_CORE_SEMVER:BOOL=OFF -DSOURCEMETA_CORE_HTML:BOOL=OFF - -DSOURCEMETA_CORE_EXTENSION_ALTERSCHEMA:BOOL=OFF -DSOURCEMETA_CORE_EXTENSION_EDITORSCHEMA:BOOL=OFF -DSOURCEMETA_CORE_DOCS:BOOL=ON - run: cmake --build ./build --config Release --target doxygen diff --git a/CMakeLists.txt b/CMakeLists.txt index c12369e28..e6b7b872b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,6 @@ option(SOURCEMETA_CORE_JSONL "Build the Sourcemeta Core JSONL library" ON) option(SOURCEMETA_CORE_YAML "Build the Sourcemeta Core YAML library" ON) option(SOURCEMETA_CORE_SEMVER "Build the Sourcemeta Core SemVer library" ON) option(SOURCEMETA_CORE_HTML "Build the Sourcemeta Core HTML library" ON) -option(SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA "Build the Sourcemeta Core AlterSchema library" ON) option(SOURCEMETA_CORE_EXTENSION_EDITORSCHEMA "Build the Sourcemeta Core EditorSchema library" ON) option(SOURCEMETA_CORE_TESTS "Build the Sourcemeta Core tests" OFF) option(SOURCEMETA_CORE_BENCHMARK "Build the Sourcemeta Core benchmarks" OFF) @@ -155,10 +154,6 @@ if(SOURCEMETA_CORE_HTML) add_subdirectory(src/core/html) endif() -if(SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA) - add_subdirectory(src/extension/alterschema) -endif() - if(SOURCEMETA_CORE_EXTENSION_EDITORSCHEMA) add_subdirectory(src/extension/editorschema) endif() @@ -278,10 +273,6 @@ if(SOURCEMETA_CORE_TESTS) add_subdirectory(test/html) endif() - if(SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA) - add_subdirectory(test/alterschema) - endif() - if(SOURCEMETA_CORE_EXTENSION_EDITORSCHEMA) add_subdirectory(test/editorschema) endif() diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 0712d693b..592900e5a 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -16,10 +16,6 @@ if(SOURCEMETA_CORE_JSONSCHEMA) list(APPEND BENCHMARK_SOURCES jsonschema.cc) endif() -if(SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA) - list(APPEND BENCHMARK_SOURCES alterschema.cc) -endif() - if(SOURCEMETA_CORE_EXTENSION_EDITORSCHEMA) list(APPEND BENCHMARK_SOURCES editorschema.cc) endif() @@ -58,11 +54,6 @@ if(BENCHMARK_SOURCES) PRIVATE sourcemeta::core::jsonschema) endif() - if(SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA) - target_link_libraries(sourcemeta_core_benchmark - PRIVATE sourcemeta::core::alterschema) - endif() - if(SOURCEMETA_CORE_EXTENSION_EDITORSCHEMA) target_link_libraries(sourcemeta_core_benchmark PRIVATE sourcemeta::core::editorschema) diff --git a/benchmark/alterschema.cc b/benchmark/alterschema.cc deleted file mode 100644 index 68cd6f14f..000000000 --- a/benchmark/alterschema.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include - -#include // assert -#include // std::size_t -#include // std::filesystem - -#include -#include -#include - -static void -Alterschema_Check_Readibility_ISO_Language_Set_3(benchmark::State &state) { - const auto schema{sourcemeta::core::read_json( - std::filesystem::path{CURRENT_DIRECTORY} / "files" / - "2020_12_iso_language_2023_set_3.json")}; - - sourcemeta::core::SchemaTransformer bundle; - sourcemeta::core::add(bundle, sourcemeta::core::AlterSchemaMode::Linter); - - for (auto _ : state) { - auto result = bundle.check(schema, sourcemeta::core::schema_walker, - sourcemeta::core::schema_resolver, - [](const auto &, const auto &, const auto &, - const auto &, const auto &) {}); - assert(result.first); - assert(result.second == 100); - benchmark::DoNotOptimize(result); - } -} - -static void Alterschema_Check_Readibility_OMC(benchmark::State &state) { - const auto schema{ - sourcemeta::core::read_json(std::filesystem::path{CURRENT_DIRECTORY} / - "files" / "2019_09_omc_json_v2.json")}; - - sourcemeta::core::SchemaTransformer bundle; - sourcemeta::core::add(bundle, sourcemeta::core::AlterSchemaMode::Linter); - - for (auto _ : state) { - auto result = bundle.check(schema, sourcemeta::core::schema_walker, - sourcemeta::core::schema_resolver, - [](const auto &, const auto &, const auto &, - const auto &, const auto &) {}); - assert(!result.first); - benchmark::DoNotOptimize(result); - } -} - -static void Alterschema_Apply_Readibility_KrakenD(benchmark::State &state) { - sourcemeta::core::SchemaTransformer bundle; - sourcemeta::core::add(bundle, sourcemeta::core::AlterSchemaMode::Linter); - - const auto schema{ - sourcemeta::core::read_json(std::filesystem::path{CURRENT_DIRECTORY} / - "files" / "2019_09_krakend.json")}; - - for (auto _ : state) { - state.PauseTiming(); - auto copy = schema; - state.ResumeTiming(); - auto result = bundle.apply(copy, sourcemeta::core::schema_walker, - sourcemeta::core::schema_resolver, - [](const auto &, const auto &, const auto &, - const auto &, const auto &) {}); - assert(!result.first); - benchmark::DoNotOptimize(result); - } -} - -static void Alterschema_Check_Invalid_External_Refs(benchmark::State &state) { - const auto schema{sourcemeta::core::read_json( - std::filesystem::path{CURRENT_DIRECTORY} / "files" / - "2020_12_many_invalid_external_refs.json")}; - - sourcemeta::core::SchemaTransformer bundle; - sourcemeta::core::add(bundle, sourcemeta::core::AlterSchemaMode::Linter); - - for (auto _ : state) { - std::size_t trace_count{0}; - auto result = bundle.check( - schema, sourcemeta::core::schema_walker, - sourcemeta::core::schema_resolver, - [&trace_count](const auto &, [[maybe_unused]] const auto &name, - const auto &, const auto &, const auto &) { - assert(name == "invalid_external_ref"); - trace_count++; - }); - assert(!result.first); - assert(trace_count == 1024); - benchmark::DoNotOptimize(result); - } -} - -BENCHMARK(Alterschema_Check_Readibility_ISO_Language_Set_3); -BENCHMARK(Alterschema_Check_Readibility_OMC); -BENCHMARK(Alterschema_Apply_Readibility_KrakenD); -BENCHMARK(Alterschema_Check_Invalid_External_Refs); diff --git a/config.cmake.in b/config.cmake.in index 0f93f6c68..be8f8bdb5 100644 --- a/config.cmake.in +++ b/config.cmake.in @@ -24,7 +24,6 @@ if(NOT SOURCEMETA_CORE_COMPONENTS) list(APPEND SOURCEMETA_CORE_COMPONENTS yaml) list(APPEND SOURCEMETA_CORE_COMPONENTS semver) list(APPEND SOURCEMETA_CORE_COMPONENTS html) - list(APPEND SOURCEMETA_CORE_COMPONENTS alterschema) list(APPEND SOURCEMETA_CORE_COMPONENTS editorschema) list(APPEND SOURCEMETA_CORE_COMPONENTS error) list(APPEND SOURCEMETA_CORE_COMPONENTS options) @@ -115,18 +114,6 @@ foreach(component ${SOURCEMETA_CORE_COMPONENTS}) elseif(component STREQUAL "html") include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_preprocessor.cmake") include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_html.cmake") - elseif(component STREQUAL "alterschema") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_ip.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_uri.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_numeric.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_io.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_unicode.cmake") - find_dependency(PCRE2 CONFIG) - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_regex.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_json.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_jsonpointer.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_jsonschema.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_alterschema.cmake") elseif(component STREQUAL "editorschema") include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_ip.cmake") include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_core_uri.cmake") diff --git a/src/extension/alterschema/CMakeLists.txt b/src/extension/alterschema/CMakeLists.txt deleted file mode 100644 index 635e0c357..000000000 --- a/src/extension/alterschema/CMakeLists.txt +++ /dev/null @@ -1,115 +0,0 @@ -sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME alterschema - SOURCES alterschema.cc - # Canonicalizer - canonicalizer/const_as_enum.h - canonicalizer/exclusive_maximum_integer_to_maximum.h - canonicalizer/exclusive_minimum_integer_to_minimum.h - canonicalizer/items_implicit.h - canonicalizer/max_contains_covered_by_max_items.h - canonicalizer/min_items_given_min_contains.h - canonicalizer/min_items_implicit.h - canonicalizer/min_length_implicit.h - canonicalizer/min_properties_covered_by_required.h - canonicalizer/min_properties_implicit.h - canonicalizer/multiple_of_implicit.h - canonicalizer/properties_implicit.h - canonicalizer/type_array_to_any_of.h - canonicalizer/type_boolean_as_enum.h - canonicalizer/type_null_as_enum.h - canonicalizer/type_union_implicit.h - - # Common - common/allof_false_simplify.h - common/anyof_false_simplify.h - common/anyof_remove_false_schemas.h - common/anyof_true_simplify.h - common/const_in_enum.h - common/const_with_type.h - common/orphan_definitions.h - common/content_media_type_without_encoding.h - common/content_schema_without_media_type.h - common/dependencies_property_tautology.h - common/dependent_required_tautology.h - common/draft_official_dialect_with_https.h - common/draft_official_dialect_without_empty_fragment.h - common/draft_ref_siblings.h - common/drop_allof_empty_schemas.h - common/duplicate_allof_branches.h - common/duplicate_anyof_branches.h - common/duplicate_enum_values.h - common/duplicate_required_values.h - common/empty_object_as_true.h - common/else_empty.h - common/else_without_if.h - common/enum_with_type.h - common/equal_numeric_bounds_to_enum.h - common/exclusive_maximum_number_and_maximum.h - common/exclusive_minimum_number_and_minimum.h - common/if_without_then_else.h - common/ignored_metaschema.h - common/max_contains_without_contains.h - common/maximum_real_for_integer.h - common/min_contains_without_contains.h - common/minimum_real_for_integer.h - common/modern_official_dialect_with_empty_fragment.h - common/modern_official_dialect_with_http.h - common/non_applicable_additional_items.h - common/non_applicable_enum_validation_keywords.h - common/non_applicable_type_specific_keywords.h - common/not_false.h - common/oneof_false_simplify.h - common/oneof_to_anyof_disjoint_types.h - common/required_properties_in_properties.h - common/single_type_array.h - common/then_empty.h - common/then_without_if.h - common/unknown_keywords_prefix.h - common/unknown_local_ref.h - common/unsatisfiable_drop_validation.h - common/unnecessary_allof_ref_wrapper_draft.h - common/unnecessary_allof_ref_wrapper_modern.h - common/unnecessary_allof_wrapper.h - common/unsatisfiable_in_place_applicator_type.h - - # Linter - linter/comment_trim.h - linter/const_not_in_enum.h - linter/content_schema_default.h - linter/definitions_to_defs.h - linter/dependencies_default.h - linter/dependent_required_default.h - linter/description_trailing_period.h - linter/description_trim.h - linter/duplicate_examples.h - linter/enum_to_const.h - linter/equal_numeric_bounds_to_const.h - linter/forbid_empty_enum.h - linter/incoherent_min_max_contains.h - linter/invalid_external_ref.h - linter/items_array_default.h - linter/items_schema_default.h - linter/multiple_of_default.h - linter/pattern_properties_default.h - linter/properties_default.h - linter/property_names_default.h - linter/property_names_type_default.h - linter/simple_properties_identifiers.h - linter/title_description_equal.h - linter/title_trailing_period.h - linter/title_trim.h - linter/top_level_description.h - linter/top_level_examples.h - linter/top_level_title.h - linter/unevaluated_items_default.h - linter/unevaluated_properties_default.h - linter/unsatisfiable_max_contains.h - linter/unsatisfiable_min_properties.h) - -if(SOURCEMETA_CORE_INSTALL) - sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME alterschema) -endif() - -target_link_libraries(sourcemeta_core_alterschema PUBLIC - sourcemeta::core::jsonschema) -target_link_libraries(sourcemeta_core_alterschema PRIVATE - sourcemeta::core::regex) diff --git a/src/extension/alterschema/alterschema.cc b/src/extension/alterschema/alterschema.cc deleted file mode 100644 index ad79e2862..000000000 --- a/src/extension/alterschema/alterschema.cc +++ /dev/null @@ -1,258 +0,0 @@ -#include -#include - -// For built-in rules -#include // std::sort, std::unique -#include // std::floor -#include // std::back_inserter -#include // std::unique_ptr, std::make_unique -#include // std::unordered_map -#include // std::unordered_set -#include // std::move, std::to_underlying -namespace sourcemeta::core { - -template -auto APPLIES_TO_KEYWORDS(Args &&...args) -> SchemaTransformRule::Result { - std::vector result; - result.reserve(sizeof...(args)); - (result.push_back(Pointer{std::forward(args)}), ...); - return result; -} - -inline auto APPLIES_TO_POINTERS(std::vector &&keywords) - -> SchemaTransformRule::Result { - return {std::move(keywords)}; -} - -#define ONLY_CONTINUE_IF(condition) \ - if (!(condition)) { \ - return false; \ - } - -// Canonicalizer -#include "canonicalizer/const_as_enum.h" -#include "canonicalizer/exclusive_maximum_integer_to_maximum.h" -#include "canonicalizer/exclusive_minimum_integer_to_minimum.h" -#include "canonicalizer/items_implicit.h" -#include "canonicalizer/max_contains_covered_by_max_items.h" -#include "canonicalizer/min_items_given_min_contains.h" -#include "canonicalizer/min_items_implicit.h" -#include "canonicalizer/min_length_implicit.h" -#include "canonicalizer/min_properties_covered_by_required.h" -#include "canonicalizer/min_properties_implicit.h" -#include "canonicalizer/multiple_of_implicit.h" -#include "canonicalizer/properties_implicit.h" -#include "canonicalizer/type_array_to_any_of.h" -#include "canonicalizer/type_boolean_as_enum.h" -#include "canonicalizer/type_null_as_enum.h" -#include "canonicalizer/type_union_implicit.h" - -// Common -#include "common/allof_false_simplify.h" -#include "common/anyof_false_simplify.h" -#include "common/anyof_remove_false_schemas.h" -#include "common/anyof_true_simplify.h" -#include "common/const_in_enum.h" -#include "common/const_with_type.h" -#include "common/content_media_type_without_encoding.h" -#include "common/content_schema_without_media_type.h" -#include "common/dependencies_property_tautology.h" -#include "common/dependent_required_tautology.h" -#include "common/draft_official_dialect_with_https.h" -#include "common/draft_official_dialect_without_empty_fragment.h" -#include "common/draft_ref_siblings.h" -#include "common/drop_allof_empty_schemas.h" -#include "common/duplicate_allof_branches.h" -#include "common/duplicate_anyof_branches.h" -#include "common/duplicate_enum_values.h" -#include "common/duplicate_required_values.h" -#include "common/else_empty.h" -#include "common/else_without_if.h" -#include "common/empty_object_as_true.h" -#include "common/enum_with_type.h" -#include "common/equal_numeric_bounds_to_enum.h" -#include "common/exclusive_maximum_number_and_maximum.h" -#include "common/exclusive_minimum_number_and_minimum.h" -#include "common/if_without_then_else.h" -#include "common/ignored_metaschema.h" -#include "common/max_contains_without_contains.h" -#include "common/maximum_real_for_integer.h" -#include "common/min_contains_without_contains.h" -#include "common/minimum_real_for_integer.h" -#include "common/modern_official_dialect_with_empty_fragment.h" -#include "common/modern_official_dialect_with_http.h" -#include "common/non_applicable_additional_items.h" -#include "common/non_applicable_enum_validation_keywords.h" -#include "common/non_applicable_type_specific_keywords.h" -#include "common/not_false.h" -#include "common/oneof_false_simplify.h" -#include "common/oneof_to_anyof_disjoint_types.h" -#include "common/orphan_definitions.h" -#include "common/required_properties_in_properties.h" -#include "common/single_type_array.h" -#include "common/then_empty.h" -#include "common/then_without_if.h" -#include "common/unknown_keywords_prefix.h" -#include "common/unknown_local_ref.h" -#include "common/unnecessary_allof_ref_wrapper_draft.h" -#include "common/unnecessary_allof_ref_wrapper_modern.h" -#include "common/unnecessary_allof_wrapper.h" -#include "common/unsatisfiable_drop_validation.h" -#include "common/unsatisfiable_in_place_applicator_type.h" - -// Linter -#include "linter/comment_trim.h" -#include "linter/const_not_in_enum.h" -#include "linter/content_schema_default.h" -#include "linter/definitions_to_defs.h" -#include "linter/dependencies_default.h" -#include "linter/dependent_required_default.h" -#include "linter/description_trailing_period.h" -#include "linter/description_trim.h" -#include "linter/duplicate_examples.h" -#include "linter/enum_to_const.h" -#include "linter/equal_numeric_bounds_to_const.h" -#include "linter/forbid_empty_enum.h" -#include "linter/incoherent_min_max_contains.h" -#include "linter/invalid_external_ref.h" -#include "linter/items_array_default.h" -#include "linter/items_schema_default.h" -#include "linter/multiple_of_default.h" -#include "linter/pattern_properties_default.h" -#include "linter/properties_default.h" -#include "linter/property_names_default.h" -#include "linter/property_names_type_default.h" -#include "linter/simple_properties_identifiers.h" -#include "linter/title_description_equal.h" -#include "linter/title_trailing_period.h" -#include "linter/title_trim.h" -#include "linter/top_level_description.h" -#include "linter/top_level_examples.h" -#include "linter/top_level_title.h" -#include "linter/unevaluated_items_default.h" -#include "linter/unevaluated_properties_default.h" -#include "linter/unsatisfiable_max_contains.h" -#include "linter/unsatisfiable_min_properties.h" - -#undef ONLY_CONTINUE_IF -} // namespace sourcemeta::core - -namespace sourcemeta::core { - -auto add(SchemaTransformer &bundle, const AlterSchemaMode mode) -> void { - if (mode == AlterSchemaMode::Canonicalizer) { - bundle.add(); - bundle.add(); - } - - if (mode == AlterSchemaMode::Linter) { - bundle.add(); - } - - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - - if (mode == AlterSchemaMode::Canonicalizer) { - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - } - - if (mode == AlterSchemaMode::Linter) { - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - } - - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); - bundle.add(); -} - -} // namespace sourcemeta::core diff --git a/src/extension/alterschema/canonicalizer/const_as_enum.h b/src/extension/alterschema/canonicalizer/const_as_enum.h deleted file mode 100644 index 138f718a1..000000000 --- a/src/extension/alterschema/canonicalizer/const_as_enum.h +++ /dev/null @@ -1,35 +0,0 @@ -class ConstAsEnum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ConstAsEnum() - : SchemaTransformRule{"const_as_enum", - "Setting `const` is syntax sugar for an " - "enumeration of a single value"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("const") && - !schema.defines("enum")); - return APPLIES_TO_KEYWORDS("const"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto values = sourcemeta::core::JSON::make_array(); - values.push_back(schema.at("const")); - schema.at("const").into(std::move(values)); - schema.rename("const", "enum"); - } -}; diff --git a/src/extension/alterschema/canonicalizer/exclusive_maximum_integer_to_maximum.h b/src/extension/alterschema/canonicalizer/exclusive_maximum_integer_to_maximum.h deleted file mode 100644 index 16246872f..000000000 --- a/src/extension/alterschema/canonicalizer/exclusive_maximum_integer_to_maximum.h +++ /dev/null @@ -1,66 +0,0 @@ -class ExclusiveMaximumIntegerToMaximum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ExclusiveMaximumIntegerToMaximum() - : SchemaTransformRule{ - "exclusive_maximum_integer_to_maximum", - "Setting `exclusiveMaximum` when `type` is `integer` is syntax " - "sugar for `maximum`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "integer" && - schema.defines("exclusiveMaximum") && - schema.at("exclusiveMaximum").is_number() && - !schema.defines("maximum")); - return APPLIES_TO_KEYWORDS("exclusiveMaximum", "type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.at("exclusiveMaximum").is_integer()) { - auto new_maximum = schema.at("exclusiveMaximum"); - new_maximum += sourcemeta::core::JSON{-1}; - schema.at("exclusiveMaximum").into(new_maximum); - schema.rename("exclusiveMaximum", "maximum"); - } else if (schema.at("exclusiveMaximum").is_decimal()) { - const auto current{schema.at("exclusiveMaximum").to_decimal()}; - auto new_value{current.to_integral()}; - if (new_value > current) { - new_value -= sourcemeta::core::Decimal{1}; - } - - if (current.is_integer()) { - new_value -= sourcemeta::core::Decimal{1}; - } - - if (new_value.is_int64()) { - schema.at("exclusiveMaximum") - .into(sourcemeta::core::JSON{new_value.to_int64()}); - } else { - schema.at("exclusiveMaximum").into(sourcemeta::core::JSON{new_value}); - } - - schema.rename("exclusiveMaximum", "maximum"); - } else { - const auto current{schema.at("exclusiveMaximum").to_real()}; - const auto new_value{static_cast(std::floor(current))}; - schema.at("exclusiveMaximum").into(sourcemeta::core::JSON{new_value}); - schema.rename("exclusiveMaximum", "maximum"); - } - } -}; diff --git a/src/extension/alterschema/canonicalizer/exclusive_minimum_integer_to_minimum.h b/src/extension/alterschema/canonicalizer/exclusive_minimum_integer_to_minimum.h deleted file mode 100644 index 87479ab7c..000000000 --- a/src/extension/alterschema/canonicalizer/exclusive_minimum_integer_to_minimum.h +++ /dev/null @@ -1,66 +0,0 @@ -class ExclusiveMinimumIntegerToMinimum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ExclusiveMinimumIntegerToMinimum() - : SchemaTransformRule{ - "exclusive_minimum_integer_to_minimum", - "Setting `exclusiveMinimum` when `type` is `integer` is syntax " - "sugar for `minimum`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "integer" && - schema.defines("exclusiveMinimum") && - schema.at("exclusiveMinimum").is_number() && - !schema.defines("minimum")); - return APPLIES_TO_KEYWORDS("exclusiveMinimum", "type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.at("exclusiveMinimum").is_integer()) { - auto new_minimum = schema.at("exclusiveMinimum"); - new_minimum += sourcemeta::core::JSON{1}; - schema.at("exclusiveMinimum").into(new_minimum); - schema.rename("exclusiveMinimum", "minimum"); - } else if (schema.at("exclusiveMinimum").is_decimal()) { - const auto current{schema.at("exclusiveMinimum").to_decimal()}; - auto new_value{current.to_integral()}; - if (new_value < current) { - new_value += sourcemeta::core::Decimal{1}; - } - - if (current.is_integer()) { - new_value += sourcemeta::core::Decimal{1}; - } - - if (new_value.is_int64()) { - schema.at("exclusiveMinimum") - .into(sourcemeta::core::JSON{new_value.to_int64()}); - } else { - schema.at("exclusiveMinimum").into(sourcemeta::core::JSON{new_value}); - } - - schema.rename("exclusiveMinimum", "minimum"); - } else { - const auto current{schema.at("exclusiveMinimum").to_real()}; - const auto new_value{static_cast(std::ceil(current))}; - schema.at("exclusiveMinimum").into(sourcemeta::core::JSON{new_value}); - schema.rename("exclusiveMinimum", "minimum"); - } - } -}; diff --git a/src/extension/alterschema/canonicalizer/items_implicit.h b/src/extension/alterschema/canonicalizer/items_implicit.h deleted file mode 100644 index 50a361e08..000000000 --- a/src/extension/alterschema/canonicalizer/items_implicit.h +++ /dev/null @@ -1,40 +0,0 @@ -class ItemsImplicit final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ItemsImplicit() - : SchemaTransformRule{"items_implicit", - "Every array has an implicit `items` " - "that consists of the boolean schema `true`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - ((vocabularies.contains( - Vocabularies::Known::JSON_Schema_2020_12_Validation) && - vocabularies.contains( - Vocabularies::Known::JSON_Schema_2020_12_Applicator)) || - (vocabularies.contains( - Vocabularies::Known::JSON_Schema_2019_09_Validation) && - vocabularies.contains( - Vocabularies::Known::JSON_Schema_2019_09_Applicator)) || - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6})) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "array" && !schema.defines("items")); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.assign("items", JSON{true}); - } -}; diff --git a/src/extension/alterschema/canonicalizer/max_contains_covered_by_max_items.h b/src/extension/alterschema/canonicalizer/max_contains_covered_by_max_items.h deleted file mode 100644 index 225a28922..000000000 --- a/src/extension/alterschema/canonicalizer/max_contains_covered_by_max_items.h +++ /dev/null @@ -1,36 +0,0 @@ -class MaxContainsCoveredByMaxItems final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - MaxContainsCoveredByMaxItems() - : SchemaTransformRule{ - "max_contains_covered_by_max_items", - "Setting the `maxContains` keyword to a number greater than or " - "equal to the array upper bound does not add any further " - "constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("maxContains") && - schema.at("maxContains").is_integer() && schema.defines("maxItems") && - schema.at("maxItems").is_integer() && - schema.at("maxContains").to_integer() > - schema.at("maxItems").to_integer()); - return APPLIES_TO_KEYWORDS("maxContains", "maxItems"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.assign("maxContains", schema.at("maxItems")); - } -}; diff --git a/src/extension/alterschema/canonicalizer/min_items_given_min_contains.h b/src/extension/alterschema/canonicalizer/min_items_given_min_contains.h deleted file mode 100644 index 56a23358e..000000000 --- a/src/extension/alterschema/canonicalizer/min_items_given_min_contains.h +++ /dev/null @@ -1,40 +0,0 @@ -class MinItemsGivenMinContains final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MinItemsGivenMinContains() - : SchemaTransformRule{ - "min_items_given_min_contains", - "Every array has a minimum size of zero items but may be affected " - "by `minContains`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "array" && - !schema.defines("minItems")); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.defines("contains") && schema.defines("minContains") && - schema.at("minContains").is_integer()) { - schema.assign("minItems", sourcemeta::core::JSON{ - schema.at("minContains").to_integer()}); - } else { - schema.assign("minItems", sourcemeta::core::JSON{0}); - } - } -}; diff --git a/src/extension/alterschema/canonicalizer/min_items_implicit.h b/src/extension/alterschema/canonicalizer/min_items_implicit.h deleted file mode 100644 index dfdeae065..000000000 --- a/src/extension/alterschema/canonicalizer/min_items_implicit.h +++ /dev/null @@ -1,35 +0,0 @@ -class MinItemsImplicit final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MinItemsImplicit() - : SchemaTransformRule{"min_items_implicit", - "Every array has a minimum size of zero items"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any({Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "array" && - !schema.defines("minItems")); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.assign("minItems", sourcemeta::core::JSON{0}); - } -}; diff --git a/src/extension/alterschema/canonicalizer/min_length_implicit.h b/src/extension/alterschema/canonicalizer/min_length_implicit.h deleted file mode 100644 index 7414758d3..000000000 --- a/src/extension/alterschema/canonicalizer/min_length_implicit.h +++ /dev/null @@ -1,38 +0,0 @@ -class MinLengthImplicit final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MinLengthImplicit() - : SchemaTransformRule{ - "min_length_implicit", - "Every string has a minimum length of zero characters"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "string" && - !schema.defines("minLength")); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.assign("minLength", sourcemeta::core::JSON{0}); - } -}; diff --git a/src/extension/alterschema/canonicalizer/min_properties_covered_by_required.h b/src/extension/alterschema/canonicalizer/min_properties_covered_by_required.h deleted file mode 100644 index 60a31913a..000000000 --- a/src/extension/alterschema/canonicalizer/min_properties_covered_by_required.h +++ /dev/null @@ -1,40 +0,0 @@ -class MinPropertiesCoveredByRequired final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - MinPropertiesCoveredByRequired() - : SchemaTransformRule{ - "min_properties_covered_by_required", - "Setting `minProperties` to a number less than `required` does " - "not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("minProperties") && - schema.at("minProperties").is_integer() && schema.defines("required") && - schema.at("required").is_array() && schema.at("required").unique() && - std::cmp_greater(schema.at("required").size(), - static_cast( - schema.at("minProperties").to_integer()))); - return APPLIES_TO_KEYWORDS("minProperties", "required"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.assign("minProperties", - sourcemeta::core::JSON{schema.at("required").size()}); - } -}; diff --git a/src/extension/alterschema/canonicalizer/min_properties_implicit.h b/src/extension/alterschema/canonicalizer/min_properties_implicit.h deleted file mode 100644 index 9a4dca7dd..000000000 --- a/src/extension/alterschema/canonicalizer/min_properties_implicit.h +++ /dev/null @@ -1,41 +0,0 @@ -class MinPropertiesImplicit final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MinPropertiesImplicit() - : SchemaTransformRule{ - "min_properties_implicit", - "The `minProperties` keyword has a logical default of 0 or the " - "size of `required`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "object" && - !schema.defines("minProperties")); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.defines("required") && schema.at("required").is_array()) { - schema.assign("minProperties", - sourcemeta::core::JSON{schema.at("required").size()}); - } else { - schema.assign("minProperties", sourcemeta::core::JSON{0}); - } - } -}; diff --git a/src/extension/alterschema/canonicalizer/multiple_of_implicit.h b/src/extension/alterschema/canonicalizer/multiple_of_implicit.h deleted file mode 100644 index b04a47f2f..000000000 --- a/src/extension/alterschema/canonicalizer/multiple_of_implicit.h +++ /dev/null @@ -1,35 +0,0 @@ -class MultipleOfImplicit final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MultipleOfImplicit() - : SchemaTransformRule{"multiple_of_implicit", - "The unit of `multipleOf` is the integer 1"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - // Applying this to numbers would be a semantic problem - schema.at("type").to_string() == "integer" && - !schema.defines("multipleOf")); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.assign("multipleOf", sourcemeta::core::JSON{1}); - } -}; diff --git a/src/extension/alterschema/canonicalizer/properties_implicit.h b/src/extension/alterschema/canonicalizer/properties_implicit.h deleted file mode 100644 index 780f0959c..000000000 --- a/src/extension/alterschema/canonicalizer/properties_implicit.h +++ /dev/null @@ -1,45 +0,0 @@ -class PropertiesImplicit final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - PropertiesImplicit() - : SchemaTransformRule{"properties_implicit", - "Every object has an implicit `properties` " - "that consists of the empty object"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - ((vocabularies.contains( - Vocabularies::Known::JSON_Schema_2020_12_Validation) && - vocabularies.contains( - Vocabularies::Known::JSON_Schema_2020_12_Applicator)) || - (vocabularies.contains( - Vocabularies::Known::JSON_Schema_2019_09_Validation) && - vocabularies.contains( - Vocabularies::Known::JSON_Schema_2019_09_Applicator)) || - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "object" && - !schema.defines("properties")); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.assign("properties", sourcemeta::core::JSON::make_object()); - } -}; diff --git a/src/extension/alterschema/canonicalizer/type_array_to_any_of.h b/src/extension/alterschema/canonicalizer/type_array_to_any_of.h deleted file mode 100644 index 1e9c74b34..000000000 --- a/src/extension/alterschema/canonicalizer/type_array_to_any_of.h +++ /dev/null @@ -1,94 +0,0 @@ -class TypeArrayToAnyOf final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - TypeArrayToAnyOf() - : SchemaTransformRule{ - "type_array_to_any_of", - "Setting `type` to more than one choice is syntax sugar to " - "`anyOf` over the corresponding types"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_array()); - - this->keyword_instances_.clear(); - - for (const auto &entry : schema.as_object()) { - if (entry.first == "type") { - continue; - } - - const auto &metadata{walker(entry.first, vocabularies)}; - if (metadata.instances.any()) { - this->keyword_instances_[entry.first] = metadata.instances; - } - } - - return APPLIES_TO_KEYWORDS("type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto disjunctors{sourcemeta::core::JSON::make_array()}; - for (const auto &type : schema.at("type").as_array()) { - auto branch{sourcemeta::core::JSON::make_object()}; - branch.assign("type", type); - const auto current_type_set{parse_schema_type(type)}; - for (const auto &[keyword, instances] : this->keyword_instances_) { - if ((instances & current_type_set).any()) { - branch.assign(keyword, schema.at(keyword)); - } - } - - disjunctors.push_back(std::move(branch)); - } - - for (const auto &[keyword, instances] : this->keyword_instances_) { - schema.erase(keyword); - } - - if (schema.defines("anyOf")) { - auto first_branch{sourcemeta::core::JSON::make_object()}; - first_branch.assign("anyOf", schema.at("anyOf")); - auto second_branch{sourcemeta::core::JSON::make_object()}; - second_branch.assign("anyOf", std::move(disjunctors)); - schema.erase("anyOf"); - - if (schema.defines("allOf")) { - schema.at("allOf").push_back(std::move(first_branch)); - schema.at("allOf").push_back(std::move(second_branch)); - schema.erase("type"); - } else { - auto allof_wrapper{sourcemeta::core::JSON::make_array()}; - allof_wrapper.push_back(std::move(first_branch)); - allof_wrapper.push_back(std::move(second_branch)); - schema.at("type").into(std::move(allof_wrapper)); - schema.rename("type", "allOf"); - } - } else { - schema.at("type").into(std::move(disjunctors)); - schema.rename("type", "anyOf"); - } - } - -private: - mutable std::unordered_map - keyword_instances_; -}; diff --git a/src/extension/alterschema/canonicalizer/type_boolean_as_enum.h b/src/extension/alterschema/canonicalizer/type_boolean_as_enum.h deleted file mode 100644 index bf689d9ff..000000000 --- a/src/extension/alterschema/canonicalizer/type_boolean_as_enum.h +++ /dev/null @@ -1,43 +0,0 @@ -class TypeBooleanAsEnum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - TypeBooleanAsEnum() - : SchemaTransformRule{ - "type_boolean_as_enum", - "Setting `type` to `boolean` is syntax sugar for an enumeration " - "of two values: `false` and `true`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "boolean" && - !schema.defines("enum") && !schema.defines("const")); - return APPLIES_TO_KEYWORDS("type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto choices = sourcemeta::core::JSON::make_array(); - choices.push_back(sourcemeta::core::JSON{false}); - choices.push_back(sourcemeta::core::JSON{true}); - schema.at("type").into(std::move(choices)); - schema.rename("type", "enum"); - } -}; diff --git a/src/extension/alterschema/canonicalizer/type_null_as_enum.h b/src/extension/alterschema/canonicalizer/type_null_as_enum.h deleted file mode 100644 index 81a01c2fb..000000000 --- a/src/extension/alterschema/canonicalizer/type_null_as_enum.h +++ /dev/null @@ -1,42 +0,0 @@ -class TypeNullAsEnum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - TypeNullAsEnum() - : SchemaTransformRule{ - "type_null_as_enum", - "Setting `type` to `null` is syntax sugar for an enumeration " - "of a single value: `null`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "null" && - !schema.defines("enum") && !schema.defines("const")); - return APPLIES_TO_KEYWORDS("type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto choices = sourcemeta::core::JSON::make_array(); - choices.push_back(sourcemeta::core::JSON{nullptr}); - schema.at("type").into(std::move(choices)); - schema.rename("type", "enum"); - } -}; diff --git a/src/extension/alterschema/canonicalizer/type_union_implicit.h b/src/extension/alterschema/canonicalizer/type_union_implicit.h deleted file mode 100644 index aff2a463e..000000000 --- a/src/extension/alterschema/canonicalizer/type_union_implicit.h +++ /dev/null @@ -1,78 +0,0 @@ -class TypeUnionImplicit final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - TypeUnionImplicit() - : SchemaTransformRule{ - "type_union_implicit", - "Not setting `type` is equivalent to accepting any type"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - using namespace sourcemeta::core; - ONLY_CONTINUE_IF(schema.is_object()); - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_0})); - ONLY_CONTINUE_IF(!schema.defines("type")); - ONLY_CONTINUE_IF(!schema.defines("enum")); - ONLY_CONTINUE_IF(!vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) || - !schema.defines("const")); - - for (const auto &entry : schema.as_object()) { - const auto &keyword_type{walker(entry.first, vocabularies).type}; - - // References point to other schemas that may have type constraints - ONLY_CONTINUE_IF(keyword_type != SchemaKeywordType::Reference); - - // Logical in-place applicators apply without affecting the instance - // location, meaning they impose constraints on the same instance. Adding - // an implicit type union alongside these would create redundant branches - // that need complex simplification - ONLY_CONTINUE_IF( - keyword_type != SchemaKeywordType::ApplicatorValueOrElementsInPlace && - keyword_type != SchemaKeywordType::ApplicatorMembersInPlaceSome && - keyword_type != SchemaKeywordType::ApplicatorElementsInPlace && - keyword_type != SchemaKeywordType::ApplicatorElementsInPlaceSome && - keyword_type != - SchemaKeywordType::ApplicatorElementsInPlaceSomeNegate && - keyword_type != SchemaKeywordType::ApplicatorValueInPlaceMaybe && - keyword_type != SchemaKeywordType::ApplicatorValueInPlaceNegate); - } - - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto types{sourcemeta::core::JSON::make_array()}; - - types.push_back(sourcemeta::core::JSON{"null"}); - types.push_back(sourcemeta::core::JSON{"boolean"}); - types.push_back(sourcemeta::core::JSON{"object"}); - types.push_back(sourcemeta::core::JSON{"array"}); - types.push_back(sourcemeta::core::JSON{"string"}); - - // Note we don't add `integer`, as its covered by `number` - types.push_back(sourcemeta::core::JSON{"number"}); - - schema.assign("type", std::move(types)); - } -}; diff --git a/src/extension/alterschema/common/allof_false_simplify.h b/src/extension/alterschema/common/allof_false_simplify.h deleted file mode 100644 index f8a59b1a1..000000000 --- a/src/extension/alterschema/common/allof_false_simplify.h +++ /dev/null @@ -1,45 +0,0 @@ -class AllOfFalseSimplify final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - AllOfFalseSimplify() - : SchemaTransformRule{"allof_false_simplify", - "When `allOf` contains a `false` branch, the " - "schema is unsatisfiable"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - static const JSON::String KEYWORD{"allOf"}; - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines(KEYWORD) && - !schema.defines("not") && schema.at(KEYWORD).is_array()); - - const auto &allof{schema.at(KEYWORD)}; - for (std::size_t index = 0; index < allof.size(); ++index) { - const auto &entry{allof.at(index)}; - if (entry.is_boolean() && !entry.to_boolean()) { - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_POINTERS({Pointer{KEYWORD, index}}); - } - } - - return false; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("allOf").into(JSON{true}); - schema.rename("allOf", "not"); - } -}; diff --git a/src/extension/alterschema/common/anyof_false_simplify.h b/src/extension/alterschema/common/anyof_false_simplify.h deleted file mode 100644 index 562ba54fa..000000000 --- a/src/extension/alterschema/common/anyof_false_simplify.h +++ /dev/null @@ -1,40 +0,0 @@ -class AnyOfFalseSimplify final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - AnyOfFalseSimplify() - : SchemaTransformRule{"anyof_false_simplify", - "An `anyOf` of a single `false` branch is " - "unsatisfiable"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - static const JSON::String KEYWORD{"anyOf"}; - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines(KEYWORD) && - !schema.defines("not") && schema.at(KEYWORD).is_array() && - schema.at(KEYWORD).size() == 1); - - const auto &entry{schema.at(KEYWORD).front()}; - ONLY_CONTINUE_IF(entry.is_boolean() && !entry.to_boolean()); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_POINTERS({Pointer{KEYWORD, 0}}); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("anyOf").into(JSON{true}); - schema.rename("anyOf", "not"); - } -}; diff --git a/src/extension/alterschema/common/anyof_remove_false_schemas.h b/src/extension/alterschema/common/anyof_remove_false_schemas.h deleted file mode 100644 index d8bee7dc2..000000000 --- a/src/extension/alterschema/common/anyof_remove_false_schemas.h +++ /dev/null @@ -1,66 +0,0 @@ -class AnyOfRemoveFalseSchemas final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - AnyOfRemoveFalseSchemas() - : SchemaTransformRule{ - "anyof_remove_false_schemas", - "The boolean schema `false` is guaranteed to never match in " - "`anyOf`, as it is sufficient for any other branch to match"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - static const JSON::String KEYWORD{"anyOf"}; - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_array() && - schema.at(KEYWORD).contains(JSON{false})); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - - std::vector false_locations; - bool has_non_false{false}; - const auto &anyof{schema.at(KEYWORD)}; - for (std::size_t index = 0; index < anyof.size(); ++index) { - const auto &entry{anyof.at(index)}; - if (entry.is_boolean() && !entry.to_boolean()) { - false_locations.push_back(Pointer{KEYWORD, index}); - } else { - has_non_false = true; - } - } - - ONLY_CONTINUE_IF(has_non_false); - return APPLIES_TO_POINTERS(std::move(false_locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - static const JSON::String KEYWORD{"anyOf"}; - - std::unordered_set indices_to_remove; - for (const auto &location : result.locations) { - indices_to_remove.insert(location.at(1).to_index()); - } - - auto new_anyof{JSON::make_array()}; - const auto &anyof{schema.at(KEYWORD)}; - for (std::size_t index = 0; index < anyof.size(); ++index) { - if (!indices_to_remove.contains(index)) { - new_anyof.push_back(anyof.at(index)); - } - } - - schema.assign(KEYWORD, std::move(new_anyof)); - } -}; diff --git a/src/extension/alterschema/common/anyof_true_simplify.h b/src/extension/alterschema/common/anyof_true_simplify.h deleted file mode 100644 index 8cdef08ba..000000000 --- a/src/extension/alterschema/common/anyof_true_simplify.h +++ /dev/null @@ -1,46 +0,0 @@ -class AnyOfTrueSimplify final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - AnyOfTrueSimplify() - : SchemaTransformRule{ - "anyof_true_simplify", - "An `anyOf` with a `true` or `{}` branch always succeeds"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - static const JSON::String KEYWORD{"anyOf"}; - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_array()); - - const auto &anyof{schema.at(KEYWORD)}; - for (std::size_t index = 0; index < anyof.size(); ++index) { - const auto &entry{anyof.at(index)}; - if ((entry.is_boolean() && entry.to_boolean()) || - (entry.is_object() && entry.empty())) { - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_POINTERS({Pointer{KEYWORD, index}}); - } - } - - return false; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("anyOf"); - } -}; diff --git a/src/extension/alterschema/common/const_in_enum.h b/src/extension/alterschema/common/const_in_enum.h deleted file mode 100644 index 0161d8dc0..000000000 --- a/src/extension/alterschema/common/const_in_enum.h +++ /dev/null @@ -1,34 +0,0 @@ -class ConstInEnum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ConstInEnum() - : SchemaTransformRule{ - "const_in_enum", - "If the `const` and `enum` keyword overlap, then `enum` is " - "redundant and can be removed"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("const") && - schema.defines("enum") && schema.at("enum").is_array() && - schema.at("enum").contains(schema.at("const"))); - return APPLIES_TO_KEYWORDS("const", "enum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("enum"); - } -}; diff --git a/src/extension/alterschema/common/const_with_type.h b/src/extension/alterschema/common/const_with_type.h deleted file mode 100644 index a853f28b6..000000000 --- a/src/extension/alterschema/common/const_with_type.h +++ /dev/null @@ -1,37 +0,0 @@ -class ConstWithType final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ConstWithType() - : SchemaTransformRule{ - "const_with_type", - "Setting `type` alongside `const` is considered an anti-pattern, " - "as the constant already implies its respective type"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("type") && - schema.defines("const")); - - const auto current_types{parse_schema_type(schema.at("type"))}; - ONLY_CONTINUE_IF( - current_types.test(std::to_underlying(schema.at("const").type()))); - return APPLIES_TO_KEYWORDS("const", "type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("type"); - } -}; diff --git a/src/extension/alterschema/common/content_media_type_without_encoding.h b/src/extension/alterschema/common/content_media_type_without_encoding.h deleted file mode 100644 index 7c8e3e009..000000000 --- a/src/extension/alterschema/common/content_media_type_without_encoding.h +++ /dev/null @@ -1,32 +0,0 @@ -class ContentMediaTypeWithoutEncoding final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ContentMediaTypeWithoutEncoding() - : SchemaTransformRule{ - "content_media_type_without_encoding", - "The `contentMediaType` keyword is meaningless " - "without the presence of the `contentEncoding` keyword"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Content, - Vocabularies::Known::JSON_Schema_2019_09_Content, - Vocabularies::Known::JSON_Schema_Draft_7}) && - schema.is_object() && schema.defines("contentMediaType") && - !schema.defines("contentEncoding")); - return APPLIES_TO_KEYWORDS("contentMediaType"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("contentMediaType"); - } -}; diff --git a/src/extension/alterschema/common/content_schema_without_media_type.h b/src/extension/alterschema/common/content_schema_without_media_type.h deleted file mode 100644 index bfa89eff8..000000000 --- a/src/extension/alterschema/common/content_schema_without_media_type.h +++ /dev/null @@ -1,36 +0,0 @@ -class ContentSchemaWithoutMediaType final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"contentSchema"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ContentSchemaWithoutMediaType() - : SchemaTransformRule{ - "content_schema_without_media_type", - "The `contentSchema` keyword is meaningless without the presence " - "of the `contentMediaType` keyword"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Content, - Vocabularies::Known::JSON_Schema_2019_09_Content}) && - schema.is_object() && schema.defines(KEYWORD) && - !schema.defines("contentMediaType")); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/dependencies_property_tautology.h b/src/extension/alterschema/common/dependencies_property_tautology.h deleted file mode 100644 index e7eec435b..000000000 --- a/src/extension/alterschema/common/dependencies_property_tautology.h +++ /dev/null @@ -1,79 +0,0 @@ -class DependenciesPropertyTautology final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - DependenciesPropertyTautology() - : SchemaTransformRule{ - "dependencies_property_tautology", - "Defining requirements for a property using `dependencies` " - "that is already marked as required is an unnecessarily complex " - "use of `dependencies`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any({Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3}) && - schema.is_object() && schema.defines("dependencies") && - schema.at("dependencies").is_object() && schema.defines("required") && - schema.at("required").is_array()); - ONLY_CONTINUE_IF(std::ranges::any_of( - schema.at("required").as_array(), [&schema](const auto &element) { - return element.is_string() && - schema.at("dependencies").defines(element.to_string()) && - (schema.at("dependencies") - .at(element.to_string()) - .is_array() || - schema.at("dependencies") - .at(element.to_string()) - .is_string()); - })); - return APPLIES_TO_KEYWORDS("dependencies", "required"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto requirements{schema.at("required")}; - while (true) { - bool match{false}; - const auto copy{requirements}; - for (const auto &element : copy.as_array()) { - if (!element.is_string() || - !schema.at("dependencies").defines(element.to_string())) { - continue; - } - - const auto &dependents{ - schema.at("dependencies").at(element.to_string())}; - if (dependents.is_array()) { - for (const auto &dependent : dependents.as_array()) { - if (dependent.is_string()) { - match = true; - requirements.push_back(dependent); - } - } - - schema.at("dependencies").erase(element.to_string()); - } else if (dependents.is_string()) { - match = true; - requirements.push_back(dependents); - schema.at("dependencies").erase(element.to_string()); - } - } - - if (!match) { - break; - } - } - - schema.assign("required", requirements); - } -}; diff --git a/src/extension/alterschema/common/dependent_required_tautology.h b/src/extension/alterschema/common/dependent_required_tautology.h deleted file mode 100644 index 2cebac02c..000000000 --- a/src/extension/alterschema/common/dependent_required_tautology.h +++ /dev/null @@ -1,70 +0,0 @@ -class DependentRequiredTautology final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - DependentRequiredTautology() - : SchemaTransformRule{ - "dependent_required_tautology", - "Defining requirements for a property using `dependentRequired` " - "that is already marked as required is an unnecessarily complex " - "use of `dependentRequired`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("dependentRequired") && - schema.at("dependentRequired").is_object() && - schema.defines("required") && schema.at("required").is_array()); - ONLY_CONTINUE_IF(std::any_of( - schema.at("required").as_array().cbegin(), - schema.at("required").as_array().cend(), - [&schema](const auto &element) { - return element.is_string() && - schema.at("dependentRequired").defines(element.to_string()); - })); - return APPLIES_TO_KEYWORDS("dependentRequired", "required"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto requirements{schema.at("required")}; - while (true) { - bool match{false}; - const auto copy{requirements}; - for (const auto &element : copy.as_array()) { - if (!element.is_string() || - !schema.at("dependentRequired").defines(element.to_string())) { - continue; - } - - const auto &dependents{ - schema.at("dependentRequired").at(element.to_string())}; - if (dependents.is_array()) { - for (const auto &dependent : dependents.as_array()) { - if (dependent.is_string()) { - match = true; - requirements.push_back(dependent); - } - } - - schema.at("dependentRequired").erase(element.to_string()); - } - } - - if (!match) { - break; - } - } - - schema.assign("required", requirements); - } -}; diff --git a/src/extension/alterschema/common/draft_official_dialect_with_https.h b/src/extension/alterschema/common/draft_official_dialect_with_https.h deleted file mode 100644 index d9e83d9fa..000000000 --- a/src/extension/alterschema/common/draft_official_dialect_with_https.h +++ /dev/null @@ -1,76 +0,0 @@ -class DraftOfficialDialectWithHttps final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DraftOfficialDialectWithHttps() - : SchemaTransformRule{ - "draft_official_dialect_with_https", - "The official dialect URI of Draft 7 and older must use " - "\"http://\" instead of \"https://\""} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - using sourcemeta::core::SchemaBaseDialect; - ONLY_CONTINUE_IF( - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_7 || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_7_Hyper || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_6 || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_6_Hyper || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_4 || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_4_Hyper || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_3 || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_3_Hyper || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_2_Hyper || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_1_Hyper || - location.base_dialect == SchemaBaseDialect::JSON_Schema_Draft_0_Hyper); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("$schema") && - schema.at("$schema").is_string()); - const auto &dialect{schema.at("$schema").to_string()}; - ONLY_CONTINUE_IF(dialect.starts_with("https://json-schema.org/")); - ONLY_CONTINUE_IF( - dialect == "https://json-schema.org/draft-07/schema" || - dialect == "https://json-schema.org/draft-07/schema#" || - dialect == "https://json-schema.org/draft-07/hyper-schema" || - dialect == "https://json-schema.org/draft-07/hyper-schema#" || - dialect == "https://json-schema.org/draft-06/schema" || - dialect == "https://json-schema.org/draft-06/schema#" || - dialect == "https://json-schema.org/draft-06/hyper-schema" || - dialect == "https://json-schema.org/draft-06/hyper-schema#" || - dialect == "https://json-schema.org/draft-04/schema" || - dialect == "https://json-schema.org/draft-04/schema#" || - dialect == "https://json-schema.org/draft-04/hyper-schema" || - dialect == "https://json-schema.org/draft-04/hyper-schema#" || - dialect == "https://json-schema.org/draft-03/schema" || - dialect == "https://json-schema.org/draft-03/schema#" || - dialect == "https://json-schema.org/draft-03/hyper-schema" || - dialect == "https://json-schema.org/draft-03/hyper-schema#" || - dialect == "https://json-schema.org/draft-02/schema" || - dialect == "https://json-schema.org/draft-02/schema#" || - dialect == "https://json-schema.org/draft-02/hyper-schema" || - dialect == "https://json-schema.org/draft-02/hyper-schema#" || - dialect == "https://json-schema.org/draft-01/schema" || - dialect == "https://json-schema.org/draft-01/schema#" || - dialect == "https://json-schema.org/draft-01/hyper-schema" || - dialect == "https://json-schema.org/draft-01/hyper-schema#" || - dialect == "https://json-schema.org/draft-00/schema" || - dialect == "https://json-schema.org/draft-00/schema#" || - dialect == "https://json-schema.org/draft-00/hyper-schema" || - dialect == "https://json-schema.org/draft-00/hyper-schema#"); - return APPLIES_TO_KEYWORDS("$schema"); - } - - auto transform(sourcemeta::core::JSON &schema, const Result &) const - -> void override { - const auto &old_dialect{schema.at("$schema").to_string()}; - std::string new_dialect{"http://"}; - new_dialect += old_dialect.substr(8); - schema.at("$schema").into(sourcemeta::core::JSON{new_dialect}); - } -}; diff --git a/src/extension/alterschema/common/draft_official_dialect_without_empty_fragment.h b/src/extension/alterschema/common/draft_official_dialect_without_empty_fragment.h deleted file mode 100644 index ff47fa639..000000000 --- a/src/extension/alterschema/common/draft_official_dialect_without_empty_fragment.h +++ /dev/null @@ -1,46 +0,0 @@ -class DraftOfficialDialectWithoutEmptyFragment final - : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DraftOfficialDialectWithoutEmptyFragment() - : SchemaTransformRule{"draft_official_dialect_without_empty_fragment", - "The official dialect URI of Draft 7 and older " - "versions must contain the empty fragment"} {}; - - [[nodiscard]] auto condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("$schema") && - schema.at("$schema").is_string()); - const auto &dialect{schema.at("$schema").to_string()}; - ONLY_CONTINUE_IF( - dialect == "http://json-schema.org/draft-07/schema" || - dialect == "http://json-schema.org/draft-07/hyper-schema" || - dialect == "http://json-schema.org/draft-06/schema" || - dialect == "http://json-schema.org/draft-06/hyper-schema" || - dialect == "http://json-schema.org/draft-04/schema" || - dialect == "http://json-schema.org/draft-04/hyper-schema" || - dialect == "http://json-schema.org/draft-03/schema" || - dialect == "http://json-schema.org/draft-03/hyper-schema" || - dialect == "http://json-schema.org/draft-02/schema" || - dialect == "http://json-schema.org/draft-02/hyper-schema" || - dialect == "http://json-schema.org/draft-01/schema" || - dialect == "http://json-schema.org/draft-01/hyper-schema" || - dialect == "http://json-schema.org/draft-00/schema" || - dialect == "http://json-schema.org/draft-00/hyper-schema"); - return APPLIES_TO_KEYWORDS("$schema"); - } - - auto transform(sourcemeta::core::JSON &schema, const Result &) const - -> void override { - auto dialect{std::move(schema.at("$schema")).to_string()}; - dialect += "#"; - schema.at("$schema").into(sourcemeta::core::JSON{dialect}); - } -}; diff --git a/src/extension/alterschema/common/draft_ref_siblings.h b/src/extension/alterschema/common/draft_ref_siblings.h deleted file mode 100644 index 2b4e02d61..000000000 --- a/src/extension/alterschema/common/draft_ref_siblings.h +++ /dev/null @@ -1,52 +0,0 @@ -class DraftRefSiblings final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DraftRefSiblings() - : SchemaTransformRule{"draft_ref_siblings", - "In Draft 7 and older dialects, keywords sibling " - "to `$ref` are never evaluated"} {} - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any({Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_0})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("$ref")); - - std::vector locations; - for (const auto &entry : schema.as_object()) { - const auto &metadata{walker(entry.first, vocabularies)}; - if (metadata.type == sourcemeta::core::SchemaKeywordType::Reference || - metadata.type == sourcemeta::core::SchemaKeywordType::Comment || - // If we disallow this, we end up deleting it and the linter will fail - // with an error about not knowing the dialect - entry.first == "$schema") { - continue; - } else { - locations.push_back(Pointer{entry.first}); - } - } - - ONLY_CONTINUE_IF(!locations.empty()); - return APPLIES_TO_POINTERS(std::move(locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - schema.erase(location.at(0).to_property()); - } - } -}; diff --git a/src/extension/alterschema/common/drop_allof_empty_schemas.h b/src/extension/alterschema/common/drop_allof_empty_schemas.h deleted file mode 100644 index 346844fa8..000000000 --- a/src/extension/alterschema/common/drop_allof_empty_schemas.h +++ /dev/null @@ -1,45 +0,0 @@ -class DropAllOfEmptySchemas final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DropAllOfEmptySchemas() - : SchemaTransformRule{"drop_allof_empty_schemas", - "Empty schemas in `allOf` are redundant and can be " - "removed"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &, const SchemaFrame::Location &, - const SchemaWalker &, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("allOf") && - schema.at("allOf").is_array() && - !schema.at("allOf").empty()); - ONLY_CONTINUE_IF( - std::ranges::any_of(schema.at("allOf").as_array(), is_empty_schema)); - return APPLIES_TO_KEYWORDS("allOf"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto new_allof{JSON::make_array()}; - for (const auto &entry : schema.at("allOf").as_array()) { - if (!is_empty_schema(entry)) { - new_allof.push_back(entry); - } - } - - if (new_allof.empty()) { - schema.erase("allOf"); - } else { - // Re-assign instead of the deleting in place to invalid memory addresses - // and avoid confusing the transformer - schema.assign("allOf", std::move(new_allof)); - } - } -}; diff --git a/src/extension/alterschema/common/duplicate_allof_branches.h b/src/extension/alterschema/common/duplicate_allof_branches.h deleted file mode 100644 index 2b84e54ea..000000000 --- a/src/extension/alterschema/common/duplicate_allof_branches.h +++ /dev/null @@ -1,76 +0,0 @@ -class DuplicateAllOfBranches final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DuplicateAllOfBranches() - : SchemaTransformRule{ - "duplicate_allof_branches", - "Setting duplicate subschemas in `allOf` is redundant, as it " - "produces " - "unnecessary additional validation that is guaranteed to not " - "affect the validation result"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("allOf") && - schema.at("allOf").is_array() && - !schema.at("allOf").unique()); - // TODO: Highlight which specific entries in `allOf` are duplicated - return APPLIES_TO_KEYWORDS("allOf"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - this->index_mapping_.clear(); - const auto &original{schema.at("allOf")}; - - std::unordered_map, std::size_t, - HashJSON>, - EqualJSON>> - seen; - auto result{JSON::make_array()}; - - for (std::size_t index = 0; index < original.size(); ++index) { - const auto &value{original.at(index)}; - const auto match{seen.find(std::cref(value))}; - - if (match == seen.end()) { - this->index_mapping_[index] = seen.size(); - seen.emplace(std::cref(value), seen.size()); - result.push_back(value); - } else { - this->index_mapping_[index] = match->second; - } - } - - schema.assign("allOf", std::move(result)); - } - - [[nodiscard]] auto rereference(const std::string_view, const Pointer &, - const Pointer &target, - const Pointer ¤t) const - -> Pointer override { - const auto allof_prefix{current.concat({"allOf"})}; - const auto relative{target.resolve_from(allof_prefix)}; - const auto old_index{relative.at(0).to_index()}; - const auto new_index{this->index_mapping_.at(old_index)}; - const Pointer old_prefix{allof_prefix.concat({old_index})}; - const Pointer new_prefix{allof_prefix.concat({new_index})}; - return target.rebase(old_prefix, new_prefix); - } - -private: - mutable std::unordered_map index_mapping_; -}; diff --git a/src/extension/alterschema/common/duplicate_anyof_branches.h b/src/extension/alterschema/common/duplicate_anyof_branches.h deleted file mode 100644 index 50719fe7a..000000000 --- a/src/extension/alterschema/common/duplicate_anyof_branches.h +++ /dev/null @@ -1,76 +0,0 @@ -class DuplicateAnyOfBranches final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DuplicateAnyOfBranches() - : SchemaTransformRule{ - "duplicate_anyof_branches", - "Setting duplicate subschemas in `anyOf` is redundant, as it " - "produces " - "unnecessary additional validation that is guaranteed to not " - "affect the validation result"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("anyOf") && - schema.at("anyOf").is_array() && - !schema.at("anyOf").unique()); - // TODO: Highlight which specific entries in `anyOf` are duplicated - return APPLIES_TO_KEYWORDS("anyOf"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - this->index_mapping_.clear(); - const auto &original{schema.at("anyOf")}; - - std::unordered_map, std::size_t, - HashJSON>, - EqualJSON>> - seen; - auto result{JSON::make_array()}; - - for (std::size_t index = 0; index < original.size(); ++index) { - const auto &value{original.at(index)}; - const auto match{seen.find(std::cref(value))}; - - if (match == seen.end()) { - this->index_mapping_[index] = seen.size(); - seen.emplace(std::cref(value), seen.size()); - result.push_back(value); - } else { - this->index_mapping_[index] = match->second; - } - } - - schema.assign("anyOf", std::move(result)); - } - - [[nodiscard]] auto rereference(const std::string_view, const Pointer &, - const Pointer &target, - const Pointer ¤t) const - -> Pointer override { - const auto anyof_prefix{current.concat({"anyOf"})}; - const auto relative{target.resolve_from(anyof_prefix)}; - const auto old_index{relative.at(0).to_index()}; - const auto new_index{this->index_mapping_.at(old_index)}; - const Pointer old_prefix{anyof_prefix.concat({old_index})}; - const Pointer new_prefix{anyof_prefix.concat({new_index})}; - return target.rebase(old_prefix, new_prefix); - } - -private: - mutable std::unordered_map index_mapping_; -}; diff --git a/src/extension/alterschema/common/duplicate_enum_values.h b/src/extension/alterschema/common/duplicate_enum_values.h deleted file mode 100644 index 8b422cf64..000000000 --- a/src/extension/alterschema/common/duplicate_enum_values.h +++ /dev/null @@ -1,50 +0,0 @@ -class DuplicateEnumValues final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - DuplicateEnumValues() - : SchemaTransformRule{"duplicate_enum_values", - "Setting duplicate values in `enum` is " - "considered an anti-pattern"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("enum") && - schema.at("enum").is_array() && - !schema.at("enum").unique()); - // TODO: Highlight which specific entries in `enum` are duplicated - return APPLIES_TO_KEYWORDS("enum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - // We want to be super careful to maintain the current ordering - // as we delete the duplicates - auto &enumeration{schema.at("enum")}; - std::unordered_set> cache; - for (auto iterator = enumeration.as_array().cbegin(); - iterator != enumeration.as_array().cend();) { - if (cache.contains(*iterator)) { - iterator = enumeration.erase(iterator); - } else { - cache.emplace(*iterator); - iterator++; - } - } - } -}; diff --git a/src/extension/alterschema/common/duplicate_required_values.h b/src/extension/alterschema/common/duplicate_required_values.h deleted file mode 100644 index 9e3f3cbde..000000000 --- a/src/extension/alterschema/common/duplicate_required_values.h +++ /dev/null @@ -1,41 +0,0 @@ -class DuplicateRequiredValues final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - DuplicateRequiredValues() - : SchemaTransformRule{ - "duplicate_required_values", - "Setting duplicate values in `required` is considered an " - "anti-pattern"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("required") && - schema.at("required").is_array() && - !schema.at("required").unique()); - // TODO: Highlight which specific entries in `required` are duplicated - return APPLIES_TO_KEYWORDS("required"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto collection = schema.at("required"); - std::sort(collection.as_array().begin(), collection.as_array().end()); - auto last = - std::unique(collection.as_array().begin(), collection.as_array().end()); - collection.erase(last, collection.as_array().end()); - schema.at("required").into(std::move(collection)); - } -}; diff --git a/src/extension/alterschema/common/else_empty.h b/src/extension/alterschema/common/else_empty.h deleted file mode 100644 index c4f64a0b3..000000000 --- a/src/extension/alterschema/common/else_empty.h +++ /dev/null @@ -1,36 +0,0 @@ -class ElseEmpty final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"else"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ElseEmpty() - : SchemaTransformRule{"else_empty", - "Setting the `else` keyword to the empty schema " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &frame, const SchemaFrame::Location &location, - const SchemaWalker &, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7}) && - schema.is_object() && schema.defines(KEYWORD) && - is_schema(schema.at(KEYWORD)) && is_empty_schema(schema.at(KEYWORD)) && - (schema.at(KEYWORD).is_object() || - (!schema.defines("if") || - !(schema.at("if").is_boolean() && schema.at("if").to_boolean())))); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/else_without_if.h b/src/extension/alterschema/common/else_without_if.h deleted file mode 100644 index 475c62222..000000000 --- a/src/extension/alterschema/common/else_without_if.h +++ /dev/null @@ -1,36 +0,0 @@ -class ElseWithoutIf final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"else"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ElseWithoutIf() - : SchemaTransformRule{"else_without_if", - "The `else` keyword is meaningless " - "without the presence of the `if` keyword"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7}) && - schema.is_object() && schema.defines(KEYWORD) && - !schema.defines("if")); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/empty_object_as_true.h b/src/extension/alterschema/common/empty_object_as_true.h deleted file mode 100644 index 288cab7d9..000000000 --- a/src/extension/alterschema/common/empty_object_as_true.h +++ /dev/null @@ -1,32 +0,0 @@ -class EmptyObjectAsTrue final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - EmptyObjectAsTrue() - : SchemaTransformRule{ - "empty_object_as_true", - "The empty schema `{}` accepts all values and is equivalent to the " - "boolean schema `true`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Core, - Vocabularies::Known::JSON_Schema_2019_09_Core, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.empty()); - return true; - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.into(JSON{true}); - } -}; diff --git a/src/extension/alterschema/common/enum_with_type.h b/src/extension/alterschema/common/enum_with_type.h deleted file mode 100644 index 941b0fb98..000000000 --- a/src/extension/alterschema/common/enum_with_type.h +++ /dev/null @@ -1,44 +0,0 @@ -class EnumWithType final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - EnumWithType() - : SchemaTransformRule{ - "enum_with_type", - "Setting `type` alongside `enum` is considered an anti-pattern, as " - "the enumeration choices already imply their respective types"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("type") && - schema.defines("enum") && schema.at("enum").is_array()); - - const auto current_types{parse_schema_type(schema.at("type"))}; - ONLY_CONTINUE_IF(std::ranges::all_of( - schema.at("enum").as_array(), [¤t_types](const auto &item) { - return current_types.test(std::to_underlying(item.type())); - })); - - return APPLIES_TO_KEYWORDS("enum", "type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("type"); - } -}; diff --git a/src/extension/alterschema/common/equal_numeric_bounds_to_enum.h b/src/extension/alterschema/common/equal_numeric_bounds_to_enum.h deleted file mode 100644 index c7cf7de8f..000000000 --- a/src/extension/alterschema/common/equal_numeric_bounds_to_enum.h +++ /dev/null @@ -1,43 +0,0 @@ -class EqualNumericBoundsToEnum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - EqualNumericBoundsToEnum() - : SchemaTransformRule{ - "equal_numeric_bounds_to_enum", - "Setting `minimum` and `maximum` to the same number only leaves " - "one possible value"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any({Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - (schema.at("type").to_string() == "integer" || - schema.at("type").to_string() == "number") && - schema.defines("minimum") && schema.at("minimum").is_number() && - schema.defines("maximum") && schema.at("maximum").is_number() && - schema.at("minimum") == schema.at("maximum")); - return APPLIES_TO_KEYWORDS("minimum", "maximum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - sourcemeta::core::JSON values = sourcemeta::core::JSON::make_array(); - values.push_back(schema.at("minimum")); - schema.assign("enum", std::move(values)); - schema.erase("type"); - schema.erase("minimum"); - schema.erase("maximum"); - } -}; diff --git a/src/extension/alterschema/common/exclusive_maximum_number_and_maximum.h b/src/extension/alterschema/common/exclusive_maximum_number_and_maximum.h deleted file mode 100644 index dd096d02b..000000000 --- a/src/extension/alterschema/common/exclusive_maximum_number_and_maximum.h +++ /dev/null @@ -1,39 +0,0 @@ -class ExclusiveMaximumNumberAndMaximum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ExclusiveMaximumNumberAndMaximum() - : SchemaTransformRule{ - "exclusive_maximum_number_and_maximum", - "Setting both `exclusiveMaximum` and `maximum` at the same time " - "is considered an anti-pattern. You should choose one"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("maximum") && - schema.defines("exclusiveMaximum") && - schema.at("maximum").is_number() && - schema.at("exclusiveMaximum").is_number()); - return APPLIES_TO_KEYWORDS("exclusiveMaximum", "maximum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.at("maximum") < schema.at("exclusiveMaximum")) { - schema.erase("exclusiveMaximum"); - } else { - schema.erase("maximum"); - } - } -}; diff --git a/src/extension/alterschema/common/exclusive_minimum_number_and_minimum.h b/src/extension/alterschema/common/exclusive_minimum_number_and_minimum.h deleted file mode 100644 index 3fb192f4c..000000000 --- a/src/extension/alterschema/common/exclusive_minimum_number_and_minimum.h +++ /dev/null @@ -1,39 +0,0 @@ -class ExclusiveMinimumNumberAndMinimum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ExclusiveMinimumNumberAndMinimum() - : SchemaTransformRule{ - "exclusive_minimum_number_and_minimum", - "Setting both `exclusiveMinimum` and `minimum` at the same time " - "is considered an anti-pattern. You should choose one"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("minimum") && - schema.defines("exclusiveMinimum") && - schema.at("minimum").is_number() && - schema.at("exclusiveMinimum").is_number()); - return APPLIES_TO_KEYWORDS("exclusiveMinimum", "minimum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.at("exclusiveMinimum") < schema.at("minimum")) { - schema.erase("exclusiveMinimum"); - } else { - schema.erase("minimum"); - } - } -}; diff --git a/src/extension/alterschema/common/if_without_then_else.h b/src/extension/alterschema/common/if_without_then_else.h deleted file mode 100644 index 93bafb3bb..000000000 --- a/src/extension/alterschema/common/if_without_then_else.h +++ /dev/null @@ -1,37 +0,0 @@ -class IfWithoutThenElse final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"if"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - IfWithoutThenElse() - : SchemaTransformRule{ - "if_without_then_else", - "The `if` keyword is meaningless " - "without the presence of the `then` or `else` keywords"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7}) && - schema.is_object() && schema.defines(KEYWORD) && - !schema.defines("then") && !schema.defines("else")); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/ignored_metaschema.h b/src/extension/alterschema/common/ignored_metaschema.h deleted file mode 100644 index 3faed03b9..000000000 --- a/src/extension/alterschema/common/ignored_metaschema.h +++ /dev/null @@ -1,31 +0,0 @@ -class IgnoredMetaschema final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - IgnoredMetaschema() - : SchemaTransformRule{ - "ignored_metaschema", - "A `$schema` declaration without a sibling identifier (or with a " - "sibling `$ref` in Draft 7 and older dialects), is ignored"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("$schema") && - schema.at("$schema").is_string()); - const auto dialect{sourcemeta::core::dialect(schema)}; - ONLY_CONTINUE_IF(!dialect.empty()); - ONLY_CONTINUE_IF(dialect != location.dialect); - return APPLIES_TO_KEYWORDS("$schema"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("$schema"); - } -}; diff --git a/src/extension/alterschema/common/max_contains_without_contains.h b/src/extension/alterschema/common/max_contains_without_contains.h deleted file mode 100644 index 4cad64f2c..000000000 --- a/src/extension/alterschema/common/max_contains_without_contains.h +++ /dev/null @@ -1,32 +0,0 @@ -class MaxContainsWithoutContains final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MaxContainsWithoutContains() - : SchemaTransformRule{"max_contains_without_contains", - "The `maxContains` keyword is meaningless " - "without the presence of the `contains` keyword"} { - }; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("maxContains") && - !schema.defines("contains")); - return APPLIES_TO_KEYWORDS("maxContains"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("maxContains"); - } -}; diff --git a/src/extension/alterschema/common/maximum_real_for_integer.h b/src/extension/alterschema/common/maximum_real_for_integer.h deleted file mode 100644 index 65b77b9eb..000000000 --- a/src/extension/alterschema/common/maximum_real_for_integer.h +++ /dev/null @@ -1,58 +0,0 @@ -class MaximumRealForInteger final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - MaximumRealForInteger() - : SchemaTransformRule{ - "maximum_real_for_integer", - "If an instance is guaranteed to be an integer, setting a real " - "number upper bound is the same as a floor of that upper bound"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "integer" && - schema.defines("maximum") && - (schema.at("maximum").is_real() || - (schema.at("maximum").is_decimal() && - !schema.at("maximum").to_decimal().is_integer()))); - return APPLIES_TO_KEYWORDS("maximum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.at("maximum").is_decimal()) { - auto current{schema.at("maximum").to_decimal()}; - auto new_value{current.to_integral()}; - if (new_value > current) { - new_value -= sourcemeta::core::Decimal{1}; - } - - if (new_value.is_int64()) { - schema.assign("maximum", sourcemeta::core::JSON{new_value.to_int64()}); - } else { - schema.assign("maximum", sourcemeta::core::JSON{std::move(new_value)}); - } - } else { - const auto current{schema.at("maximum").to_real()}; - const auto new_value{static_cast(std::floor(current))}; - schema.assign("maximum", sourcemeta::core::JSON{new_value}); - } - } -}; diff --git a/src/extension/alterschema/common/min_contains_without_contains.h b/src/extension/alterschema/common/min_contains_without_contains.h deleted file mode 100644 index 1bd56a758..000000000 --- a/src/extension/alterschema/common/min_contains_without_contains.h +++ /dev/null @@ -1,32 +0,0 @@ -class MinContainsWithoutContains final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MinContainsWithoutContains() - : SchemaTransformRule{"min_contains_without_contains", - "The `minContains` keyword is meaningless " - "without the presence of the `contains` keyword"} { - }; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("minContains") && - !schema.defines("contains")); - return APPLIES_TO_KEYWORDS("minContains"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("minContains"); - } -}; diff --git a/src/extension/alterschema/common/minimum_real_for_integer.h b/src/extension/alterschema/common/minimum_real_for_integer.h deleted file mode 100644 index ba46ddbc5..000000000 --- a/src/extension/alterschema/common/minimum_real_for_integer.h +++ /dev/null @@ -1,58 +0,0 @@ -class MinimumRealForInteger final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - MinimumRealForInteger() - : SchemaTransformRule{ - "minimum_real_for_integer", - "If an instance is guaranteed to be an integer, setting a real " - "number lower bound is the same as a ceil of that lower bound"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - schema.at("type").to_string() == "integer" && - schema.defines("minimum") && - (schema.at("minimum").is_real() || - (schema.at("minimum").is_decimal() && - !schema.at("minimum").to_decimal().is_integer()))); - return APPLIES_TO_KEYWORDS("minimum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - if (schema.at("minimum").is_decimal()) { - const auto current{schema.at("minimum").to_decimal()}; - auto new_value{current.to_integral()}; - if (new_value < current) { - new_value += sourcemeta::core::Decimal{1}; - } - - if (new_value.is_int64()) { - schema.assign("minimum", sourcemeta::core::JSON{new_value.to_int64()}); - } else { - schema.assign("minimum", sourcemeta::core::JSON{new_value}); - } - } else { - const auto current{schema.at("minimum").to_real()}; - const auto new_value{static_cast(std::ceil(current))}; - schema.assign("minimum", sourcemeta::core::JSON{new_value}); - } - } -}; diff --git a/src/extension/alterschema/common/modern_official_dialect_with_empty_fragment.h b/src/extension/alterschema/common/modern_official_dialect_with_empty_fragment.h deleted file mode 100644 index 555dc687e..000000000 --- a/src/extension/alterschema/common/modern_official_dialect_with_empty_fragment.h +++ /dev/null @@ -1,37 +0,0 @@ -class ModernOfficialDialectWithEmptyFragment final - : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ModernOfficialDialectWithEmptyFragment() - : SchemaTransformRule{ - "modern_official_dialect_with_empty_fragment", - "The official dialect URI of 2019-09 and newer versions must " - "not contain the empty fragment"} {}; - - [[nodiscard]] auto condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("$schema") && - schema.at("$schema").is_string()); - const auto &dialect{schema.at("$schema").to_string()}; - ONLY_CONTINUE_IF( - dialect == "https://json-schema.org/draft/2019-09/schema#" || - dialect == "https://json-schema.org/draft/2019-09/hyper-schema#" || - dialect == "https://json-schema.org/draft/2020-12/schema#" || - dialect == "https://json-schema.org/draft/2020-12/hyper-schema#"); - return APPLIES_TO_KEYWORDS("$schema"); - } - - auto transform(sourcemeta::core::JSON &schema, const Result &) const - -> void override { - auto dialect{std::move(schema.at("$schema")).to_string()}; - dialect.pop_back(); - schema.at("$schema").into(sourcemeta::core::JSON{dialect}); - } -}; diff --git a/src/extension/alterschema/common/modern_official_dialect_with_http.h b/src/extension/alterschema/common/modern_official_dialect_with_http.h deleted file mode 100644 index cca26b705..000000000 --- a/src/extension/alterschema/common/modern_official_dialect_with_http.h +++ /dev/null @@ -1,49 +0,0 @@ -class ModernOfficialDialectWithHttp final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ModernOfficialDialectWithHttp() - : SchemaTransformRule{ - "modern_official_dialect_with_http", - "The official dialect URI of 2019-09 and later must use " - "\"https://\" instead of \"http://\""} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - using sourcemeta::core::SchemaBaseDialect; - ONLY_CONTINUE_IF( - location.base_dialect == SchemaBaseDialect::JSON_Schema_2020_12 || - location.base_dialect == SchemaBaseDialect::JSON_Schema_2020_12_Hyper || - location.base_dialect == SchemaBaseDialect::JSON_Schema_2019_09 || - location.base_dialect == SchemaBaseDialect::JSON_Schema_2019_09_Hyper); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("$schema") && - schema.at("$schema").is_string()); - const auto &dialect{schema.at("$schema").to_string()}; - ONLY_CONTINUE_IF(dialect.starts_with("http://json-schema.org/")); - ONLY_CONTINUE_IF( - dialect == "http://json-schema.org/draft/2020-12/schema" || - dialect == "http://json-schema.org/draft/2020-12/schema#" || - dialect == "http://json-schema.org/draft/2020-12/hyper-schema" || - dialect == "http://json-schema.org/draft/2020-12/hyper-schema#" || - dialect == "http://json-schema.org/draft/2019-09/schema" || - dialect == "http://json-schema.org/draft/2019-09/schema#" || - dialect == "http://json-schema.org/draft/2019-09/hyper-schema" || - dialect == "http://json-schema.org/draft/2019-09/hyper-schema#"); - return APPLIES_TO_KEYWORDS("$schema"); - } - - auto transform(sourcemeta::core::JSON &schema, const Result &) const - -> void override { - const auto &old_dialect{schema.at("$schema").to_string()}; - std::string new_dialect{"https://"}; - new_dialect += old_dialect.substr(7); - schema.at("$schema").into(sourcemeta::core::JSON{new_dialect}); - } -}; diff --git a/src/extension/alterschema/common/non_applicable_additional_items.h b/src/extension/alterschema/common/non_applicable_additional_items.h deleted file mode 100644 index 4ac055cd8..000000000 --- a/src/extension/alterschema/common/non_applicable_additional_items.h +++ /dev/null @@ -1,45 +0,0 @@ -class NonApplicableAdditionalItems final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"additionalItems"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - NonApplicableAdditionalItems() - : SchemaTransformRule{ - "non_applicable_additional_items", - "The `additionalItems` keyword is ignored when the " - "`items` keyword is either not present or set to a schema"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3}) && - schema.is_object() && schema.defines(KEYWORD)); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - - if (schema.defines("items") && is_schema(schema.at("items"))) { - return APPLIES_TO_KEYWORDS(KEYWORD, "items"); - } else if (!schema.defines("items")) { - return APPLIES_TO_KEYWORDS(KEYWORD); - } else { - return false; - } - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/non_applicable_enum_validation_keywords.h b/src/extension/alterschema/common/non_applicable_enum_validation_keywords.h deleted file mode 100644 index a56c24015..000000000 --- a/src/extension/alterschema/common/non_applicable_enum_validation_keywords.h +++ /dev/null @@ -1,67 +0,0 @@ -class NonApplicableEnumValidationKeywords final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - NonApplicableEnumValidationKeywords() - : SchemaTransformRule{ - "non_applicable_enum_validation_keywords", - "Setting validation keywords that do not apply to any item in " - "`enum` is considered an anti-pattern"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_2_Hyper, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_1_Hyper}) && - schema.is_object() && schema.defines("enum") && - schema.at("enum").is_array() && !schema.defines("type")); - - sourcemeta::core::JSON::TypeSet enum_types; - for (const auto &value : schema.at("enum").as_array()) { - enum_types.set(std::to_underlying(value.type())); - } - - ONLY_CONTINUE_IF(enum_types.any()); - - std::vector positions; - for (const auto &entry : schema.as_object()) { - const auto &metadata = walker(entry.first, vocabularies); - - // If instances is empty (none set), the keyword applies to all types - if (metadata.instances.none()) { - continue; - } - - // Check if there's any overlap between keyword's applicable types and - // enum types - if ((metadata.instances & enum_types).none()) { - positions.push_back(Pointer{entry.first}); - } - } - - ONLY_CONTINUE_IF(!positions.empty()); - - return APPLIES_TO_POINTERS(std::move(positions)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - schema.erase(location.at(0).to_property()); - } - } -}; diff --git a/src/extension/alterschema/common/non_applicable_type_specific_keywords.h b/src/extension/alterschema/common/non_applicable_type_specific_keywords.h deleted file mode 100644 index a727a7de2..000000000 --- a/src/extension/alterschema/common/non_applicable_type_specific_keywords.h +++ /dev/null @@ -1,97 +0,0 @@ -class NonApplicableTypeSpecificKeywords final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - NonApplicableTypeSpecificKeywords() - : SchemaTransformRule{"non_applicable_type_specific_keywords", - "Avoid keywords that don't apply to the type or " - "types that the current subschema expects"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object()); - - auto current_types{vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_2_Hyper, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_1_Hyper, - Vocabularies::Known::JSON_Schema_Draft_0, - Vocabularies::Known::JSON_Schema_Draft_0_Hyper}) && - schema.defines("type") - ? parse_schema_type(schema.at("type")) - : sourcemeta::core::JSON::TypeSet{}}; - - if (vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1}) && - schema.defines("enum") && schema.at("enum").is_array()) { - for (const auto &entry : schema.at("enum").as_array()) { - current_types.set(std::to_underlying(entry.type())); - } - } - - if (vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.defines("const")) { - current_types.set(std::to_underlying(schema.at("const").type())); - } - - // This means that the schema has no explicit type constraints, - // so we cannot remove anything from it. - ONLY_CONTINUE_IF(current_types.any()); - - std::vector positions; - for (const auto &entry : schema.as_object()) { - const auto &metadata{walker(entry.first, vocabularies)}; - - // The keyword applies to any type, so it cannot be removed - if (metadata.instances.none()) { - continue; - } - - // If none of the types that the keyword applies to is a valid - // type for the current schema, then by definition we can remove it - if ((metadata.instances & current_types).none()) { - // Skip keywords that have references pointing to them - if (frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(entry.first)})) { - continue; - } - - positions.push_back(Pointer{entry.first}); - } - } - - ONLY_CONTINUE_IF(!positions.empty()); - return APPLIES_TO_POINTERS(std::move(positions)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - schema.erase(location.at(0).to_property()); - } - } -}; diff --git a/src/extension/alterschema/common/not_false.h b/src/extension/alterschema/common/not_false.h deleted file mode 100644 index 65de31f6c..000000000 --- a/src/extension/alterschema/common/not_false.h +++ /dev/null @@ -1,36 +0,0 @@ -class NotFalse final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"not"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - NotFalse() - : SchemaTransformRule{"not_false", - "Setting the `not` keyword to `false` imposes no " - "constraints. Negating `false` yields the " - "always-true schema"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &frame, const SchemaFrame::Location &location, - const SchemaWalker &, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_boolean() && - !schema.at(KEYWORD).to_boolean()); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/oneof_false_simplify.h b/src/extension/alterschema/common/oneof_false_simplify.h deleted file mode 100644 index 64c4adf6a..000000000 --- a/src/extension/alterschema/common/oneof_false_simplify.h +++ /dev/null @@ -1,40 +0,0 @@ -class OneOfFalseSimplify final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - OneOfFalseSimplify() - : SchemaTransformRule{"oneof_false_simplify", - "A `oneOf` of a single `false` branch is " - "unsatisfiable"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - static const JSON::String KEYWORD{"oneOf"}; - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines(KEYWORD) && - !schema.defines("not") && schema.at(KEYWORD).is_array() && - schema.at(KEYWORD).size() == 1); - - const auto &entry{schema.at(KEYWORD).front()}; - ONLY_CONTINUE_IF(entry.is_boolean() && !entry.to_boolean()); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_POINTERS({Pointer{KEYWORD, 0}}); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("oneOf").into(JSON{true}); - schema.rename("oneOf", "not"); - } -}; diff --git a/src/extension/alterschema/common/oneof_to_anyof_disjoint_types.h b/src/extension/alterschema/common/oneof_to_anyof_disjoint_types.h deleted file mode 100644 index 1d31dbd28..000000000 --- a/src/extension/alterschema/common/oneof_to_anyof_disjoint_types.h +++ /dev/null @@ -1,97 +0,0 @@ -class OneOfToAnyOfDisjointTypes final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - OneOfToAnyOfDisjointTypes() - : SchemaTransformRule{ - "oneof_to_anyof_disjoint_types", - "A `oneOf` where all branches have disjoint types can be safely " - "converted to `anyOf`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - static const JSON::String KEYWORD{"oneOf"}; - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_array() && - schema.at(KEYWORD).size() > 1); - - const auto has_validation_vocabulary{vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})}; - - const auto has_const_vocabulary{vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6})}; - - const auto &oneof{schema.at(KEYWORD)}; - std::vector type_sets; - type_sets.reserve(oneof.size()); - - for (const auto &branch : oneof.as_array()) { - ONLY_CONTINUE_IF(branch.is_object()); - - const auto has_type{branch.defines("type")}; - const auto has_const{has_const_vocabulary && branch.defines("const")}; - const auto has_enum{has_validation_vocabulary && branch.defines("enum") && - branch.at("enum").is_array()}; - - if (has_type) { - type_sets.push_back(parse_schema_type(branch.at("type"))); - } else if (has_const && !has_enum) { - JSON::TypeSet branch_types; - branch_types.set(std::to_underlying(branch.at("const").type())); - type_sets.push_back(branch_types); - } else if (has_enum && !has_const) { - JSON::TypeSet branch_types; - for (const auto &item : branch.at("enum").as_array()) { - branch_types.set(std::to_underlying(item.type())); - } - type_sets.push_back(branch_types); - } else { - return false; - } - } - - for (std::size_t index = 0; index < type_sets.size(); ++index) { - for (std::size_t other = index + 1; other < type_sets.size(); ++other) { - ONLY_CONTINUE_IF((type_sets[index] & type_sets[other]).none()); - } - } - - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.rename("oneOf", "anyOf"); - } - - [[nodiscard]] auto - rereference(const std::string_view, const Pointer &origin [[maybe_unused]], - const Pointer &target, const Pointer ¤t) const - -> Pointer override { - const Pointer oneof_prefix{current.concat({"oneOf"})}; - const Pointer anyof_prefix{current.concat({"anyOf"})}; - return target.rebase(oneof_prefix, anyof_prefix); - } -}; diff --git a/src/extension/alterschema/common/orphan_definitions.h b/src/extension/alterschema/common/orphan_definitions.h deleted file mode 100644 index a59c8693f..000000000 --- a/src/extension/alterschema/common/orphan_definitions.h +++ /dev/null @@ -1,125 +0,0 @@ -class OrphanDefinitions final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - OrphanDefinitions() - : SchemaTransformRule{ - "orphan_definitions", - "Schema definitions in `$defs` or `definitions` that " - "are never internally referenced can be removed"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &resolver) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object()); - const bool has_modern_core{ - vocabularies.contains(Vocabularies::Known::JSON_Schema_2020_12_Core) || - vocabularies.contains(Vocabularies::Known::JSON_Schema_2019_09_Core)}; - const bool has_draft_definitions{ - vocabularies.contains(Vocabularies::Known::JSON_Schema_Draft_7) || - vocabularies.contains(Vocabularies::Known::JSON_Schema_Draft_6) || - vocabularies.contains(Vocabularies::Known::JSON_Schema_Draft_4)}; - const bool has_defs{has_modern_core && schema.defines("$defs")}; - const bool has_definitions{(has_modern_core || has_draft_definitions) && - schema.defines("definitions")}; - ONLY_CONTINUE_IF(has_defs || has_definitions); - - const auto base{frame.traverse(frame.root())}; - ONLY_CONTINUE_IF(base.has_value()); - - std::vector orphans; - collect_orphans(frame, base->get(), walker, resolver, location.pointer, - schema, "$defs", has_defs, orphans); - collect_orphans(frame, base->get(), walker, resolver, location.pointer, - schema, "definitions", has_definitions, orphans); - - ONLY_CONTINUE_IF(!orphans.empty()); - return APPLIES_TO_POINTERS(std::move(orphans)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &pointer : result.locations) { - assert(pointer.size() == 2); - assert(pointer.at(0).is_property()); - assert(pointer.at(1).is_property()); - const auto &container{pointer.at(0).to_property()}; - schema.at(container).erase(pointer.at(1).to_property()); - } - - if (schema.defines("$defs") && schema.at("$defs").empty()) { - schema.erase("$defs"); - } - - if (schema.defines("definitions") && schema.at("definitions").empty()) { - schema.erase("definitions"); - } - } - -private: - static auto has_reachable_reference_through( - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &base, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &resolver, - const WeakPointer &pointer) -> bool { - for (const auto &reference : frame.references()) { - const auto destination{frame.traverse(reference.second.destination)}; - if (!destination.has_value()) { - continue; - } - - if (!destination->get().pointer.starts_with(pointer)) { - continue; - } - - const auto &source_pointer{reference.first.second}; - if (source_pointer.empty()) { - return true; - } - - const auto source_location{frame.traverse( - source_pointer.initial(), - sourcemeta::core::SchemaFrame::LocationType::Subschema)}; - if (source_location.has_value() && - frame.is_reachable(base, source_location->get(), walker, resolver)) { - return true; - } - } - - return false; - } - - static auto - collect_orphans(const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &base, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &resolver, - const WeakPointer &prefix, const JSON &schema, - const JSON::String &container, const bool has_container, - std::vector &orphans) -> void { - if (!has_container || !schema.at(container).is_object()) { - return; - } - - for (const auto &entry : schema.at(container).as_object()) { - const WeakPointer entry_pointer{std::cref(container), - std::cref(entry.first)}; - const auto absolute_entry_pointer{prefix.concat(entry_pointer)}; - const auto entry_location{frame.traverse( - absolute_entry_pointer, - sourcemeta::core::SchemaFrame::LocationType::Subschema)}; - if (entry_location.has_value() && - !frame.is_reachable(base, entry_location->get(), walker, resolver) && - !has_reachable_reference_through(frame, base, walker, resolver, - absolute_entry_pointer)) { - orphans.push_back(Pointer{container, entry.first}); - } - } - } -}; diff --git a/src/extension/alterschema/common/required_properties_in_properties.h b/src/extension/alterschema/common/required_properties_in_properties.h deleted file mode 100644 index f4e7a1793..000000000 --- a/src/extension/alterschema/common/required_properties_in_properties.h +++ /dev/null @@ -1,113 +0,0 @@ -class RequiredPropertiesInProperties final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - RequiredPropertiesInProperties() - : SchemaTransformRule{ - "required_properties_in_properties", - "Every property listed in the `required` keyword must be " - "explicitly defined using the `properties` keyword"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &root, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &resolver) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - ((vocabularies.contains( - Vocabularies::Known::JSON_Schema_2020_12_Validation) && - vocabularies.contains( - Vocabularies::Known::JSON_Schema_2020_12_Applicator)) || - (vocabularies.contains( - Vocabularies::Known::JSON_Schema_2019_09_Validation) && - vocabularies.contains( - Vocabularies::Known::JSON_Schema_2019_09_Applicator)) || - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3})) && - schema.is_object() && schema.defines("required") && - schema.at("required").is_array() && !schema.at("required").empty() && - !schema.defines("additionalProperties")); - - std::vector locations; - std::size_t index{0}; - for (const auto &property : schema.at("required").as_array()) { - if (property.is_string() && - !this->defined_in_properties_sibling(schema, property.to_string()) && - !this->defined_in_properties_parent(root, frame, location, walker, - resolver, property.to_string())) { - locations.push_back(Pointer{"required", index}); - } - - index += 1; - } - - ONLY_CONTINUE_IF(!locations.empty()); - return APPLIES_TO_POINTERS(std::move(locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - schema.assign_if_missing("properties", - sourcemeta::core::JSON::make_object()); - for (const auto &location : result.locations) { - const auto &property{ - schema.at("required").at(location.at(1).to_index()).to_string()}; - schema.at("properties").assign(property, sourcemeta::core::JSON{true}); - } - } - -private: - [[nodiscard]] auto - defined_in_properties_sibling(const JSON &schema, - const JSON::String &property) const -> bool { - assert(schema.is_object()); - return schema.defines("properties") && - schema.at("properties").is_object() && - schema.at("properties").defines(property); - }; - - [[nodiscard]] auto - defined_in_properties_parent(const JSON &root, const SchemaFrame &frame, - const SchemaFrame::Location &location, - const SchemaWalker &walker, - const SchemaResolver &resolver, - const JSON::String &property) const -> bool { - auto current_pointer = location.pointer; - auto current_parent = location.parent; - - while (current_parent.has_value()) { - const auto &parent_pointer{current_parent.value()}; - const auto relative_pointer{current_pointer.resolve_from(parent_pointer)}; - assert(!relative_pointer.empty() && relative_pointer.at(0).is_property()); - const auto parent{ - frame.traverse(frame.uri(parent_pointer).value().get())}; - assert(parent.has_value()); - const auto type{walker(relative_pointer.at(0).to_property(), - frame.vocabularies(parent.value().get(), resolver)) - .type}; - if (type != SchemaKeywordType::ApplicatorElementsInPlaceSome && - type != SchemaKeywordType::ApplicatorElementsInPlace && - type != SchemaKeywordType::ApplicatorValueInPlaceMaybe && - type != SchemaKeywordType::ApplicatorValueInPlaceNegate && - type != SchemaKeywordType::ApplicatorValueInPlaceOther) { - return false; - } - - if (this->defined_in_properties_sibling(get(root, parent_pointer), - property)) { - return true; - } - - current_pointer = parent_pointer; - current_parent = parent.value().get().parent; - } - - return false; - }; -}; diff --git a/src/extension/alterschema/common/single_type_array.h b/src/extension/alterschema/common/single_type_array.h deleted file mode 100644 index 742ea1041..000000000 --- a/src/extension/alterschema/common/single_type_array.h +++ /dev/null @@ -1,40 +0,0 @@ -class SingleTypeArray final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - SingleTypeArray() - : SchemaTransformRule{"single_type_array", - "Setting `type` to an array of a single type is " - "the same as directly declaring such type"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_0}) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_array() && - schema.at("type").size() == 1 && - schema.at("type").front().is_string()); - return APPLIES_TO_KEYWORDS("type"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto type{schema.at("type").front()}; - schema.at("type").into(std::move(type)); - } -}; diff --git a/src/extension/alterschema/common/then_empty.h b/src/extension/alterschema/common/then_empty.h deleted file mode 100644 index eacf299a4..000000000 --- a/src/extension/alterschema/common/then_empty.h +++ /dev/null @@ -1,36 +0,0 @@ -class ThenEmpty final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"then"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ThenEmpty() - : SchemaTransformRule{"then_empty", - "Setting the `then` keyword to the empty schema " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &frame, const SchemaFrame::Location &location, - const SchemaWalker &, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7}) && - schema.is_object() && schema.defines(KEYWORD) && - is_schema(schema.at(KEYWORD)) && is_empty_schema(schema.at(KEYWORD)) && - (schema.at(KEYWORD).is_object() || - (!schema.defines("if") || - !(schema.at("if").is_boolean() && schema.at("if").to_boolean())))); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/then_without_if.h b/src/extension/alterschema/common/then_without_if.h deleted file mode 100644 index 75d526d85..000000000 --- a/src/extension/alterschema/common/then_without_if.h +++ /dev/null @@ -1,36 +0,0 @@ -class ThenWithoutIf final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"then"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ThenWithoutIf() - : SchemaTransformRule{"then_without_if", - "The `then` keyword is meaningless " - "without the presence of the `if` keyword"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7}) && - schema.is_object() && schema.defines(KEYWORD) && - !schema.defines("if")); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/unknown_keywords_prefix.h b/src/extension/alterschema/common/unknown_keywords_prefix.h deleted file mode 100644 index 46f1eba51..000000000 --- a/src/extension/alterschema/common/unknown_keywords_prefix.h +++ /dev/null @@ -1,70 +0,0 @@ -class UnknownKeywordsPrefix final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnknownKeywordsPrefix() - : SchemaTransformRule{ - "unknown_keywords_prefix", - "Future versions of JSON Schema will refuse to evaluate unknown " - "keywords or custom keywords from optional vocabularies that don't " - "have an x- prefix"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &, const SchemaFrame::Location &, - const SchemaWalker &walker, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object()); - std::vector locations; - for (const auto &entry : schema.as_object()) { - if (entry.first.starts_with("x-")) { - continue; - } - - const auto &metadata = walker(entry.first, vocabularies); - if (metadata.type == SchemaKeywordType::Unknown && - // If there is any i.e. optional vocabulary we don't recognise, then - // this seemingly unknown keyword might belong to one of those, and - // thus it might not be safe to flag it - !vocabularies.has_unknown()) { - locations.push_back(Pointer{entry.first}); - } - } - - ONLY_CONTINUE_IF(!locations.empty()); - return APPLIES_TO_POINTERS(std::move(locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - this->renames_.clear(); - for (const auto &location : result.locations) { - const auto &keyword{location.at(0).to_property()}; - assert(schema.defines(keyword)); - std::string prefixed_name = "x-" + keyword; - while (schema.defines(prefixed_name)) { - prefixed_name.insert(0, "x-"); - } - - this->renames_.emplace(keyword, prefixed_name); - schema.rename(keyword, std::move(prefixed_name)); - } - } - - [[nodiscard]] auto rereference(const std::string_view, const Pointer &, - const Pointer &target, - const Pointer ¤t) const - -> Pointer override { - for (const auto &[old_name, new_name] : this->renames_) { - const auto result{target.rebase(current.concat(Pointer{old_name}), - current.concat(Pointer{new_name}))}; - if (result != target) { - return result; - } - } - - return target; - } - -private: - mutable std::unordered_map renames_; -}; diff --git a/src/extension/alterschema/common/unknown_local_ref.h b/src/extension/alterschema/common/unknown_local_ref.h deleted file mode 100644 index 1901e91a4..000000000 --- a/src/extension/alterschema/common/unknown_local_ref.h +++ /dev/null @@ -1,61 +0,0 @@ -class UnknownLocalRef final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"$ref"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnknownLocalRef() - : SchemaTransformRule{ - "unknown_local_ref", - "Local references that point to unknown locations are invalid and " - "will result in evaluation failures"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &frame, const SchemaFrame::Location &location, - const SchemaWalker &, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Core, - Vocabularies::Known::JSON_Schema_2019_09_Core, - // In JSON Schema Draft 7 and older, `$ref` overrides siblings. - // However, we do not need to worry about this case here, as if the - // `$ref` points to an unknown local location, the entire schema is - // invalid anyway. We just help at least making the schema valid - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_string()); - - // Find the keyword location entry - auto keyword_pointer{location.pointer}; - keyword_pointer.push_back(std::cref(KEYWORD)); - const auto reference_entry{ - frame.reference(SchemaReferenceType::Static, keyword_pointer)}; - ONLY_CONTINUE_IF(reference_entry.has_value()); - - // If the keyword has no fragment, continue - const auto &reference_fragment{reference_entry->get().fragment}; - ONLY_CONTINUE_IF(reference_fragment.has_value()); - - // Only continue if the reference target does not exist - ONLY_CONTINUE_IF( - !frame.traverse(reference_entry->get().destination).has_value()); - - // If there is a base beyond the fragment, the base must exist. - // Otherwise it is likely an external reference? - const auto &reference_base{reference_entry->get().base}; - if (!reference_base.empty()) { - ONLY_CONTINUE_IF(frame.traverse(reference_base).has_value()); - } - - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/common/unnecessary_allof_ref_wrapper_draft.h b/src/extension/alterschema/common/unnecessary_allof_ref_wrapper_draft.h deleted file mode 100644 index f5f8d38d0..000000000 --- a/src/extension/alterschema/common/unnecessary_allof_ref_wrapper_draft.h +++ /dev/null @@ -1,44 +0,0 @@ -class UnnecessaryAllOfRefWrapperDraft final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnnecessaryAllOfRefWrapperDraft() - : SchemaTransformRule{"unnecessary_allof_ref_wrapper_draft", - "Wrapping `$ref` in `allOf` is only necessary if " - "there are other sibling keywords"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any({Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4})); - ONLY_CONTINUE_IF(schema.is_object() && schema.size() == 1 && - schema.defines("allOf") && schema.at("allOf").is_array()); - - const auto &all_of{schema.at("allOf")}; - - // In Draft 7 and older, `$ref` overrides sibling keywords, so we can only - // elevate it if it is the only keyword of the only branch, and the outer - // subschema only declares `allOf` - ONLY_CONTINUE_IF(all_of.size() == 1); - const auto &entry{all_of.at(0)}; - ONLY_CONTINUE_IF(entry.is_object()); - ONLY_CONTINUE_IF(entry.size() == 1 && entry.defines("$ref")); - - return APPLIES_TO_POINTERS({{"allOf", 0, "$ref"}}); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto value{schema.at("allOf").at(0).at("$ref")}; - schema.at("allOf").into(std::move(value)); - schema.rename("allOf", "$ref"); - } -}; diff --git a/src/extension/alterschema/common/unnecessary_allof_ref_wrapper_modern.h b/src/extension/alterschema/common/unnecessary_allof_ref_wrapper_modern.h deleted file mode 100644 index ade6bd7e6..000000000 --- a/src/extension/alterschema/common/unnecessary_allof_ref_wrapper_modern.h +++ /dev/null @@ -1,70 +0,0 @@ -class UnnecessaryAllOfRefWrapperModern final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnnecessaryAllOfRefWrapperModern() - : SchemaTransformRule{"unnecessary_allof_ref_wrapper_modern", - "Wrapping `$ref` in `allOf` was only necessary in " - "JSON Schema Draft 7 and older"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("allOf") && - schema.at("allOf").is_array()); - - const auto &all_of{schema.at("allOf")}; - - // Don't do anything if there is more than one branch and ALL branches - // define `$ref` (a common multiple composition pattern) - ONLY_CONTINUE_IF( - !(all_of.size() > 1 && - std::ranges::all_of(all_of.as_array(), [](const auto &entry) { - return entry.is_object() && entry.defines("$ref"); - }))); - - std::vector locations; - for (std::size_t index = 0; index < all_of.size(); index++) { - const auto &entry{all_of.at(index)}; - if (entry.is_object() && entry.defines("$ref") && - // We cannot safely elevate a reference on a subschema with its own - // base URI - // TODO: In theory we can if the URI is absolute - !entry.defines("$id") && !schema.defines("$ref")) { - locations.push_back(Pointer{"allOf", index, "$ref"}); - } - } - - ONLY_CONTINUE_IF(!locations.empty()); - return APPLIES_TO_POINTERS(std::move(locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - assert(location.size() == 3); - const auto allof_index{location.at(1).to_index()}; - const auto &keyword{location.at(2).to_property()}; - - if (!schema.defines(keyword)) { - schema.try_assign_before( - keyword, schema.at("allOf").at(allof_index).at(keyword), "allOf"); - schema.at("allOf").at(allof_index).erase(keyword); - } - } - - schema.at("allOf").erase_if(sourcemeta::core::is_empty_schema); - - if (schema.at("allOf").empty()) { - schema.erase("allOf"); - } - } -}; diff --git a/src/extension/alterschema/common/unnecessary_allof_wrapper.h b/src/extension/alterschema/common/unnecessary_allof_wrapper.h deleted file mode 100644 index 33c78e0ea..000000000 --- a/src/extension/alterschema/common/unnecessary_allof_wrapper.h +++ /dev/null @@ -1,180 +0,0 @@ -class UnnecessaryAllOfWrapper final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"allOf"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnnecessaryAllOfWrapper() - : SchemaTransformRule{"unnecessary_allof_wrapper", - "Keywords inside `allOf` that do not conflict with " - "the parent schema can be elevated"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &frame, const SchemaFrame::Location &location, - const SchemaWalker &walker, const SchemaResolver &) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_array() && - !schema.at(KEYWORD).empty()); - - std::unordered_set dependency_blocked; - for (const auto &entry : schema.as_object()) { - for (const auto &dependency : - walker(entry.first, vocabularies).dependencies) { - dependency_blocked.emplace(dependency); - } - } - - const JSON::TypeSet parent_types{ - schema.defines("type") && - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) - ? parse_schema_type(schema.at("type")) - : JSON::TypeSet{}}; - - const auto &all_of{schema.at(KEYWORD)}; - std::vector locations; - std::unordered_set elevated; - - for (auto index = all_of.size(); index > 0; index--) { - const auto &entry{all_of.at(index - 1)}; - if (!entry.is_object() || entry.empty() || - // We separately handle this case, as it has many other subtleties - entry.defines("$ref")) { - continue; - } - - // Skip entries that have direct references pointing to them - auto entry_pointer{location.pointer}; - entry_pointer.push_back(std::cref(KEYWORD)); - entry_pointer.push_back(index - 1); - if (frame.has_references_to(entry_pointer)) { - continue; - } - - // Skip entries that define their own identity, as elevating keywords - // from them could break references that target those anchors - if (!this->is_anonymous(entry, vocabularies)) { - continue; - } - - for (const auto &keyword_entry : entry.as_object()) { - const auto &keyword{keyword_entry.first}; - const auto &metadata{walker(keyword, vocabularies)}; - - if (elevated.contains(keyword) || - (schema.defines(keyword) && - schema.at(keyword) != keyword_entry.second)) { - continue; - } - - if (dependency_blocked.contains(keyword)) { - continue; - } - - if (metadata.instances.any() && parent_types.any() && - (metadata.instances & parent_types).none()) { - continue; - } - - if (std::ranges::any_of( - metadata.dependencies, [&](const auto &dependency) { - return !entry.defines(std::string{dependency}) && - (schema.defines(std::string{dependency}) || - elevated.contains(dependency)); - })) { - continue; - } - - locations.push_back(Pointer{KEYWORD, index - 1, keyword}); - elevated.emplace(keyword); - - for (const auto &dependency : metadata.dependencies) { - if (!entry.defines(std::string{dependency})) { - dependency_blocked.emplace(dependency); - } - } - } - } - - ONLY_CONTINUE_IF(!locations.empty()); - return APPLIES_TO_POINTERS(std::move(locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - assert(location.size() == 3); - const auto allof_index{location.at(1).to_index()}; - const auto &keyword{location.at(2).to_property()}; - schema.try_assign_before( - keyword, schema.at(KEYWORD).at(allof_index).at(keyword), KEYWORD); - schema.at(KEYWORD).at(allof_index).erase(keyword); - } - } - - [[nodiscard]] auto rereference(const std::string_view, const Pointer &, - const Pointer &target, - const Pointer ¤t) const - -> Pointer override { - // The rule moves keywords from /allOf// to / - const auto allof_prefix{current.concat({KEYWORD})}; - const auto relative{target.resolve_from(allof_prefix)}; - const auto &keyword{relative.at(1).to_property()}; - const Pointer old_prefix{allof_prefix.concat({relative.at(0), keyword})}; - const Pointer new_prefix{current.concat({keyword})}; - return target.rebase(old_prefix, new_prefix); - } - -private: - // TODO: Ideally we this information from the frame out of the box - [[nodiscard]] auto is_anonymous(const JSON &entry, - const Vocabularies &vocabularies) const - -> bool { - if (vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Core, - Vocabularies::Known::JSON_Schema_2019_09_Core})) { - if (entry.defines("$id") || entry.defines("$anchor")) { - return false; - } - - if (vocabularies.contains( - Vocabularies::Known::JSON_Schema_2020_12_Core) && - entry.defines("$dynamicAnchor")) { - return false; - } - - if (vocabularies.contains( - Vocabularies::Known::JSON_Schema_2019_09_Core) && - entry.defines("$recursiveAnchor") && - entry.at("$recursiveAnchor").is_boolean() && - entry.at("$recursiveAnchor").to_boolean()) { - return false; - } - - return true; - } - - if (vocabularies.contains_any({Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6})) { - return !entry.defines("$id"); - } - - if (vocabularies.contains(Vocabularies::Known::JSON_Schema_Draft_4)) { - return !entry.defines("id"); - } - - return false; - } -}; diff --git a/src/extension/alterschema/common/unsatisfiable_drop_validation.h b/src/extension/alterschema/common/unsatisfiable_drop_validation.h deleted file mode 100644 index 4e5b44c0e..000000000 --- a/src/extension/alterschema/common/unsatisfiable_drop_validation.h +++ /dev/null @@ -1,85 +0,0 @@ -class UnsatisfiableDropValidation final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnsatisfiableDropValidation() - : SchemaTransformRule{"unsatisfiable_drop_validation", - "Do not place assertions or applicators next to an " - "unsatisfiable negation"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("not") && - schema.at("not").is_boolean() && - schema.at("not").to_boolean()); - - std::vector positions; - for (const auto &entry : schema.as_object()) { - if (entry.first == "not") { - continue; - } - - const auto &metadata{walker(entry.first, vocabularies)}; - if (!is_removable_keyword_type(metadata.type)) { - continue; - } - - if (frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(entry.first)})) { - continue; - } - - positions.push_back(Pointer{entry.first}); - } - - ONLY_CONTINUE_IF(!positions.empty()); - return APPLIES_TO_POINTERS(std::move(positions)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - schema.erase(location.at(0).to_property()); - } - } - -private: - static auto is_removable_keyword_type(const SchemaKeywordType type) -> bool { - switch (type) { - case SchemaKeywordType::Assertion: - case SchemaKeywordType::Reference: - case SchemaKeywordType::LocationMembers: - case SchemaKeywordType::ApplicatorMembersTraversePropertyStatic: - case SchemaKeywordType::ApplicatorMembersTraversePropertyRegex: - case SchemaKeywordType::ApplicatorValueTraverseSomeProperty: - case SchemaKeywordType::ApplicatorValueTraverseAnyPropertyKey: - case SchemaKeywordType::ApplicatorValueTraverseAnyItem: - case SchemaKeywordType::ApplicatorValueTraverseSomeItem: - case SchemaKeywordType::ApplicatorValueTraverseParent: - case SchemaKeywordType::ApplicatorElementsTraverseItem: - case SchemaKeywordType::ApplicatorValueOrElementsTraverseAnyItemOrItem: - case SchemaKeywordType::ApplicatorValueOrElementsInPlace: - case SchemaKeywordType::ApplicatorMembersInPlaceSome: - case SchemaKeywordType::ApplicatorElementsInPlace: - case SchemaKeywordType::ApplicatorElementsInPlaceSome: - case SchemaKeywordType::ApplicatorElementsInPlaceSomeNegate: - case SchemaKeywordType::ApplicatorValueInPlaceMaybe: - case SchemaKeywordType::ApplicatorValueInPlaceOther: - case SchemaKeywordType::ApplicatorValueInPlaceNegate: - return true; - default: - return false; - } - } -}; diff --git a/src/extension/alterschema/common/unsatisfiable_in_place_applicator_type.h b/src/extension/alterschema/common/unsatisfiable_in_place_applicator_type.h deleted file mode 100644 index 08152fabe..000000000 --- a/src/extension/alterschema/common/unsatisfiable_in_place_applicator_type.h +++ /dev/null @@ -1,87 +0,0 @@ -class UnsatisfiableInPlaceApplicatorType final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnsatisfiableInPlaceApplicatorType() - : SchemaTransformRule{ - "unsatisfiable_in_place_applicator_type", - "An in-place applicator branch that defines a `type` with no " - "overlap with the parent `type` can never be satisfied"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &walker, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("type")); - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_0})); - const auto parent_types{parse_schema_type(schema.at("type"))}; - - std::vector locations; - - for (const auto &entry : schema.as_object()) { - const auto &keyword{entry.first}; - const auto &keyword_type{walker(keyword, vocabularies).type}; - - if (keyword_type == SchemaKeywordType::ApplicatorElementsInPlace || - keyword_type == SchemaKeywordType::ApplicatorElementsInPlaceSome) { - if (!entry.second.is_array()) { - continue; - } - - const auto &branches{entry.second}; - for (std::size_t index = 0; index < branches.size(); ++index) { - const auto &branch{branches.at(index)}; - if (!branch.is_object() || !branch.defines("type")) { - continue; - } - - const auto branch_types{parse_schema_type(branch.at("type"))}; - if ((parent_types & branch_types).none()) { - locations.push_back(Pointer{keyword, index}); - } - } - } else if (keyword_type == - SchemaKeywordType::ApplicatorValueInPlaceMaybe) { - if (!entry.second.is_object() || !entry.second.defines("type")) { - continue; - } - - const auto branch_types{parse_schema_type(entry.second.at("type"))}; - if ((parent_types & branch_types).none()) { - locations.push_back(Pointer{keyword}); - } - } - } - - ONLY_CONTINUE_IF(!locations.empty()); - return APPLIES_TO_POINTERS(std::move(locations)); - } - - auto transform(JSON &schema, const Result &result) const -> void override { - for (const auto &location : result.locations) { - if (location.size() == 2) { - const auto &keyword{location.at(0).to_property()}; - const auto index{location.at(1).to_index()}; - schema.at(keyword).at(index).into(JSON{false}); - } else { - assert(location.size() == 1); - const auto &keyword{location.at(0).to_property()}; - schema.at(keyword).into(JSON{false}); - } - } - } -}; diff --git a/src/extension/alterschema/include/sourcemeta/core/alterschema.h b/src/extension/alterschema/include/sourcemeta/core/alterschema.h deleted file mode 100644 index 3a1578840..000000000 --- a/src/extension/alterschema/include/sourcemeta/core/alterschema.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA_H_ -#define SOURCEMETA_CORE_EXTENSION_ALTERSCHEMA_H_ - -/// @defgroup alterschema AlterSchema -/// @brief A growing collection of JSON Schema transformation rules. -/// -/// This functionality is included as follows: -/// -/// ```cpp -/// #include -/// ``` - -#ifndef SOURCEMETA_CORE_ALTERSCHEMA_EXPORT -#include -#endif - -#include - -#include // std::uint8_t - -namespace sourcemeta::core { - -/// @ingroup alterschema -/// The category of a built-in transformation rule -enum class AlterSchemaMode : std::uint8_t { - /// Rules that simplify the given schema for both human readability and - /// performance - Linter, - - /// Rules that surface implicit constraints and simplifies keywords that - /// are syntax sugar to other keywords, potentially decreasing human - /// readability in favor of explicitness - Canonicalizer, -}; - -/// @ingroup alterschema -/// Add a set of built-in schema transformation rules given a category. For -/// example: -/// -/// ```cpp -/// #include -/// #include -/// -/// sourcemeta::core::SchemaTransformer bundle; -/// -/// sourcemeta::core::add(bundle, -/// sourcemeta::core::AlterSchemaMode::Linter); -/// -/// auto schema = sourcemeta::core::parse_json(R"JSON({ -/// "$schema": "https://json-schema.org/draft/2020-12/schema", -/// "foo": 1, -/// "items": { -/// "type": "string", -/// "foo": 2 -/// } -/// })JSON"); -/// -/// bundle.apply(schema, sourcemeta::core::schema_walker, -/// sourcemeta::core::schema_resolver); -/// ``` -SOURCEMETA_CORE_ALTERSCHEMA_EXPORT -auto add(SchemaTransformer &bundle, const AlterSchemaMode mode) -> void; - -} // namespace sourcemeta::core - -#endif diff --git a/src/extension/alterschema/linter/comment_trim.h b/src/extension/alterschema/linter/comment_trim.h deleted file mode 100644 index c29690818..000000000 --- a/src/extension/alterschema/linter/comment_trim.h +++ /dev/null @@ -1,33 +0,0 @@ -class CommentTrim final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - CommentTrim() - : SchemaTransformRule{ - "comment_trim", - "Comments should not contain leading or trailing whitespace"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Core, - Vocabularies::Known::JSON_Schema_2019_09_Core, - Vocabularies::Known::JSON_Schema_Draft_7})); - ONLY_CONTINUE_IF(schema.is_object()); - ONLY_CONTINUE_IF(schema.defines("$comment")); - ONLY_CONTINUE_IF(schema.at("$comment").is_string()); - ONLY_CONTINUE_IF(!schema.at("$comment").is_trimmed()); - return APPLIES_TO_KEYWORDS("$comment"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("$comment").trim(); - } -}; diff --git a/src/extension/alterschema/linter/const_not_in_enum.h b/src/extension/alterschema/linter/const_not_in_enum.h deleted file mode 100644 index 4aff28f9e..000000000 --- a/src/extension/alterschema/linter/const_not_in_enum.h +++ /dev/null @@ -1,30 +0,0 @@ -class ConstNotInEnum final : public SchemaTransformRule { -public: - using mutates = std::false_type; - using reframe_after_transform = std::false_type; - ConstNotInEnum() - : SchemaTransformRule{ - "const_not_in_enum", - "Do not set the `const` and `enum` keyword at the same time, " - "mainly when their values diverge"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("const") && - schema.defines("enum") && schema.at("enum").is_array() && - !schema.at("enum").contains(schema.at("const"))); - return APPLIES_TO_KEYWORDS("const", "enum"); - } -}; diff --git a/src/extension/alterschema/linter/content_schema_default.h b/src/extension/alterschema/linter/content_schema_default.h deleted file mode 100644 index 411d35a86..000000000 --- a/src/extension/alterschema/linter/content_schema_default.h +++ /dev/null @@ -1,38 +0,0 @@ -class ContentSchemaDefault final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"contentSchema"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ContentSchemaDefault() - : SchemaTransformRule{ - "content_schema_default", - "Setting the `contentSchema` keyword to the true schema " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Content, - Vocabularies::Known::JSON_Schema_2019_09_Content}) && - schema.is_object() && schema.defines(KEYWORD) && - ((schema.at(KEYWORD).is_boolean() && schema.at(KEYWORD).to_boolean()) || - (schema.at(KEYWORD).is_object() && schema.at(KEYWORD).empty()))); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/linter/definitions_to_defs.h b/src/extension/alterschema/linter/definitions_to_defs.h deleted file mode 100644 index 016bec717..000000000 --- a/src/extension/alterschema/linter/definitions_to_defs.h +++ /dev/null @@ -1,38 +0,0 @@ -class DefinitionsToDefs final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DefinitionsToDefs() - : SchemaTransformRule{"definitions_to_defs", - "`definitions` was superseded by `$defs` in " - "2019-09 and later versions"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Core, - Vocabularies::Known::JSON_Schema_2019_09_Core}) && - schema.is_object() && schema.defines("definitions") && - !schema.defines("$defs")); - return APPLIES_TO_KEYWORDS("definitions"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.rename("definitions", "$defs"); - } - - [[nodiscard]] auto rereference(const std::string_view, const Pointer &, - const Pointer &target, - const Pointer ¤t) const - -> Pointer override { - return target.rebase(current.concat({"definitions"}), - current.concat({"$defs"})); - } -}; diff --git a/src/extension/alterschema/linter/dependencies_default.h b/src/extension/alterschema/linter/dependencies_default.h deleted file mode 100644 index 29dde6bde..000000000 --- a/src/extension/alterschema/linter/dependencies_default.h +++ /dev/null @@ -1,38 +0,0 @@ -class DependenciesDefault final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"dependencies"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DependenciesDefault() - : SchemaTransformRule{ - "dependencies_default", - "Setting the `dependencies` keyword to an empty object " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any({Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3}) && - schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_object() && schema.at(KEYWORD).empty()); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/linter/dependent_required_default.h b/src/extension/alterschema/linter/dependent_required_default.h deleted file mode 100644 index f108dc3bb..000000000 --- a/src/extension/alterschema/linter/dependent_required_default.h +++ /dev/null @@ -1,33 +0,0 @@ -class DependentRequiredDefault final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - DependentRequiredDefault() - : SchemaTransformRule{ - "dependent_required_default", - "Setting the `dependentRequired` keyword to an empty object " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("dependentRequired") && - schema.at("dependentRequired").is_object() && - schema.at("dependentRequired").empty()); - return APPLIES_TO_KEYWORDS("dependentRequired"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("dependentRequired"); - } -}; diff --git a/src/extension/alterschema/linter/description_trailing_period.h b/src/extension/alterschema/linter/description_trailing_period.h deleted file mode 100644 index 31e6bc403..000000000 --- a/src/extension/alterschema/linter/description_trailing_period.h +++ /dev/null @@ -1,46 +0,0 @@ -class DescriptionTrailingPeriod final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - DescriptionTrailingPeriod() - : SchemaTransformRule{ - "description_trailing_period", - "Descriptions should not end with a period to give user interfaces " - "flexibility in presenting the text"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object()); - ONLY_CONTINUE_IF(schema.defines("description")); - ONLY_CONTINUE_IF(schema.at("description").is_string()); - const auto &description{schema.at("description").to_string()}; - ONLY_CONTINUE_IF(!description.empty() && description.back() == '.'); - return APPLIES_TO_KEYWORDS("description"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto &description{schema.at("description")}; - auto value{description.to_string()}; - while (!value.empty() && value.back() == '.') { - value.pop_back(); - } - - description.into(JSON{value}); - } -}; diff --git a/src/extension/alterschema/linter/description_trim.h b/src/extension/alterschema/linter/description_trim.h deleted file mode 100644 index 7b1744251..000000000 --- a/src/extension/alterschema/linter/description_trim.h +++ /dev/null @@ -1,39 +0,0 @@ -class DescriptionTrim final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - DescriptionTrim() - : SchemaTransformRule{ - "description_trim", - "Descriptions should not contain leading or trailing whitespace"} { - }; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object()); - ONLY_CONTINUE_IF(schema.defines("description")); - ONLY_CONTINUE_IF(schema.at("description").is_string()); - ONLY_CONTINUE_IF(!schema.at("description").is_trimmed()); - return APPLIES_TO_KEYWORDS("description"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("description").trim(); - } -}; diff --git a/src/extension/alterschema/linter/duplicate_examples.h b/src/extension/alterschema/linter/duplicate_examples.h deleted file mode 100644 index 8471bd394..000000000 --- a/src/extension/alterschema/linter/duplicate_examples.h +++ /dev/null @@ -1,42 +0,0 @@ -class DuplicateExamples final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - DuplicateExamples() - : SchemaTransformRule{ - "duplicate_examples", - "Setting duplicate values in `examples` is redundant"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("examples") && - schema.at("examples").is_array() && - !schema.at("examples").unique()); - return APPLIES_TO_KEYWORDS("examples"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - std::unordered_set> seen; - auto result = JSON::make_array(); - for (const auto &element : schema.at("examples").as_array()) { - if (!seen.contains(element)) { - seen.insert(element); - result.push_back(element); - } - } - - schema.at("examples").into(std::move(result)); - } -}; diff --git a/src/extension/alterschema/linter/enum_to_const.h b/src/extension/alterschema/linter/enum_to_const.h deleted file mode 100644 index 7e1ffb2d3..000000000 --- a/src/extension/alterschema/linter/enum_to_const.h +++ /dev/null @@ -1,35 +0,0 @@ -class EnumToConst final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - EnumToConst() - : SchemaTransformRule{ - "enum_to_const", - "An `enum` of a single value can be expressed as `const`"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && !schema.defines("const") && - schema.defines("enum") && schema.at("enum").is_array() && - schema.at("enum").size() == 1); - return APPLIES_TO_KEYWORDS("enum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto front{schema.at("enum").front()}; - schema.at("enum").into(front); - schema.rename("enum", "const"); - } -}; diff --git a/src/extension/alterschema/linter/equal_numeric_bounds_to_const.h b/src/extension/alterschema/linter/equal_numeric_bounds_to_const.h deleted file mode 100644 index 603d5692d..000000000 --- a/src/extension/alterschema/linter/equal_numeric_bounds_to_const.h +++ /dev/null @@ -1,42 +0,0 @@ -class EqualNumericBoundsToConst final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - EqualNumericBoundsToConst() - : SchemaTransformRule{ - "equal_numeric_bounds_to_const", - "Setting `minimum` and `maximum` to the same number only leaves " - "one possible value"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any({ - Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - }) && - schema.is_object() && schema.defines("type") && - schema.at("type").is_string() && - (schema.at("type").to_string() == "integer" || - schema.at("type").to_string() == "number") && - schema.defines("minimum") && schema.at("minimum").is_number() && - schema.defines("maximum") && schema.at("maximum").is_number() && - schema.at("minimum") == schema.at("maximum")); - return APPLIES_TO_KEYWORDS("minimum", "maximum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.rename("minimum", "const"); - schema.erase("type"); - schema.erase("maximum"); - } -}; diff --git a/src/extension/alterschema/linter/forbid_empty_enum.h b/src/extension/alterschema/linter/forbid_empty_enum.h deleted file mode 100644 index 279d20f55..000000000 --- a/src/extension/alterschema/linter/forbid_empty_enum.h +++ /dev/null @@ -1,36 +0,0 @@ -class ForbidEmptyEnum final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ForbidEmptyEnum() - : SchemaTransformRule{"forbid_empty_enum", - "An empty `enum` validates nothing and is " - "unsatisfiable"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && !schema.defines("not") && - schema.defines("enum") && schema.at("enum").is_array() && - schema.at("enum").empty()); - ONLY_CONTINUE_IF(!frame.has_references_through(location.pointer)); - return APPLIES_TO_KEYWORDS("enum"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("enum").into(JSON::make_object()); - schema.rename("enum", "not"); - } -}; diff --git a/src/extension/alterschema/linter/incoherent_min_max_contains.h b/src/extension/alterschema/linter/incoherent_min_max_contains.h deleted file mode 100644 index 7ee0a0011..000000000 --- a/src/extension/alterschema/linter/incoherent_min_max_contains.h +++ /dev/null @@ -1,33 +0,0 @@ -class IncoherentMinMaxContains final : public SchemaTransformRule { -public: - using mutates = std::false_type; - using reframe_after_transform = std::false_type; - IncoherentMinMaxContains() - : SchemaTransformRule{ - "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the schema " - "unsatisfiable"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("contains") && - schema.defines("minContains") && - schema.at("minContains").is_integer() && - schema.defines("maxContains") && - schema.at("maxContains").is_integer() && - schema.at("minContains").to_integer() > - schema.at("maxContains").to_integer()); - return APPLIES_TO_KEYWORDS("minContains", "maxContains"); - } -}; diff --git a/src/extension/alterschema/linter/invalid_external_ref.h b/src/extension/alterschema/linter/invalid_external_ref.h deleted file mode 100644 index d0dbcf504..000000000 --- a/src/extension/alterschema/linter/invalid_external_ref.h +++ /dev/null @@ -1,112 +0,0 @@ -class InvalidExternalRef final : public SchemaTransformRule { -public: - using mutates = std::false_type; - using reframe_after_transform = std::false_type; - InvalidExternalRef() - : SchemaTransformRule{ - "invalid_external_ref", - "External references must point to schemas that can be " - "resolved"} {}; - - [[nodiscard]] auto - condition(const JSON &schema, const JSON &, const Vocabularies &vocabularies, - const SchemaFrame &frame, const SchemaFrame::Location &location, - const SchemaWalker &walker, const SchemaResolver &resolver) const - -> SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(!frame.standalone()); - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Core, - Vocabularies::Known::JSON_Schema_2019_09_Core, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_string()); - - auto keyword_pointer{location.pointer}; - keyword_pointer.push_back(std::cref(KEYWORD)); - const auto reference_entry{ - frame.reference(SchemaReferenceType::Static, keyword_pointer)}; - ONLY_CONTINUE_IF(reference_entry.has_value()); - - // If the destination exists in the frame, it is an internal reference - ONLY_CONTINUE_IF( - !frame.traverse(reference_entry->get().destination).has_value()); - - const auto &reference_base{reference_entry->get().base}; - - // Empty base with unresolvable destination is a local reference problem - ONLY_CONTINUE_IF(!reference_base.empty()); - - // Known official metaschemas are always resolvable - ONLY_CONTINUE_IF(!is_known_schema(reference_base)); - - // If the base exists in the frame, the reference is internal (e.g. an - // embedded $id). A bad fragment on an internal base is handled by the - // unknown_local_ref rule instead - ONLY_CONTINUE_IF(!frame.traverse(reference_base).has_value()); - - const auto &has_fragment{reference_entry->get().fragment.has_value()}; - const JSON::String base_key{reference_base}; - - // Check the resolver cache to avoid redundant lookups - const auto cached{this->resolver_cache_.find(base_key)}; - if (cached != this->resolver_cache_.end()) { - if (!cached->second.has_value()) { - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - if (has_fragment) { - return this->is_fragment_invalid(reference_entry->get(), cached->second, - base_key, walker, resolver, location) - ? APPLIES_TO_KEYWORDS(KEYWORD) - : false; - } - - return false; - } - - auto remote{resolver(reference_base)}; - const auto &[entry, - _]{this->resolver_cache_.emplace(base_key, std::move(remote))}; - if (!entry->second.has_value()) { - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - if (has_fragment) { - return this->is_fragment_invalid(reference_entry->get(), entry->second, - base_key, walker, resolver, location) - ? APPLIES_TO_KEYWORDS(KEYWORD) - : false; - } - - return false; - } - -private: - static inline const std::string KEYWORD{"$ref"}; - mutable std::unordered_map> resolver_cache_; - mutable std::unordered_map> - frame_cache_; - - [[nodiscard]] auto - is_fragment_invalid(const SchemaFrame::ReferencesEntry &reference_entry, - const std::optional &remote, - const JSON::String &base_key, const SchemaWalker &walker, - const SchemaResolver &resolver, - const SchemaFrame::Location &location) const -> bool { - auto frame_iterator{this->frame_cache_.find(base_key)}; - if (frame_iterator == this->frame_cache_.end()) { - auto remote_frame{ - std::make_unique(SchemaFrame::Mode::Locations)}; - remote_frame->analyse(remote.value(), walker, resolver, location.dialect, - base_key); - frame_iterator = - this->frame_cache_.emplace(base_key, std::move(remote_frame)).first; - } - - return !frame_iterator->second->traverse(reference_entry.destination) - .has_value(); - } -}; diff --git a/src/extension/alterschema/linter/items_array_default.h b/src/extension/alterschema/linter/items_array_default.h deleted file mode 100644 index 0afbc43af..000000000 --- a/src/extension/alterschema/linter/items_array_default.h +++ /dev/null @@ -1,38 +0,0 @@ -class ItemsArrayDefault final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ItemsArrayDefault() - : SchemaTransformRule{"items_array_default", - "Setting the `items` keyword to the empty array " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_2_Hyper, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_1_Hyper}) && - schema.is_object() && schema.defines("items") && - schema.at("items").is_array() && - schema.at("items").empty()); - return APPLIES_TO_KEYWORDS("items"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("items"); - } -}; diff --git a/src/extension/alterschema/linter/items_schema_default.h b/src/extension/alterschema/linter/items_schema_default.h deleted file mode 100644 index aee24af96..000000000 --- a/src/extension/alterschema/linter/items_schema_default.h +++ /dev/null @@ -1,45 +0,0 @@ -class ItemsSchemaDefault final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"items"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - ItemsSchemaDefault() - : SchemaTransformRule{"items_schema_default", - "Setting the `items` keyword to the true schema " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_2_Hyper, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_1_Hyper}) && - schema.is_object() && schema.defines(KEYWORD) && - ((schema.at(KEYWORD).is_boolean() && schema.at(KEYWORD).to_boolean()) || - (schema.at(KEYWORD).is_object() && schema.at(KEYWORD).empty()))); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/linter/multiple_of_default.h b/src/extension/alterschema/linter/multiple_of_default.h deleted file mode 100644 index 6915657b2..000000000 --- a/src/extension/alterschema/linter/multiple_of_default.h +++ /dev/null @@ -1,39 +0,0 @@ -class MultipleOfDefault final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - MultipleOfDefault() - : SchemaTransformRule{ - "multiple_of_default", - "Setting `multipleOf` to 1 does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("multipleOf") && - ((schema.at("multipleOf").is_integer() && - schema.at("multipleOf").to_integer() == 1) || - (schema.at("multipleOf").is_real() && - schema.at("multipleOf").to_real() == 1.0) || - (schema.at("multipleOf").is_decimal() && - schema.at("multipleOf").to_decimal() == - sourcemeta::core::Decimal{1}))); - return APPLIES_TO_KEYWORDS("multipleOf"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("multipleOf"); - } -}; diff --git a/src/extension/alterschema/linter/pattern_properties_default.h b/src/extension/alterschema/linter/pattern_properties_default.h deleted file mode 100644 index 6decf0eb0..000000000 --- a/src/extension/alterschema/linter/pattern_properties_default.h +++ /dev/null @@ -1,37 +0,0 @@ -class PatternPropertiesDefault final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - PatternPropertiesDefault() - : SchemaTransformRule{ - "pattern_properties_default", - "Setting the `patternProperties` keyword to the empty object " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3}) && - schema.is_object() && - schema.defines("patternProperties") && - schema.at("patternProperties").is_object() && - schema.at("patternProperties").empty()); - return APPLIES_TO_KEYWORDS("patternProperties"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("patternProperties"); - } -}; diff --git a/src/extension/alterschema/linter/properties_default.h b/src/extension/alterschema/linter/properties_default.h deleted file mode 100644 index dd43363be..000000000 --- a/src/extension/alterschema/linter/properties_default.h +++ /dev/null @@ -1,40 +0,0 @@ -class PropertiesDefault final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - PropertiesDefault() - : SchemaTransformRule{ - "properties_default", - "Setting the `properties` keyword to the empty object " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_2_Hyper, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_1_Hyper}) && - schema.is_object() && schema.defines("properties") && - schema.at("properties").is_object() && - schema.at("properties").empty()); - return APPLIES_TO_KEYWORDS("properties"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("properties"); - } -}; diff --git a/src/extension/alterschema/linter/property_names_default.h b/src/extension/alterschema/linter/property_names_default.h deleted file mode 100644 index 479ca0961..000000000 --- a/src/extension/alterschema/linter/property_names_default.h +++ /dev/null @@ -1,39 +0,0 @@ -class PropertyNamesDefault final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"propertyNames"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - PropertyNamesDefault() - : SchemaTransformRule{ - "property_names_default", - "Setting the `propertyNames` keyword to the empty object " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines(KEYWORD) && - schema.at(KEYWORD).is_object() && - schema.at(KEYWORD).empty()); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/linter/property_names_type_default.h b/src/extension/alterschema/linter/property_names_type_default.h deleted file mode 100644 index 4ced15cfa..000000000 --- a/src/extension/alterschema/linter/property_names_type_default.h +++ /dev/null @@ -1,43 +0,0 @@ -class PropertyNamesTypeDefault final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - PropertyNamesTypeDefault() - : SchemaTransformRule{ - "property_names_type_default", - "Setting the `type` keyword to `string` inside " - "`propertyNames` does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6}) && - schema.is_object() && schema.defines("propertyNames") && - schema.at("propertyNames").is_object() && - schema.at("propertyNames").defines("type") && - ((schema.at("propertyNames").at("type").is_string() && - schema.at("propertyNames").at("type").to_string() == "string") || - (schema.at("propertyNames").at("type").is_array() && - std::all_of(schema.at("propertyNames").at("type").as_array().begin(), - schema.at("propertyNames").at("type").as_array().end(), - [](const auto &item) { - return item.is_string() && item.to_string() == "string"; - })))); - return APPLIES_TO_POINTERS({{"propertyNames", "type"}}); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("propertyNames").erase("type"); - } -}; diff --git a/src/extension/alterschema/linter/simple_properties_identifiers.h b/src/extension/alterschema/linter/simple_properties_identifiers.h deleted file mode 100644 index 7f4f30d98..000000000 --- a/src/extension/alterschema/linter/simple_properties_identifiers.h +++ /dev/null @@ -1,69 +0,0 @@ -class SimplePropertiesIdentifiers final : public SchemaTransformRule { -public: - using mutates = std::false_type; - using reframe_after_transform = std::false_type; - SimplePropertiesIdentifiers() - // Inspired by - // https://json-structure.github.io/core/draft-vasters-json-structure-core.html#section-3.6 - : SchemaTransformRule{ - "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily mapped to " - "programming languages (matching [A-Za-z_][A-Za-z0-9_]*)"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &root, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Applicator, - Vocabularies::Known::JSON_Schema_2019_09_Applicator, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_2_Hyper, - Vocabularies::Known::JSON_Schema_Draft_1, - Vocabularies::Known::JSON_Schema_Draft_1_Hyper})); - ONLY_CONTINUE_IF(schema.is_object() && schema.defines("properties") && - schema.at("properties").is_object() && - !schema.at("properties").empty()); - - if (vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Core, - Vocabularies::Known::JSON_Schema_2019_09_Core})) { - // Skip meta-schemas with `$vocabulary` (2019-09+) - // We check the current schema resource (not root) to handle bundled - // schemas - const auto base_location{frame.traverse(location.base)}; - if (base_location.has_value()) { - const auto &resource{get(root, base_location->get().pointer)}; - ONLY_CONTINUE_IF(!resource.is_object() || - !resource.defines("$vocabulary")); - } - } else { - // Skip pre-vocabulary meta-schemas - JSON::String base_with_hash{location.base}; - base_with_hash += '#'; - ONLY_CONTINUE_IF(location.base != location.dialect && - base_with_hash != location.dialect); - } - - std::vector offenders; - for (const auto &entry : schema.at("properties").as_object()) { - static const Regex IDENTIFIER_PATTERN{ - to_regex("^[A-Za-z_][A-Za-z0-9_]*$").value()}; - if (!matches(IDENTIFIER_PATTERN, entry.first)) { - offenders.push_back(Pointer{"properties", entry.first}); - } - } - - ONLY_CONTINUE_IF(!offenders.empty()); - return APPLIES_TO_POINTERS(std::move(offenders)); - } -}; diff --git a/src/extension/alterschema/linter/title_description_equal.h b/src/extension/alterschema/linter/title_description_equal.h deleted file mode 100644 index 01320ba76..000000000 --- a/src/extension/alterschema/linter/title_description_equal.h +++ /dev/null @@ -1,40 +0,0 @@ -class TitleDescriptionEqual final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - TitleDescriptionEqual() - : SchemaTransformRule{ - "title_description_equal", - "The title and description metadata keywords should not be set to " - "the same value"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object()); - ONLY_CONTINUE_IF(schema.defines("title") && schema.defines("description")); - ONLY_CONTINUE_IF(schema.at("title").is_string() && - schema.at("description").is_string()); - ONLY_CONTINUE_IF(schema.at("title") == schema.at("description")); - return APPLIES_TO_KEYWORDS("title", "description"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("description"); - } -}; diff --git a/src/extension/alterschema/linter/title_trailing_period.h b/src/extension/alterschema/linter/title_trailing_period.h deleted file mode 100644 index bf7b9ad2e..000000000 --- a/src/extension/alterschema/linter/title_trailing_period.h +++ /dev/null @@ -1,46 +0,0 @@ -class TitleTrailingPeriod final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - TitleTrailingPeriod() - : SchemaTransformRule{ - "title_trailing_period", - "Titles should not end with a period to give user interfaces " - "flexibility in presenting the text"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object()); - ONLY_CONTINUE_IF(schema.defines("title")); - ONLY_CONTINUE_IF(schema.at("title").is_string()); - const auto &title{schema.at("title").to_string()}; - ONLY_CONTINUE_IF(!title.empty() && title.back() == '.'); - return APPLIES_TO_KEYWORDS("title"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - auto &title{schema.at("title")}; - auto value{title.to_string()}; - while (!value.empty() && value.back() == '.') { - value.pop_back(); - } - - title.into(JSON{value}); - } -}; diff --git a/src/extension/alterschema/linter/title_trim.h b/src/extension/alterschema/linter/title_trim.h deleted file mode 100644 index 3846fc307..000000000 --- a/src/extension/alterschema/linter/title_trim.h +++ /dev/null @@ -1,38 +0,0 @@ -class TitleTrim final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::false_type; - TitleTrim() - : SchemaTransformRule{ - "title_trim", - "Titles should not contain leading or trailing whitespace"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object()); - ONLY_CONTINUE_IF(schema.defines("title")); - ONLY_CONTINUE_IF(schema.at("title").is_string()); - ONLY_CONTINUE_IF(!schema.at("title").is_trimmed()); - return APPLIES_TO_KEYWORDS("title"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.at("title").trim(); - } -}; diff --git a/src/extension/alterschema/linter/top_level_description.h b/src/extension/alterschema/linter/top_level_description.h deleted file mode 100644 index d1da3562a..000000000 --- a/src/extension/alterschema/linter/top_level_description.h +++ /dev/null @@ -1,38 +0,0 @@ -class TopLevelDescription final : public SchemaTransformRule { -public: - using mutates = std::false_type; - using reframe_after_transform = std::false_type; - TopLevelDescription() - : SchemaTransformRule{ - "top_level_description", - "Set a non-empty description at the top level of the " - "schema to explain what the definition is about in detail"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(location.pointer.empty()); - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object()); - if (schema.defines("description") && schema.at("description").is_string() && - schema.at("description").empty()) { - return APPLIES_TO_KEYWORDS("description"); - } else { - return !schema.defines("description"); - } - } -}; diff --git a/src/extension/alterschema/linter/top_level_examples.h b/src/extension/alterschema/linter/top_level_examples.h deleted file mode 100644 index c92c407bd..000000000 --- a/src/extension/alterschema/linter/top_level_examples.h +++ /dev/null @@ -1,34 +0,0 @@ -class TopLevelExamples final : public SchemaTransformRule { -public: - using mutates = std::false_type; - using reframe_after_transform = std::false_type; - TopLevelExamples() - : SchemaTransformRule{ - "top_level_examples", - "Set a non-empty examples array at the top level of the schema to " - "illustrate the expected data"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(location.pointer.empty()); - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6})); - ONLY_CONTINUE_IF(schema.is_object()); - if (schema.defines("examples") && schema.at("examples").is_array() && - schema.at("examples").empty()) { - return APPLIES_TO_KEYWORDS("examples"); - } else { - return !schema.defines("examples"); - } - } -}; diff --git a/src/extension/alterschema/linter/top_level_title.h b/src/extension/alterschema/linter/top_level_title.h deleted file mode 100644 index cc7fa2cfb..000000000 --- a/src/extension/alterschema/linter/top_level_title.h +++ /dev/null @@ -1,38 +0,0 @@ -class TopLevelTitle final : public SchemaTransformRule { -public: - using mutates = std::false_type; - using reframe_after_transform = std::false_type; - TopLevelTitle() - : SchemaTransformRule{ - "top_level_title", - "Set a concise non-empty title at the top level of the " - "schema to explain what the definition is about"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF(location.pointer.empty()); - ONLY_CONTINUE_IF(vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Meta_Data, - Vocabularies::Known::JSON_Schema_2019_09_Meta_Data, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4, - Vocabularies::Known::JSON_Schema_Draft_3, - Vocabularies::Known::JSON_Schema_Draft_2, - Vocabularies::Known::JSON_Schema_Draft_1})); - ONLY_CONTINUE_IF(schema.is_object()); - if (schema.defines("title") && schema.at("title").is_string() && - schema.at("title").empty()) { - return APPLIES_TO_KEYWORDS("title"); - } else { - return !schema.defines("title"); - } - } -}; diff --git a/src/extension/alterschema/linter/unevaluated_items_default.h b/src/extension/alterschema/linter/unevaluated_items_default.h deleted file mode 100644 index 6ce4570ed..000000000 --- a/src/extension/alterschema/linter/unevaluated_items_default.h +++ /dev/null @@ -1,38 +0,0 @@ -class UnevaluatedItemsDefault final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"unevaluatedItems"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnevaluatedItemsDefault() - : SchemaTransformRule{ - "unevaluated_items_default", - "Setting the `unevaluatedItems` keyword to the true schema " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Unevaluated, - Vocabularies::Known::JSON_Schema_2019_09_Applicator}) && - schema.is_object() && schema.defines(KEYWORD) && - ((schema.at(KEYWORD).is_boolean() && schema.at(KEYWORD).to_boolean()) || - (schema.at(KEYWORD).is_object() && schema.at(KEYWORD).empty()))); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/linter/unevaluated_properties_default.h b/src/extension/alterschema/linter/unevaluated_properties_default.h deleted file mode 100644 index b7fff5b0d..000000000 --- a/src/extension/alterschema/linter/unevaluated_properties_default.h +++ /dev/null @@ -1,38 +0,0 @@ -class UnevaluatedPropertiesDefault final : public SchemaTransformRule { -private: - static inline const std::string KEYWORD{"unevaluatedProperties"}; - -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnevaluatedPropertiesDefault() - : SchemaTransformRule{ - "unevaluated_properties_default", - "Setting the `unevaluatedProperties` keyword to the true schema " - "does not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &frame, - const sourcemeta::core::SchemaFrame::Location &location, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Unevaluated, - Vocabularies::Known::JSON_Schema_2019_09_Applicator}) && - schema.is_object() && schema.defines(KEYWORD) && - ((schema.at(KEYWORD).is_boolean() && schema.at(KEYWORD).to_boolean()) || - (schema.at(KEYWORD).is_object() && schema.at(KEYWORD).empty()))); - ONLY_CONTINUE_IF(!frame.has_references_through( - location.pointer, WeakPointer::Token{std::cref(KEYWORD)})); - return APPLIES_TO_KEYWORDS(KEYWORD); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase(KEYWORD); - } -}; diff --git a/src/extension/alterschema/linter/unsatisfiable_max_contains.h b/src/extension/alterschema/linter/unsatisfiable_max_contains.h deleted file mode 100644 index 6ff7c0fe7..000000000 --- a/src/extension/alterschema/linter/unsatisfiable_max_contains.h +++ /dev/null @@ -1,36 +0,0 @@ -class UnsatisfiableMaxContains final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnsatisfiableMaxContains() - : SchemaTransformRule{ - "unsatisfiable_max_contains", - "Setting the `maxContains` keyword to a number greater than or " - "equal to the array upper bound does not add any further " - "constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation}) && - schema.is_object() && schema.defines("maxContains") && - schema.at("maxContains").is_integer() && schema.defines("maxItems") && - schema.at("maxItems").is_integer() && - schema.at("maxContains").to_integer() >= - schema.at("maxItems").to_integer()); - return APPLIES_TO_KEYWORDS("maxContains", "maxItems"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("maxContains"); - } -}; diff --git a/src/extension/alterschema/linter/unsatisfiable_min_properties.h b/src/extension/alterschema/linter/unsatisfiable_min_properties.h deleted file mode 100644 index 30c72c7fc..000000000 --- a/src/extension/alterschema/linter/unsatisfiable_min_properties.h +++ /dev/null @@ -1,39 +0,0 @@ -class UnsatisfiableMinProperties final : public SchemaTransformRule { -public: - using mutates = std::true_type; - using reframe_after_transform = std::true_type; - UnsatisfiableMinProperties() - : SchemaTransformRule{ - "unsatisfiable_min_properties", - "Setting `minProperties` to a number less than `required` does " - "not add any further constraint"} {}; - - [[nodiscard]] auto - condition(const sourcemeta::core::JSON &schema, - const sourcemeta::core::JSON &, - const sourcemeta::core::Vocabularies &vocabularies, - const sourcemeta::core::SchemaFrame &, - const sourcemeta::core::SchemaFrame::Location &, - const sourcemeta::core::SchemaWalker &, - const sourcemeta::core::SchemaResolver &) const - -> sourcemeta::core::SchemaTransformRule::Result override { - ONLY_CONTINUE_IF( - vocabularies.contains_any( - {Vocabularies::Known::JSON_Schema_2020_12_Validation, - Vocabularies::Known::JSON_Schema_2019_09_Validation, - Vocabularies::Known::JSON_Schema_Draft_7, - Vocabularies::Known::JSON_Schema_Draft_6, - Vocabularies::Known::JSON_Schema_Draft_4}) && - schema.is_object() && schema.defines("minProperties") && - schema.at("minProperties").is_integer() && schema.defines("required") && - schema.at("required").is_array() && schema.at("required").unique() && - std::cmp_greater_equal(schema.at("required").size(), - static_cast( - schema.at("minProperties").to_integer()))); - return APPLIES_TO_KEYWORDS("minProperties", "required"); - } - - auto transform(JSON &schema, const Result &) const -> void override { - schema.erase("minProperties"); - } -}; diff --git a/test/alterschema/CMakeLists.txt b/test/alterschema/CMakeLists.txt deleted file mode 100644 index d6e09f7fa..000000000 --- a/test/alterschema/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -sourcemeta_googletest(NAMESPACE sourcemeta PROJECT core NAME alterschema - SOURCES - alterschema_canonicalize_2020_12_test.cc - alterschema_canonicalize_2019_09_test.cc - alterschema_canonicalize_draft7_test.cc - alterschema_canonicalize_draft6_test.cc - alterschema_canonicalize_draft4_test.cc - alterschema_canonicalize_draft3_test.cc - alterschema_canonicalize_draft2_test.cc - alterschema_canonicalize_draft1_test.cc - alterschema_canonicalize_draft0_test.cc - alterschema_lint_2020_12_test.cc - alterschema_lint_2019_09_test.cc - alterschema_lint_draft7_test.cc - alterschema_lint_draft6_test.cc - alterschema_lint_draft4_test.cc - alterschema_lint_draft3_test.cc - alterschema_lint_draft2_test.cc - alterschema_lint_draft1_test.cc - alterschema_lint_draft0_test.cc - alterschema_lint_openapi_test.cc - alterschema_test_utils.h) - -target_link_libraries(sourcemeta_core_alterschema_unit - PRIVATE sourcemeta::core::json) -target_link_libraries(sourcemeta_core_alterschema_unit - PRIVATE sourcemeta::core::jsonschema) -target_link_libraries(sourcemeta_core_alterschema_unit - PRIVATE sourcemeta::core::alterschema) - -sourcemeta_executable(NAMESPACE sourcemeta PROJECT core - NAME alterschema_canonicalize - SOURCES alterschema_canonicalize.cc) -target_link_libraries(sourcemeta_core_alterschema_canonicalize - PRIVATE sourcemeta::core::json) -target_link_libraries(sourcemeta_core_alterschema_canonicalize - PRIVATE sourcemeta::core::jsonschema) -target_link_libraries(sourcemeta_core_alterschema_canonicalize - PRIVATE sourcemeta::core::alterschema) diff --git a/test/alterschema/alterschema_canonicalize.cc b/test/alterschema/alterschema_canonicalize.cc deleted file mode 100644 index 21830ce47..000000000 --- a/test/alterschema/alterschema_canonicalize.cc +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include // EXIT_SUCCESS, EXIT_FAILURE -#include // std::cerr, std::cout - -auto main(int argc, char *argv[]) -> int { - if (argc != 2) { - std::cerr << "Usage: " << argv[0] << " \n"; - return EXIT_FAILURE; - } - - auto document{sourcemeta::core::read_json(argv[1])}; - - sourcemeta::core::SchemaTransformer bundle; - sourcemeta::core::add(bundle, - sourcemeta::core::AlterSchemaMode::Canonicalizer); - const auto result{ - bundle.apply(document, sourcemeta::core::schema_walker, - sourcemeta::core::schema_resolver, - [](const auto &pointer, const auto &name, - const auto &message, const auto &, const auto &) { - std::cerr << sourcemeta::core::to_string(pointer) << ": " - << name << ": " << message << "\n"; - })}; - - sourcemeta::core::format(document, sourcemeta::core::schema_walker, - sourcemeta::core::schema_resolver); - sourcemeta::core::prettify(document, std::cout); - std::cout << "\n"; - - return result.first ? EXIT_SUCCESS : EXIT_FAILURE; -} diff --git a/test/alterschema/alterschema_canonicalize_2019_09_test.cc b/test/alterschema/alterschema_canonicalize_2019_09_test.cc deleted file mode 100644 index b9facefef..000000000 --- a/test/alterschema/alterschema_canonicalize_2019_09_test.cc +++ /dev/null @@ -1,594 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_2019_09, duplicate_allof_branches_2) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, duplicate_allof_branches_3) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "type": "number" }, - { "type": "number" }, - { "type": "string" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, duplicate_allof_branches_4) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" }, - { "type": "number" }, - { "type": "string" }, - { "type": "string" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, const_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_maximum_integer_to_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 1, - "maximum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_maximum_integer_to_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMaximum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 1, - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_maximum_integer_to_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_maximum_integer_to_maximum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMaximum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_minimum_integer_to_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_minimum_integer_to_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMinimum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_minimum_integer_to_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, exclusive_minimum_integer_to_minimum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMinimum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { - "type": "object", - "properties": { - "foo": true - }, - "minProperties": 0 - }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, max_contains_covered_by_max_items_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "string" }, - "maxContains": 2, - "maxItems": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { - "type": "string", - "minLength": 0 - }, - "maxContains": 1, - "minItems": 0, - "maxItems": 1, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, min_properties_covered_by_required_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "minProperties": 1, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, min_properties_implicit_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, min_properties_implicit_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, min_items_given_min_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "boolean" }, - "minContains": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "enum": [ false, true ] }, - "minContains": 3, - "minItems": 3, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, min_items_given_min_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "minContains": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "minItems": 0, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, - exclusive_maximum_integer_to_maximum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMaximum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 1, - "maximum": 10.00000000000000e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, - exclusive_minimum_integer_to_minimum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMinimum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 1, - "minimum": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2019_09, items_implicit_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "minItems": 0, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_2020_12_test.cc b/test/alterschema/alterschema_canonicalize_2020_12_test.cc deleted file mode 100644 index 26ef16404..000000000 --- a/test/alterschema/alterschema_canonicalize_2020_12_test.cc +++ /dev/null @@ -1,1330 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_2020_12, duplicate_allof_branches_2) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, duplicate_allof_branches_3) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "number" }, - { "type": "number" }, - { "type": "string" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, duplicate_allof_branches_4) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" }, - { "type": "number" }, - { "type": "string" }, - { "type": "string" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, allof_false_simplify_preserves_id) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schema", - "type": "string", - "allOf": [ false ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, allof_false_simplify_preserves_anchor) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$anchor": "myanchor", - "type": "string", - "allOf": [ false ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$anchor": "myanchor", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, allof_false_simplify_removes_defs) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "allOf": [ false ], - "$defs": { - "foo": { "type": "number" } - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, duplicate_allof_branches_5) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "multipleOf": 2, - "allOf": [ - { "type": "number", "multipleOf": 1 } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "multipleOf": 2, - "type": "number", - "anyOf": [ - { "type": "number", "multipleOf": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, dependent_required_tautology_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "required": [ "foo" ], - "dependentRequired": { - "foo": [ "bar" ], - "bar": [ "baz" ] - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "required": [ "foo", "bar", "baz" ], - "dependentRequired": {}, - "properties": { - "foo": true, - "bar": true, - "baz": true - }, - "minProperties": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, const_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_maximum_integer_to_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": 1, - "maximum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_maximum_integer_to_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMaximum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": 1, - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_maximum_integer_to_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_maximum_integer_to_maximum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMaximum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_minimum_integer_to_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_minimum_integer_to_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMinimum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_minimum_integer_to_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, exclusive_minimum_integer_to_minimum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMinimum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { - "type": "object", - "properties": { - "foo": true - }, - "minProperties": 0 - }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_array_to_any_of_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$anchor": "foo", - "type": [ "integer", "number", "string" ], - "minimum": 5 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$anchor": "foo", - "anyOf": [ - { "type": "integer", "minimum": 5, "multipleOf": 1 }, - { "type": "number", "minimum": 5 }, - { "type": "string", "minLength": 0 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_array_to_any_of_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "integer", "number", "string" ], - "anyOf": [ - { "minimum": 4, "type": "integer" }, - { "maximum": 8, "type": "integer" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "integer", "multipleOf": 1 }, - { "type": "number" }, - { "type": "string", "minLength": 0 } - ], - "allOf": [ - { - "anyOf": [ - { "minimum": 4, "type": "integer", "multipleOf": 1 }, - { "maximum": 8, "type": "integer", "multipleOf": 1 } - ] - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_array_to_any_of_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "object", "array", "string" ], - "additionalProperties": { - "$anchor": "foo", - "type": "string" - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "type": "object", - "properties": {}, - "minProperties": 0, - "additionalProperties": { - "$anchor": "foo", - "type": "string", - "minLength": 0 - } - }, - { - "type": "array", - "minItems": 0, - "items": true - }, - { - "type": "string", - "minLength": 0 - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_array_to_any_of_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "object", "array" ], - "$ref": "#/$defs/foo", - "$defs": { - "foo": { - "type": "string", - "minLength": 0 - } - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { - "type": "object", - "properties": {}, - "minProperties": 0 - }, - { - "type": "array", - "minItems": 0, - "items": true - } - ], - "$ref": "#/$defs/foo", - "$defs": { - "foo": { - "type": "string", - "minLength": 0 - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, type_array_to_any_of_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "string", "number" ], - "anyOf": [ - { "minLength": 1 }, - { "minimum": 0 } - ], - "allOf": [ - { "title": "My schema" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "anyOf": [ - { "type": "string", "minLength": 0 }, - { "type": "number" } - ], - "allOf": [ - { - "anyOf": [ - { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "type": "object", "minProperties": 0, "properties": {} }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 1 }, - { "type": "number" } - ] - }, - { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "type": "object", "minProperties": 0, "properties": {} }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number", "minimum": 0 } - ] - } - ] - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, max_contains_covered_by_max_items_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "string" }, - "maxContains": 2, - "maxItems": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { - "type": "string", - "minLength": 0 - }, - "maxContains": 1, - "minItems": 0, - "maxItems": 1, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, min_properties_covered_by_required_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "minProperties": 1, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, min_properties_implicit_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, min_properties_implicit_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, min_items_given_min_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "boolean" }, - "minContains": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "enum": [ false, true ] }, - "minContains": 3, - "minItems": 3, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, min_items_given_min_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "minContains": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "minItems": 0, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, - exclusive_maximum_integer_to_maximum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMaximum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": 1, - "maximum": 10.00000000000000e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, - exclusive_minimum_integer_to_minimum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMinimum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": 1, - "minimum": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, circular_ref_through_defs_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "a": { "$ref": "#/$defs/b" }, - "b": { "$ref": "#/$defs/a" } - }, - "$ref": "#/$defs/a" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "a": { "$ref": "#/$defs/b" }, - "b": { "$ref": "#/$defs/a" } - }, - "$ref": "#/$defs/a" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, conflicting_type_and_const_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "const": 42 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "enum": [ 42 ], - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, conflicting_type_and_enum_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "enum": [ 1, 2, 3 ], - "minLength": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, allof_two_required_branches_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "allOf": [ - { "required": [ "a" ] }, - { "required": [ "b" ] } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "required": [ "b" ], - "anyOf": [ - { - "type": "object", - "required": [ "a" ], - "properties": { - "a": true - }, - "minProperties": 1 - } - ], - "minProperties": 1, - "properties": { - "b": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, allof_min_max_constraints_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "integer", "minimum": 0 }, - { "maximum": 100 } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "maximum": 100, - "minimum": 0, - "multipleOf": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, allof_two_properties_branches_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "allOf": [ - { "properties": { "a": {} } }, - { "properties": { "b": {} } } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "anyOf": [ - { - "type": "object", - "properties": { - "a": { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "type": "object", "minProperties": 0, "properties": {} }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - } - }, - "minProperties": 0 - } - ], - "allOf": [ - { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { - "type": "object", - "properties": { - "b": { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "type": "object", "minProperties": 0, "properties": {} }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - } - }, - "minProperties": 0 - }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - } - ], - "minProperties": 0, - "properties": {} - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, - type_union_implicit_with_content_schema) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentMediaType": "application/json", - "contentEncoding": "base64", - "contentSchema": { "type": "object" } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "type": "object", "minProperties": 0, "properties": {} }, - { "type": "array", "minItems": 0, "items": true }, - { - "type": "string", - "contentSchema": { - "type": "object", - "minProperties": 0, - "properties": {} - }, - "contentEncoding": "base64", - "contentMediaType": "application/json", - "minLength": 0 - }, - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, - unsatisfiable_logic_branch_type_anyof_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "anyOf": [ - { "type": "number" }, - { "minLength": 1 } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0, - "anyOf": [ - { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "type": "object", "minProperties": 0, "properties": {} }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 1 }, - { "type": "number" } - ] - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, - unsatisfiable_logic_branch_type_oneof_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "oneOf": [ - { "type": "string" }, - { "minimum": 0 } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "oneOf": [ - false, - { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "type": "object", "minProperties": 0, "properties": {} }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number", "minimum": 0 } - ] - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, - unsatisfiable_logic_branch_type_if_then_else_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "if": { "type": "number" }, - "then": { "type": "array" }, - "else": { "type": "object" } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 0, - "if": false, - "then": false, - "else": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, - allof_two_properties_branches_with_typed_values_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "allOf": [ - { - "properties": { - "name": { "type": "string" } - } - }, - { - "properties": { - "age": { "type": "integer" } - } - } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "anyOf": [ - { - "type": "object", - "properties": { - "name": { "type": "string", "minLength": 0 } - }, - "minProperties": 0 - } - ], - "allOf": [ - { - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { - "type": "object", - "properties": { - "age": { "type": "integer", "multipleOf": 1 } - }, - "minProperties": 0 - }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - } - ], - "minProperties": 0, - "properties": {} - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, items_implicit_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "minItems": 0, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_2020_12, items_implicit_2) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "items": { "type": "string" } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "minItems": 0, - "items": { "type": "string", "minLength": 0 } - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_draft0_test.cc b/test/alterschema/alterschema_canonicalize_draft0_test.cc deleted file mode 100644 index 86295954a..000000000 --- a/test/alterschema/alterschema_canonicalize_draft0_test.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_draft0, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": [ "null", "boolean", "object", "array", "string", "number" ], - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_draft1_test.cc b/test/alterschema/alterschema_canonicalize_draft1_test.cc deleted file mode 100644 index 95fe3eb7d..000000000 --- a/test/alterschema/alterschema_canonicalize_draft1_test.cc +++ /dev/null @@ -1,124 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_draft1, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft1, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft1, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft1, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft1, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": [ "null", "boolean", "object", "array", "string", "number" ], - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft1, equal_numeric_bounds_to_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_draft2_test.cc b/test/alterschema/alterschema_canonicalize_draft2_test.cc deleted file mode 100644 index bf489cf27..000000000 --- a/test/alterschema/alterschema_canonicalize_draft2_test.cc +++ /dev/null @@ -1,124 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_draft2, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft2, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft2, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft2, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft2, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": [ "null", "boolean", "object", "array", "string", "number" ], - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft2, equal_numeric_bounds_to_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_draft3_test.cc b/test/alterschema/alterschema_canonicalize_draft3_test.cc deleted file mode 100644 index b01d9adea..000000000 --- a/test/alterschema/alterschema_canonicalize_draft3_test.cc +++ /dev/null @@ -1,124 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_draft3, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft3, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft3, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft3, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft3, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": [ "null", "boolean", "object", "array", "string", "number" ], - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft3, equal_numeric_bounds_to_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_draft4_test.cc b/test/alterschema/alterschema_canonicalize_draft4_test.cc deleted file mode 100644 index 851c7f752..000000000 --- a/test/alterschema/alterschema_canonicalize_draft4_test.cc +++ /dev/null @@ -1,290 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_draft4, duplicate_allof_branches_2) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "minLength": 0, - "allOf": [ false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, duplicate_allof_branches_3) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "type": "number" }, - { "type": "number" }, - { "type": "string" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "minLength": 0, - "allOf": [ false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, duplicate_allof_branches_4) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" }, - { "type": "number" }, - { "type": "string" }, - { "type": "string" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "minLength": 0, - "allOf": [ false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { - "type": "object", - "properties": { - "foo": true - }, - "minProperties": 0 - }, - { "type": "array", "minItems": 0 }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, min_properties_covered_by_required_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "minProperties": 1, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, min_properties_implicit_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "required": [ "foo", "bar" ], - "minProperties": 2, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, min_properties_implicit_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "required": [ "foo", "bar" ], - "minProperties": 2, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft4, equal_numeric_bounds_to_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_draft6_test.cc b/test/alterschema/alterschema_canonicalize_draft6_test.cc deleted file mode 100644 index 2c7d3604a..000000000 --- a/test/alterschema/alterschema_canonicalize_draft6_test.cc +++ /dev/null @@ -1,520 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_draft6, duplicate_allof_branches_2) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, duplicate_allof_branches_3) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "type": "number" }, - { "type": "number" }, - { "type": "string" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, duplicate_allof_branches_4) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" }, - { "type": "number" }, - { "type": "string" }, - { "type": "string" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, const_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_maximum_integer_to_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "multipleOf": 1, - "maximum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_maximum_integer_to_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMaximum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "multipleOf": 1, - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_maximum_integer_to_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_maximum_integer_to_maximum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMaximum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_minimum_integer_to_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_minimum_integer_to_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMinimum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_minimum_integer_to_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, exclusive_minimum_integer_to_minimum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMinimum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { - "type": "object", - "properties": { - "foo": true - }, - "minProperties": 0 - }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, min_properties_covered_by_required_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "minProperties": 1, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, min_properties_implicit_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, min_properties_implicit_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, - exclusive_maximum_integer_to_maximum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMaximum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "multipleOf": 1, - "maximum": 10.00000000000000e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, - exclusive_minimum_integer_to_minimum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMinimum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "multipleOf": 1, - "minimum": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft6, items_implicit_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "array" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "array", - "minItems": 0, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_canonicalize_draft7_test.cc b/test/alterschema/alterschema_canonicalize_draft7_test.cc deleted file mode 100644 index f25da187d..000000000 --- a/test/alterschema/alterschema_canonicalize_draft7_test.cc +++ /dev/null @@ -1,564 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_canonicalize_draft7, duplicate_allof_branches_2) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, duplicate_allof_branches_3) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "type": "number" }, - { "type": "number" }, - { "type": "string" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, duplicate_allof_branches_4) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "type": "number" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" }, - { "type": "number" }, - { "type": "string" }, - { "type": "string" }, - { "type": "string" }, - { "type": "number" }, - { "type": "number" } - ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, type_boolean_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "boolean" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ false, true ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, type_boolean_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "boolean", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, type_null_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "null" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, type_null_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "null", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, const_as_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_maximum_integer_to_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "maximum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_maximum_integer_to_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMaximum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_maximum_integer_to_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "number", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_maximum_integer_to_maximum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMaximum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMaximum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_minimum_integer_to_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_minimum_integer_to_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMinimum": 1.2 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "minimum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_minimum_integer_to_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "number", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, exclusive_minimum_integer_to_minimum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMinimum": 1 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { "properties": {}, "minProperties": 0, "type": "object" }, - { "minItems": 0, "type": "array", "items": true }, - { "minLength": 0, "type": "string" }, - { "type": "number", "exclusiveMinimum": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, - exclusive_maximum_integer_to_maximum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMaximum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "maximum": 10.00000000000000e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, - exclusive_maximum_integer_to_maximum_decimal_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMaximum": 9.99999999999999999999999999999e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "maximum": 100.0000000000000e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, - exclusive_minimum_integer_to_minimum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMinimum": 1.0e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "minimum": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, - exclusive_minimum_integer_to_minimum_decimal_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMinimum": 9.99999999999999999999999999999e400 - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1, - "minimum": 1.0e+401 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, boolean_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "foo": true - } - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ - { "enum": [ null ] }, - { "enum": [ false, true ] }, - { - "type": "object", - "properties": { - "foo": true - }, - "minProperties": 0 - }, - { "type": "array", "minItems": 0, "items": true }, - { "type": "string", "minLength": 0 }, - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, min_properties_covered_by_required_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "minProperties": 1, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, min_properties_implicit_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, min_properties_implicit_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "minProperties": 2, - "required": [ "foo", "bar" ] - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - }, - "minProperties": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_canonicalize_draft7, items_implicit_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "array" - })JSON"); - - CANONICALIZE(document, result, traces); - - EXPECT_TRUE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "array", - "minItems": 0, - "items": true - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_2019_09_test.cc b/test/alterschema/alterschema_lint_2019_09_test.cc deleted file mode 100644 index e3ef2ef9c..000000000 --- a/test/alterschema/alterschema_lint_2019_09_test.cc +++ /dev/null @@ -1,5094 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_2019_09, local_ref_to_unknown_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, local_ref_to_unknown_location_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, local_ref_to_unknown_anchor) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - local_ref_to_unknown_location_with_nested_resource_relative) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "foo#/$defs/foo", - "additionalProperties": { "$id": "foo" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "additionalProperties": { "$id": "foo" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - local_ref_to_unknown_location_with_nested_resource_relative_valid) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - local_ref_to_unknown_location_with_nested_resource_absolute) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://www.example.com/foo#/$defs/foo", - "additionalProperties": { "$id": "foo" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "additionalProperties": { "$id": "foo" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - local_ref_to_unknown_location_with_nested_resource_absolute_valid) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://www.example.com/foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://www.example.com/foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, nested_ref_to_unknown_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "$ref": "#/$defs/bar" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, nested_ref_to_existing_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "bar": { "type": "string" } - }, - "properties": { - "foo": { - "$ref": "#/$defs/bar" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "bar": { "type": "string" } - }, - "properties": { - "foo": { - "$ref": "#/$defs/bar" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, deeply_nested_ref_to_unknown_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "items": { - "properties": { - "bar": { - "$ref": "#/$defs/baz" - } - } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "items": { - "properties": { - "bar": true - } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, nested_ref_to_unknown_anchor) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { - "$ref": "#unknownAnchor" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, nested_ref_to_existing_anchor) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "myDef": { - "$anchor": "myAnchor", - "type": "number" - } - }, - "properties": { - "value": { - "$ref": "#myAnchor" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "myDef": { - "$anchor": "myAnchor", - "type": "number" - } - }, - "properties": { - "value": { - "$ref": "#myAnchor" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, mixed_nested_refs_valid_and_invalid) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "string": { "type": "string" } - }, - "properties": { - "name": { - "$ref": "#/$defs/string" - }, - "age": { - "$ref": "#/$defs/number" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "string": { "type": "string" } - }, - "properties": { - "name": { - "$ref": "#/$defs/string" - }, - "age": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, external_ref_with_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "$ref": "https://example.com/schema#/$defs/bar" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "$ref": "https://example.com/schema#/$defs/bar" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, external_ref_with_unknown_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://json-schema.org/draft/2019-09/schema#/$defs/nonNegativeInteger" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://json-schema.org/draft/2019-09/schema#/$defs/nonNegativeInteger" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, nested_external_ref_with_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com/base-schema#/$defs/common", - "properties": { - "value": { - "$ref": "http://another-example.com/types#/definitions/string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com/base-schema#/$defs/common", - "properties": { - "value": { - "$ref": "http://another-example.com/types#/definitions/string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - external_relative_ref_with_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com/my-schema", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "data": { - "$ref": "common-types.json#/$defs/uuid" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com/my-schema", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "data": { - "$ref": "common-types.json#/$defs/uuid" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, enum_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, const_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, const_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": [ "string", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, const_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, const_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ "foo", "bar" ], - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, 2, 3 ], - "minLength": 0, - "maxLength": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ { "a": 1 }, { "b": 2 } ], - "minLength": 3, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ { "a": 1 }, { "b": 2 } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/schema", - "$anchor": "color-enum", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "$comment": "This schema uses enum with various annotation keywords", - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2, - "minProperties": 1, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/schema", - "$anchor": "color-enum", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "$comment": "This schema uses enum with various annotation keywords", - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, content_media_type_without_encoding_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentMediaType": "application/json" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, content_schema_without_media_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64", - "contentSchema": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, max_contains_without_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "maxContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, max_contains_without_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contains": true, - "maxContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contains": true, - "maxContains": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, min_contains_without_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "minContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, min_contains_without_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contains": true, - "minContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contains": true, - "minContains": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, then_without_if_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "then": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, then_without_if_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": true, - "then": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": true, - "then": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, else_without_if_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "else": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, else_without_if_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": true, - "else": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": true, - "else": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, if_without_then_else_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unevaluated_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedProperties": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unevaluated_properties_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unevaluated_properties_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedProperties": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedProperties": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unevaluated_items_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedItems": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unevaluated_items_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedItems": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unevaluated_items_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedItems": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "unevaluatedItems": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, content_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, content_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, content_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, items_array_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, duplicate_enum_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, duplicate_required_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar", "baz", "foo" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_maximum_number_and_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMaximum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMaximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_maximum_number_and_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMaximum": 3, - "maximum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "maximum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_maximum_number_and_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMaximum": 3, - "maximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_minimum_number_and_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMinimum": 3, - "minimum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_minimum_number_and_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMinimum": 3, - "minimum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_minimum_number_and_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "exclusiveMinimum": 3, - "minimum": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, duplicate_allof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, duplicate_anyof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ { "type": "string" }, { "type": "integer" } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, anyof_true_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ true, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, anyof_true_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ { "type": "string" }, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, anyof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, anyof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, oneof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "oneOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, oneof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, oneof_to_anyof_disjoint_types_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "oneOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "anyOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, oneof_to_anyof_disjoint_types_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, dependent_required_tautology_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo" ], - "dependentRequired": { - "foo": [ "bar" ], - "xxx": [ "yyy" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "dependentRequired": { - "xxx": [ "yyy" ] - }, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, dependent_required_tautology_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo" ], - "dependentRequired": { - "foo": [ "bar" ], - "bar": [ "baz" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar", "baz" ], - "properties": { - "foo": true, - "bar": true, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, pattern_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "patternProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unsatisfiable_min_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unsatisfiable_min_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "bar", "baz", "foo" ], - "minProperties": 4, - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unsatisfiable_min_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "array", - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "boolean", - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "null", - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "number", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "number", - "multipleOf": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "integer", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "integer", - "multipleOf": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "object", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "object", - "unevaluatedProperties": false, - "maxProperties": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "string", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "type": "string", - "contentEncoding": "base64", - "format": "uri" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, const_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_maximum_integer_to_maximum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, exclusive_minimum_integer_to_minimum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unsatisfiable_max_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unsatisfiable_max_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unsatisfiable_max_contains_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 3, - "maxContains": 3 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_3) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 1, - "maxContains": 5 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_4) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/properties/foo", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_5) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 5 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_6) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "items": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/items", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_7) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "$ref": "#/$defs/foo", - "$defs": { - "foo": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/$defs/foo", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_8) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "$ref": "#/$defs/A/properties/bar", - "$defs": { - "A": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3, - "properties": { - "bar": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/$defs/A", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2019_09, incoherent_min_max_contains_9) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "minContains": 5, - "maxContains": 3 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 2); - EXPECT_LINT_TRACE(traces, 0, "", "max_contains_without_contains", - "The `maxContains` keyword is meaningless " - "without the presence of the `contains` keyword", - true); - EXPECT_LINT_TRACE(traces, 1, "", "min_contains_without_contains", - "The `minContains` keyword is meaningless " - "without the presence of the `contains` keyword", - true); -} - -TEST(AlterSchema_lint_2019_09, equal_numeric_bounds_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, equal_numeric_bounds_to_const_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, equal_numeric_bounds_to_const_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "minimum": 1.0e400, - "maximum": 1.0e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com/foo", - "allOf": [ - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com/foo", - "allOf": [ - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "type": "number" }, - { "$ref": "https://example.com" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com", - "type": "integer", - "allOf": [ - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { - "type": "integer", - "$ref": "https://example.com" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_6) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "A test schema", - "examples": [ "test" ], - "allOf": [ - { "type": "string", "$ref": "https://example.com" } - ] - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "unnecessary_allof_ref_wrapper_modern", - "Wrapping `$ref` in `allOf` was only necessary in JSON " - "Schema Draft 7 and older", - true); -} - -TEST(AlterSchema_lint_2019_09, multiple_of_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, multiple_of_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "multipleOf": 1.0, - "contains": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "contains": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, multiple_of_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "multipleOf": 1.2, - "type": "number" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "multipleOf": 1.2, - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, multiple_of_default_no_change_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "integer", - "multipleOf": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "bar": { "type": "string" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "bar": { "type": "string" } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "foo": { "minLength": 3 } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "foo": { "minLength": 3 } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "bar": { "minLength": 3 }, - "baz": { "maxLength": 5 } - } - }, - { "type": "object" }, - { - "properties": { - "qux": { "pattern": "^f" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "type": "object", - "allOf": [ - { - "properties": { - "bar": { "minLength": 3 }, - "baz": { "maxLength": 5 } - } - }, - { - "properties": { - "qux": { "pattern": "^f" } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_properties_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com", - "properties": { - "bar": { "pattern": "^f" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { "type": "string" } - }, - "$ref": "https://example.com", - "allOf": [ - { - "properties": { - "bar": { "pattern": "^f" } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_ref_wrapper_modern_elevation_single_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_ref_wrapper_modern_no_elevation_all_branches_have_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" }, - { "$ref": "https://example.com/baz" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" }, - { "$ref": "https://example.com/baz" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_ref_wrapper_modern_no_elevation_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { - "$ref": "https://example.com", - "$id": "https://other.com" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { - "$ref": "https://example.com", - "$id": "https://other.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, additional_items_with_schema_items_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": { - "type": "number" - }, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, additional_items_with_schema_items_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": { - "unevaluatedProperties": false - }, - "additionalItems": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": { - "unevaluatedProperties": false - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - additional_items_with_schema_items_boolean_items_true) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": true, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - additional_items_with_schema_items_boolean_items_false) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": false, - "additionalItems": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, additional_items_with_schema_items_array_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, modern_official_dialect_with_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, modern_official_dialect_with_empty_fragment_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/hyper-schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/hyper-schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, modern_official_dialect_with_empty_fragment_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, then_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, else_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, then_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {}, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, else_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, property_names_type_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "propertyNames": { - "type": "string", - "pattern": "^S_" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "propertyNames": { - "pattern": "^S_" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, property_names_type_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "propertyNames": { - "type": [ "string" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, property_names_type_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "propertyNames": { - "type": "integer" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "propertyNames": { - "type": "integer" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, property_names_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "propertyNames": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, definitions_to_defs_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "properties": { - "id": { - "$ref": "#/definitions/uuid" - } - }, - "definitions": { - "uuid": { - "type": "string", - "format": "uuid" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "properties": { - "id": { - "$ref": "#/$defs/uuid" - } - }, - "$defs": { - "uuid": { - "type": "string", - "format": "uuid" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, definitions_to_defs_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/foo", - "definitions": { - "foo": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/foo", - "$defs": { - "foo": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, definitions_to_defs_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "$ref": "#/properties/bar/definitions/helper" - }, - "bar": { - "definitions": { - "helper": { - "type": "string" - } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "$ref": "#/properties/bar/$defs/helper" - }, - "bar": { - "$defs": { - "helper": { - "type": "string" - } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, definitions_to_defs_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "properties": { - "bar": { - "definitions": { - "baz": { - "type": "string", - "format": "uuid" - }, - "qux": { - "type": "number" - } - }, - "properties": { - "id": { - "$ref": "#/properties/foo/properties/bar/definitions/baz" - }, - "count": { - "$ref": "#/properties/foo/properties/bar/definitions/qux" - } - } - } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": { - "properties": { - "bar": { - "$defs": { - "baz": { - "type": "string", - "format": "uuid" - }, - "qux": { - "type": "number" - } - }, - "properties": { - "id": { - "$ref": "#/properties/foo/properties/bar/$defs/baz" - }, - "count": { - "$ref": "#/properties/foo/properties/bar/$defs/qux" - } - } - } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_type_specific_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": null, - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": null - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, non_applicable_type_specific_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": "foo", - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "const": "foo", - "maxLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, not_false_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, not_false_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "minimum": 5, - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "minimum": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, not_false_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, not_false_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "not": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, not_false_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, required_properties_in_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, required_properties_in_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, required_properties_in_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": {}, - "bar": false, - "baz": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": false, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, required_properties_in_properties_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, required_properties_in_properties_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, required_properties_in_properties_16) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, required_properties_in_properties_17) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "custom": "value", - "x-custom": "conflicting value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "x-custom": "conflicting value", - "x-x-custom": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "properties": { - "nested": { - "type": "string", - "custom": "value", - "x-custom": "conflicting value" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "properties": { - "nested": { - "type": "string", - "x-custom": "conflicting value", - "x-x-custom": "value" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/foo", - "type": "object", - "$defs": { - "foo": { - "type": "string", - "custom": "value", - "x-custom": "conflicting value" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/foo", - "type": "object", - "$defs": { - "foo": { - "type": "string", - "x-custom": "conflicting value", - "x-x-custom": "value" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/foo", - "custom": "value", - "x-custom": "conflicting value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "x-custom": "conflicting value", - "x-x-custom": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unknown_keywords_prefix_11) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "unevaluatedProperties": false, - "custom": "value", - "x-custom": "conflicting value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "unevaluatedProperties": false, - "x-custom": "conflicting value", - "x-x-custom": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, top_level_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://sourcemeta.com", - "$ref": "https://example.com" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://sourcemeta.com", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, additional_items_with_no_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, comment_trim_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$comment": " A comment with whitespace ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$comment": "A comment with whitespace", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, comment_trim_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$comment": "A comment without whitespace", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$comment": "A comment without whitespace", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, top_level_examples_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "My schema", - "description": "A description", - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_examples", - "Set a non-empty examples array at the top level of the " - "schema to illustrate the expected data", - false); -} - -TEST(AlterSchema_lint_2019_09, top_level_examples_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "My schema", - "description": "A description", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, duplicate_examples_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "examples": [ "foo", "bar", "foo" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, duplicate_examples_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, orphan_definitions_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "$defs": { - "unused": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, orphan_definitions_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, orphan_definitions_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { "type": "string" }, - "unused": { "type": "integer" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, orphan_definitions_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "definitions": { - "unused": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, orphan_definitions_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/definitions/used", - "definitions": { - "used": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, orphan_definitions_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object", - "$defs": { - "unused_in_defs": { "type": "string" } - }, - "definitions": { - "unused_in_definitions": { "type": "integer" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, orphan_definitions_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/from_defs", - "$defs": { - "from_defs": { "$ref": "#/definitions/from_definitions" } - }, - "definitions": { - "from_definitions": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "#/$defs/from_defs", - "$defs": { - "from_defs": { "$ref": "#/definitions/from_definitions" } - }, - "definitions": { - "from_definitions": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_inner_additional_properties_outer_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_inner_properties_and_additional_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_type_can_elevate_with_outer_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { "foo": { "type": "string" } }, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_ref_with_siblings_can_elevate) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$ref": "https://example.com", "minLength": 5 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$ref": "https://example.com", - "minLength": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_with_recursive_ref_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$recursiveRef": "#", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$recursiveRef": "#", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, unnecessary_allof_wrapper_with_id_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_with_anchor_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$anchor": "foo", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$anchor": "foo", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_with_recursive_anchor_true_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$recursiveAnchor": true, "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$recursiveAnchor": true, "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - unnecessary_allof_wrapper_with_recursive_anchor_false_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "allOf": [ - { "$recursiveAnchor": false, "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$recursiveAnchor": false, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, simple_properties_identifiers_skip_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/my-metaschema", - "title": "My meta-schema", - "description": "A custom meta-schema", - "examples": [ {} ], - "$vocabulary": { - "https://json-schema.org/draft/2019-09/vocab/core": true, - "https://json-schema.org/draft/2019-09/vocab/applicator": true - }, - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, - simple_properties_identifiers_skip_metaschema_nested) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/my-metaschema", - "title": "My meta-schema", - "description": "A custom meta-schema", - "examples": [ {} ], - "$vocabulary": { - "https://json-schema.org/draft/2019-09/vocab/core": true, - "https://json-schema.org/draft/2019-09/vocab/applicator": true - }, - "properties": { - "valid": { - "properties": { - "also-invalid": { "type": "number" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, simple_properties_identifiers_applies_non_meta) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/my-schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily " - "mapped to programming languages (matching " - "[A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_2019_09, - simple_properties_identifiers_skip_bundled_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/main", - "title": "Main schema", - "description": "A schema that bundles a meta-schema", - "examples": [ {} ], - "$ref": "https://example.com/my-metaschema", - "$defs": { - "metaschema": { - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$id": "https://example.com/my-metaschema", - "$vocabulary": { - "https://json-schema.org/draft/2019-09/vocab/core": true, - "https://json-schema.org/draft/2019-09/vocab/applicator": true - }, - "properties": { - "foo-bar": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, empty_object_as_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": {} - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "not": true - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "enum": [] - } - }, - "$ref": "#/$defs/A" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "enum": [] - } - }, - "$ref": "#/$defs/A" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "enum": [], - "$defs": { - "inner": { "type": "string" } - } - } - }, - "$ref": "#/$defs/A/$defs/inner" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "enum": [], - "$defs": { - "inner": { "type": "string" } - } - } - }, - "$ref": "#/$defs/A/$defs/inner" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "$id": "https://example.com/schemas/A", - "enum": [] - } - }, - "$ref": "https://example.com/schemas/A" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "$id": "https://example.com/schemas/A", - "enum": [] - } - }, - "$ref": "https://example.com/schemas/A" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "x-note": "placeholder", - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "x-note": "placeholder", - "not": true - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "enum": [], - "additionalProperties": { "type": "string" } - } - }, - "$ref": "#/$defs/A/additionalProperties" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "$defs": { - "A": { - "enum": [], - "additionalProperties": { "type": "string" } - } - }, - "$ref": "#/$defs/A/additionalProperties" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, forbid_empty_enum_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": { "type": "string" }, - "enum": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "not": { "type": "string" }, - "enum": [] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, invalid_external_ref_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://unknown.example.com/nonexistent" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_2019_09, invalid_external_ref_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$defs": { - "foo": { "type": "string" } - }, - "$ref": "#/$defs/foo" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2019_09, modern_official_dialect_with_http_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, modern_official_dialect_with_http_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft/2019-09/hyper-schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/hyper-schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, modern_official_dialect_with_http_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft/2019-09/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2019_09, - modern_official_dialect_with_http_already_https) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2019-09/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_2020_12_test.cc b/test/alterschema/alterschema_lint_2020_12_test.cc deleted file mode 100644 index b303726c3..000000000 --- a/test/alterschema/alterschema_lint_2020_12_test.cc +++ /dev/null @@ -1,10656 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_2020_12, local_ref_to_unknown_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, local_ref_to_unknown_location_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, local_ref_to_unknown_anchor) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - local_ref_to_unknown_location_with_nested_resource_relative) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "foo#/$defs/foo", - "additionalProperties": { "$id": "foo" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": { "$id": "foo" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - local_ref_to_unknown_location_with_nested_resource_relative_valid) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - local_ref_to_unknown_location_with_nested_resource_absolute) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://www.example.com/foo#/$defs/foo", - "additionalProperties": { "$id": "foo" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": { "$id": "foo" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - local_ref_to_unknown_location_with_nested_resource_absolute_valid) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://www.example.com/foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://www.example.com/foo#/$defs/foo", - "additionalProperties": { "$id": "foo", "$defs": { "foo": true } } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, nested_ref_to_unknown_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$ref": "#/$defs/bar" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, nested_ref_to_existing_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "bar": { "type": "string" } - }, - "properties": { - "foo": { - "$ref": "#/$defs/bar" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "bar": { "type": "string" } - }, - "properties": { - "foo": { - "$ref": "#/$defs/bar" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, deeply_nested_ref_to_unknown_location) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "items": { - "properties": { - "bar": { - "$ref": "#/$defs/baz" - } - } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "items": { - "properties": { - "bar": true - } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, nested_ref_to_unknown_anchor) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "$ref": "#unknownAnchor" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, nested_ref_to_existing_anchor) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "myDef": { - "$anchor": "myAnchor", - "type": "number" - } - }, - "properties": { - "value": { - "$ref": "#myAnchor" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "myDef": { - "$anchor": "myAnchor", - "type": "number" - } - }, - "properties": { - "value": { - "$ref": "#myAnchor" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, mixed_nested_refs_valid_and_invalid) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "string": { "type": "string" } - }, - "properties": { - "name": { - "$ref": "#/$defs/string" - }, - "age": { - "$ref": "#/$defs/number" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "string": { "type": "string" } - }, - "properties": { - "name": { - "$ref": "#/$defs/string" - }, - "age": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, external_ref_with_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$ref": "https://example.com/schema#/$defs/bar" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$ref": "https://example.com/schema#/$defs/bar" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, external_ref_with_unknown_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema#/$defs/nonNegativeInteger" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://json-schema.org/draft/2020-12/schema#/$defs/nonNegativeInteger" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, nested_external_ref_with_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com/base-schema#/$defs/common", - "properties": { - "value": { - "$ref": "http://another-example.com/types#/definitions/string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com/base-schema#/$defs/common", - "properties": { - "value": { - "$ref": "http://another-example.com/types#/definitions/string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - external_relative_ref_with_fragment_not_removed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com/my-schema", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "data": { - "$ref": "common-types.json#/$defs/uuid" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.example.com/my-schema", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "data": { - "$ref": "common-types.json#/$defs/uuid" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, enum_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, const_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, const_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "string", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, const_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, const_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, content_media_type_without_encoding_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentMediaType": "application/json" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, content_schema_without_media_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64", - "contentSchema": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, max_contains_without_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "maxContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, max_contains_without_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contains": true, - "maxContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contains": true, - "maxContains": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, min_contains_without_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "minContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, min_contains_without_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contains": true, - "minContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contains": true, - "minContains": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_without_if_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "then": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_without_if_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "then": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "then": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_without_if_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "else": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_without_if_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "else": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "else": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, if_without_then_else_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_properties_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_properties_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_items_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_items_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_items_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, content_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, content_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, content_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_enum_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_enum_values_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "S", "C", "U", "F", "E", "N", "L", "R", "U", null ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "S", "C", "U", "F", "E", "N", "L", "R", null ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_required_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar", "baz", "foo" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_maximum_number_and_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMaximum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMaximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_maximum_number_and_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMaximum": 3, - "maximum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "maximum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_maximum_number_and_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMaximum": 3, - "maximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_minimum_number_and_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMinimum": 3, - "minimum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_minimum_number_and_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMinimum": 3, - "minimum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_minimum_number_and_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "exclusiveMinimum": 3, - "minimum": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, allof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ false, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, allof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, allof_false_simplify_with_ref_through) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ false, { "type": "string" } ], - "properties": { - "foo": { "$ref": "#/allOf/1" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ false, { "type": "string" } ], - "properties": { - "foo": { "$ref": "#/allOf/1" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_allof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_anyof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ { "type": "string" }, { "type": "integer" } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_anyof_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "anyOf": [ - { "type": "number" }, - { "minLength": 1 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "anyOf": [ - { "minLength": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_anyof_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "anyOf": [ - { "type": "array" }, - { "type": "string" }, - { "type": "object", "minProperties": 1 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "anyOf": [ - { "type": "object", "minProperties": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_oneof_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "oneOf": [ - { "type": "string" }, - { "minimum": 0 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "oneOf": [ - false, - { "minimum": 0 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_oneof_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "oneOf": [ - { "type": "object" }, - { "type": "string" }, - { "type": "array", "minItems": 1 }, - { "type": "number" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "oneOf": [ - false, - false, - { "type": "array", "minItems": 1 }, - false - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_if_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "if": { "type": "number" }, - "then": { "minLength": 1 } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "if": false, - "then": { "minLength": 1 } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_then_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "if": { "required": [ "foo" ] }, - "then": { "type": "array" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "if": { "required": [ "foo" ], "properties": { "foo": true } }, - "then": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_else_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "if": { "minimum": 0 }, - "else": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "if": { "minimum": 0 }, - "else": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_if_then_else_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "if": { "type": "number" }, - "then": { "type": "array" }, - "else": { "type": "object" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "if": false, - "then": false, - "else": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_logic_branch_type_mixed_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "allOf": [ { "type": "string" } ], - "anyOf": [ { "type": "object" }, { "multipleOf": 2 } ], - "oneOf": [ { "type": "array" }, { "minimum": 0 } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, dependent_required_tautology_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo" ], - "dependentRequired": { - "foo": [ "bar" ], - "xxx": [ "yyy" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "dependentRequired": { - "xxx": [ "yyy" ] - }, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, dependent_required_tautology_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo" ], - "dependentRequired": { - "foo": [ "bar" ], - "bar": [ "baz" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar", "baz" ], - "properties": { - "foo": true, - "bar": true, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, pattern_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "patternProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_min_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_min_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "bar", "baz", "foo" ], - "minProperties": 4, - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_min_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "array", - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "boolean", - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "null", - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "number", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "number", - "multipleOf": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "integer", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "integer", - "multipleOf": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "object", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "object", - "unevaluatedProperties": false, - "maxProperties": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "string", - "multipleOf": 2, - "unevaluatedProperties": false, - "contentEncoding": "base64", - "maxProperties": 3, - "format": "uri", - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "type": "string", - "contentEncoding": "base64", - "format": "uri" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, const_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_maximum_integer_to_maximum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, exclusive_minimum_integer_to_minimum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_max_contains_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_max_contains_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unsatisfiable_max_contains_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3, - "maxContains": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "contains": { "type": "string" }, - "maxItems": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 3, - "maxContains": 3 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_3) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 1, - "maxContains": 5 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_4) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/properties/foo", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_5) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "contains": { "type": "string" }, - "minContains": 5 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_6) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "items": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/items", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_7) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "$ref": "#/$defs/foo", - "$defs": { - "foo": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3 - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/$defs/foo", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_8) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "$ref": "#/$defs/A/properties/bar", - "$defs": { - "A": { - "type": "array", - "contains": { "type": "string" }, - "minContains": 5, - "maxContains": 3, - "properties": { - "bar": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/$defs/A", "incoherent_min_max_contains", - "`minContains` greater than `maxContains` makes the " - "schema unsatisfiable", - false); -} - -TEST(AlterSchema_lint_2020_12, incoherent_min_max_contains_9) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ [] ], - "type": "array", - "minContains": 5, - "maxContains": 3 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 2); - EXPECT_LINT_TRACE(traces, 0, "", "max_contains_without_contains", - "The `maxContains` keyword is meaningless " - "without the presence of the `contains` keyword", - true); - EXPECT_LINT_TRACE(traces, 1, "", "min_contains_without_contains", - "The `minContains` keyword is meaningless " - "without the presence of the `contains` keyword", - true); -} - -TEST(AlterSchema_lint_2020_12, equal_numeric_bounds_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, equal_numeric_bounds_to_const_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, equal_numeric_bounds_to_const_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "minimum": 1.0e400, - "maximum": 1.0e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com/foo", - "allOf": [ - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com/foo", - "allOf": [ - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "number" }, - { "$ref": "https://example.com" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "type": "integer", - "allOf": [ - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "type": "integer", - "$ref": "https://example.com" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com" } - ], - "title": "Foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "title": "Foo" - })JSON"); - - EXPECT_EQ(document, expected); - - // We expect the `$ref` keyword to take the place of `allOf` in - // terms of keyword ordering - std::vector keywords; - for (const auto &entry : document.as_object()) { - keywords.emplace_back(entry.first); - } - - EXPECT_EQ(keywords.size(), 3); - EXPECT_EQ(keywords.at(0), "$schema"); - EXPECT_EQ(keywords.at(1), "$ref"); - EXPECT_EQ(keywords.at(2), "title"); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com" }, - { "type": "string" } - ], - "title": "Foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "type": "string", - "title": "Foo" - })JSON"); - - EXPECT_EQ(document, expected); - - // We expect the `$ref` and `type` keywords to take the place of `allOf` in - // terms of keyword ordering - std::vector keywords; - for (const auto &entry : document.as_object()) { - keywords.emplace_back(entry.first); - } - - EXPECT_EQ(keywords.size(), 4); - EXPECT_EQ(keywords.at(0), "$schema"); - EXPECT_EQ(keywords.at(1), "$ref"); - EXPECT_EQ(keywords.at(2), "type"); - EXPECT_EQ(keywords.at(3), "title"); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "string", "$ref": "https://example.com" } - ], - "title": "Foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "type": "string", - "title": "Foo" - })JSON"); - - EXPECT_EQ(document, expected); - - // We expect the `$ref` and `type` keywords to take the place of `allOf` in - // terms of keyword ordering - std::vector keywords; - for (const auto &entry : document.as_object()) { - keywords.emplace_back(entry.first); - } - - EXPECT_EQ(keywords.size(), 4); - EXPECT_EQ(keywords.at(0), "$schema"); - EXPECT_EQ(keywords.at(1), "$ref"); - EXPECT_EQ(keywords.at(2), "type"); - EXPECT_EQ(keywords.at(3), "title"); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_9) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ "test" ], - "allOf": [ - { "type": "string", "$ref": "https://example.com" } - ] - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "unnecessary_allof_ref_wrapper_modern", - "Wrapping `$ref` in `allOf` was only necessary in JSON " - "Schema Draft 7 and older", - true); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "number", "$ref": "https://example.com" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "type": "integer", - "allOf": [ - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_11) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "if": { "type": "string" }, "then": { "minLength": 1 } }, - { "if": { "type": "integer" }, "then": { "minimum": 1 } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { "type": "integer" }, - "then": { "minimum": 1 }, - "allOf": [ - { "if": { "type": "string" }, "then": { "minLength": 1 } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_12) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "allOf": [ - { "properties": { "foo": { "type": "string" } } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "allOf": [ - { "properties": { "foo": { "type": "string" } } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_13) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "allOf": [ - { "patternProperties": { "^f": { "type": "string" } } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "allOf": [ - { "patternProperties": { "^f": { "type": "string" } } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_14) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": false, - "allOf": [ - { "prefixItems": [ true, false ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": false, - "allOf": [ - { "prefixItems": [ true, false ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_15) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": false, - "allOf": [ - { "properties": { "foo": { "type": "string" } } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": false, - "properties": { "foo": { "type": "string" } } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_16) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "allOf": [ - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_17) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 5, - "allOf": [ - { "type": "string", "minLength": 5 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "minLength": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_18) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com", "minLength": 5 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "minLength": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_cross_dependency_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "properties": { "foo": {} } }, - { "additionalProperties": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "allOf": [ - { "properties": { "foo": true } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_cross_dependency_prefixItems) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "prefixItems": [ { "type": "string" } ] }, - { "items": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": false, - "allOf": [ - { "prefixItems": [ { "type": "string" } ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_cross_dependency_contains_minContains) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "contains": { "type": "number" } }, - { "minContains": 2 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contains": { "type": "number" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_with_dynamic_ref_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$dynamicRef": "#foo", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$dynamicRef": "#foo", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_with_id_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_with_anchor_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$anchor": "foo", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$anchor": "foo", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_with_dynamic_anchor_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$dynamicAnchor": "foo", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$dynamicAnchor": "foo", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, multiple_of_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, multiple_of_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "multipleOf": 1.0, - "unevaluatedProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, multiple_of_default_no_change_string_value) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": "1" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "integer", - "multipleOf": "1" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, multiple_of_default_no_change_numeric_value) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "multipleOf": 2.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "number", - "multipleOf": 2.5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "bar": { "type": "string" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "bar": { "type": "string" } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "foo": { "minLength": 3 } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "foo": { "minLength": 3 } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "properties": { - "bar": { "minLength": 3 }, - "baz": { "maxLength": 5 } - } - }, - { "type": "object" }, - { - "properties": { - "qux": { "pattern": "^f" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "type": "object", - "allOf": [ - { - "properties": { - "bar": { "minLength": 3 }, - "baz": { "maxLength": 5 } - } - }, - { - "properties": { - "qux": { "pattern": "^f" } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_properties_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com", - "properties": { - "bar": { "pattern": "^f" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - }, - "$ref": "https://example.com", - "allOf": [ - { - "properties": { - "bar": { "pattern": "^f" } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_elevation_single_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_elevation_multiple_refs) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" }, - { "$ref": "https://example.com/baz" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" }, - { "$ref": "https://example.com/baz" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_elevation_mixed_branches_with_and_without_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "properties": { "bar": { "type": "string" } } }, - { "$ref": "https://example.com/baz", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$ref": "https://example.com/foo", - "properties": { "bar": { "type": "string" } }, - "allOf": [ - { "$ref": "https://example.com/baz", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_no_elevation_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "$ref": "https://example.com", - "$id": "https://other.com" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "$ref": "https://example.com", - "$id": "https://other.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_no_elevation_parent_has_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com/main", - "allOf": [ - { "$ref": "https://example.com/foo" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com/main", - "allOf": [ - { "$ref": "https://example.com/foo" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_no_elevation_all_branches_have_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_no_elevation_all_branches_have_ref_with_siblings) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo", "type": "object" }, - { "$ref": "https://example.com/bar", "properties": { "x": { "type": "string" } } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "https://example.com/foo", "type": "object" }, - { "$ref": "https://example.com/bar", "properties": { "x": { "type": "string" } } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_ref_wrapper_modern_elevation_ref_with_siblings) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "$ref": "https://example.com", - "type": "object", - "properties": { "foo": { "type": "string" } } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "https://example.com", - "type": "object", - "properties": { "foo": { "type": "string" } } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, modern_official_dialect_with_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, modern_official_dialect_with_empty_fragment_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/hyper-schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/hyper-schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, modern_official_dialect_with_empty_fragment_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - // Should remain unchanged since there's no empty fragment - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {}, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_empty_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "else": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_empty_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_empty_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "then": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, property_names_type_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "propertyNames": { - "type": "string", - "pattern": "^S_" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "propertyNames": { - "pattern": "^S_" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, property_names_type_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "propertyNames": { - "type": [ "string" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, property_names_type_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "propertyNames": { - "type": "integer" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "propertyNames": { - "type": "integer" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, property_names_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "propertyNames": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, definitions_to_defs_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/foo", - "definitions": { - "foo": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/foo", - "$defs": { - "foo": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, definitions_to_defs_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$ref": "#/properties/bar/definitions/helper" - }, - "bar": { - "definitions": { - "helper": { - "type": "string" - } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$ref": "#/properties/bar/$defs/helper" - }, - "bar": { - "$defs": { - "helper": { - "type": "string" - } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, definitions_to_defs_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "properties": { - "bar": { - "definitions": { - "baz": { - "type": "string", - "format": "uuid" - }, - "qux": { - "type": "number" - } - }, - "properties": { - "id": { - "$ref": "#/properties/foo/properties/bar/definitions/baz" - }, - "count": { - "$ref": "#/properties/foo/properties/bar/definitions/qux" - } - } - } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "properties": { - "bar": { - "$defs": { - "baz": { - "type": "string", - "format": "uuid" - }, - "qux": { - "type": "number" - } - }, - "properties": { - "id": { - "$ref": "#/properties/foo/properties/bar/$defs/baz" - }, - "count": { - "$ref": "#/properties/foo/properties/bar/$defs/qux" - } - } - } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_type_specific_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": null, - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": null - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_type_specific_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": "foo", - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "const": "foo", - "maxLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, not_false_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, not_false_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "minimum": 5, - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "minimum": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, not_false_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, not_false_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "not": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, not_false_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": {}, - "bar": false, - "baz": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": false, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "anyOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar" ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "anyOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar" ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "anyOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar", "baz" ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "anyOf": [ - { "required": [ "foo" ] }, - { - "required": [ "bar", "baz" ], - "properties": { - "baz": true - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "oneOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar" ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "oneOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar" ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "oneOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar", "baz" ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "oneOf": [ - { "required": [ "foo" ] }, - { - "required": [ "bar", "baz" ], - "properties": { - "baz": true - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "allOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar" ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "required": [ "bar" ], - "allOf": [ - { "required": [ "foo" ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_11) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true }, - "allOf": [ - { "required": [ "foo" ] }, - { "required": [ "bar", "baz" ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true, "baz": true }, - "required": [ "bar", "baz" ], - "allOf": [ - { "required": [ "foo" ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_12) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true, "baz": true }, - "if": { "required": [ "foo" ] }, - "then": { "required": [ "bar" ] }, - "else": { "required": [ "baz" ] } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true, "bar": true, "baz": true }, - "if": { "required": [ "foo" ] }, - "then": { "required": [ "bar" ] }, - "else": { "required": [ "baz" ] } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_13) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true }, - "not": { "required": [ "foo" ] } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true }, - "not": { "required": [ "foo" ] } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_14) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true }, - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": { "required": [ "foo" ] } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": true }, - "contentEncoding": "base64", - "contentMediaType": "application/json", - "contentSchema": { "required": [ "foo" ] } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_15) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "$ref": "#/$defs/helper", - "$defs": { - "helper": { - "properties": { "foo": true, "bar": true } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "$ref": "#/$defs/helper", - "properties": { "foo": true, "bar": true }, - "$defs": { - "helper": { - "properties": { "foo": true, "bar": true } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_16) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, required_properties_in_properties_17) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "x-alreadyPrefixed": true, - "X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "x-x-foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "x-x-x-foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/MyType", - "definitions": { - "MyType": { "type": "string" } - }, - "customKeyword": "should be prefixed", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/MyType", - "$defs": { - "MyType": { "type": "string" } - }, - "x-customKeyword": "should be prefixed", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/MyType", - "unknownKeyword": "should be prefixed in modern drafts", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "x-unknownKeyword": "should be prefixed in modern drafts", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_11) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "properties": { - "name": { "type": "string" } - }, - "unevaluatedProperties": false, - "customKeyword": "should be prefixed" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "properties": { - "name": { "type": "string" } - }, - "unevaluatedProperties": false, - "x-customKeyword": "should be prefixed" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_12) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ "test" ], - "unknown-1": 1, - "unknown-2": 2 - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "", "unknown_keywords_prefix", - "Future versions of JSON Schema will refuse to evaluate unknown " - "keywords or custom keywords from optional vocabularies that don't " - "have an x- prefix", - true); - EXPECT_EQ(std::get<3>(traces.at(0)).locations.size(), 2); - EXPECT_EQ( - sourcemeta::core::to_string(std::get<3>(traces.at(0)).locations.at(0)), - "/unknown-1"); - EXPECT_EQ( - sourcemeta::core::to_string(std::get<3>(traces.at(0)).locations.at(1)), - "/unknown-2"); -} - -TEST(AlterSchema_lint_2020_12, unknown_keywords_prefix_13) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://sourcemeta.com/2020-12-custom-vocabulary-optional", - "foo": "bar" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://sourcemeta.com/2020-12-custom-vocabulary-optional", - "foo": "bar" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, 2, 3 ], - "minLength": 3, - "pattern": "^[a-z]+$" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "one", "two" ], - "minimum": 0, - "maximum": 100, - "multipleOf": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "one", "two" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ true, false ], - "minLength": 1, - "minimum": 0, - "minItems": 1, - "minProperties": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schema", - "$anchor": "color-enum", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "$comment": "This schema uses enum with various annotation keywords", - "examples": [ "red", "blue" ], - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2, - "minProperties": 1, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/schema", - "$anchor": "color-enum", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "$comment": "This schema uses enum with various annotation keywords", - "examples": [ "red", "blue" ], - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, non_applicable_enum_validation_keywords_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, 2, 3 ], - "minLength": 2, - "maxLength": 10, - "pattern": "^[a-z]+$" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - non_applicable_enum_validation_keywords_with_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/myType", - "enum": [ "foo", "bar" ], - "minimum": 10, - "maxItems": 5, - "$defs": { - "myType": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/myType", - "enum": [ "foo", "bar" ], - "$defs": { - "myType": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - non_applicable_enum_validation_keywords_universal_keywords) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "foo", "bar" ], - "title": "My enum", - "description": "A test enum", - "default": "foo", - "examples": [ "foo" ], - "minimum": 10, - "maxItems": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "enum": [ "foo", "bar" ], - "title": "My enum", - "description": "A test enum", - "default": "foo", - "examples": [ "foo" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, embedded_resource_draft7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/embedded", - "$defs": { - "embedded": { - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com", - "definitions": {} - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/embedded", - "$defs": { - "embedded": { - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com", - "definitions": {} - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, invalid_embedded_resource_draft7_without_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/embedded", - "$defs": { - "embedded": { - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": {} - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - // As `$schema` without `$id` is ignored - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/embedded", - "$defs": { - "embedded": { - "$defs": {} - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - invalid_embedded_resource_draft7_with_sibling_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/main", - "$ref": "embedded", - "$defs": { - "embedded": { - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "embedded", - "$ref": "#/definitions/foo", - "definitions": { - "foo": { "type": "number" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/main", - "$ref": "embedded", - "$defs": { - "embedded": { - "$id": "embedded", - "$ref": "#/$defs/foo", - "$defs": { - "foo": { "type": "number" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://sourcemeta.com", - "$ref": "https://example.com" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://sourcemeta.com", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_title_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "description": "Missing title", - "examples": [ "test" ], - "additionalProperties": { - "type": "string" - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_title", - "Set a concise non-empty title at the top level of the " - "schema to explain what the definition is about", - false); -} - -TEST(AlterSchema_lint_2020_12, top_level_title_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "description": "Missing title", - "additionalProperties": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "description": "Missing title", - "additionalProperties": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_description_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Missing description", - "examples": [ "test" ], - "additionalProperties": { - "type": "string" - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_description", - "Set a non-empty description at the top level of the " - "schema to explain what the definition is about in detail", - false); -} - -TEST(AlterSchema_lint_2020_12, top_level_description_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Missing description", - "additionalProperties": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Missing description", - "additionalProperties": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_title_3) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "", - "description": "Has empty title", - "examples": [ "test" ], - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_title", - "Set a concise non-empty title at the top level of the " - "schema to explain what the definition is about", - false); -} - -TEST(AlterSchema_lint_2020_12, top_level_title_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "", - "description": "Has empty title", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "", - "description": "Has empty title", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_description_3) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Has empty description", - "description": "", - "examples": [ "test" ], - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_description", - "Set a non-empty description at the top level of the " - "schema to explain what the definition is about in detail", - false); -} - -TEST(AlterSchema_lint_2020_12, top_level_description_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Has empty description", - "description": "", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Has empty description", - "description": "", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_description_equal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "My schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_description_equal_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "Different description", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "Different description", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_description_equal_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "description": "Foo property", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_description_equal_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/helper", - "title": "Top level", - "description": "Top level description", - "$defs": { - "helper": { - "title": "Helper", - "description": "Helper", - "type": "integer" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/helper", - "title": "Top level", - "description": "Top level description", - "$defs": { - "helper": { - "title": "Helper", - "type": "integer" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trailing_period_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema.", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trailing_period_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema...", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trailing_period_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trailing_period_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property.", - "description": "The foo property", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "description": "The foo property", - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trailing_period_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema.", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trailing_period_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema...", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trailing_period_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trailing_period_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "description": "The foo property.", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "description": "The foo property", - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trim_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": " My schema ", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trim_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "\t\nMy schema\r\n", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trim_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trim_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": " Foo property ", - "description": "The foo property", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "description": "The foo property", - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": " A description of the schema ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "\t\nA description of the schema\r\n", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "description": " The foo property ", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Top level", - "description": "Top level description", - "properties": { - "foo": { - "title": "Foo property", - "description": "The foo property", - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trim_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": " ", - "description": "A description of the schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "", - "description": "A description of the schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": " ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "a": { - "description": " untrimmed description a " - }, - "b": { - "description": " untrimmed description b " - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 5); - - // The mutable rules that were applied - EXPECT_LINT_TRACE(traces, 0, "/properties/a", "description_trim", - "Descriptions should not contain leading or trailing " - "whitespace", - true); - EXPECT_LINT_TRACE(traces, 1, "/properties/b", "description_trim", - "Descriptions should not contain leading or trailing " - "whitespace", - true); - - // The non-mutable rules that couldn't be fixed - EXPECT_LINT_TRACE(traces, 2, "", "top_level_title", - "Set a concise non-empty title at the top level of the " - "schema to explain what the definition is about", - false); - EXPECT_LINT_TRACE(traces, 3, "", "top_level_description", - "Set a non-empty description at the top level of the " - "schema to explain what the definition is about in detail", - false); - EXPECT_LINT_TRACE(traces, 4, "", "top_level_examples", - "Set a non-empty examples array at the top level of the " - "schema to illustrate the expected data", - false); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "a": { - "description": "untrimmed description a" - }, - "b": { - "description": "untrimmed description b" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My Title", - "description": "My Description", - "examples": [ "foo" ], - "allOf": [ - { "minLength": 1 }, - { "minLength": 1 }, - { "minLength": 1 }, - { - "properties": { - "foo": { "description": " untrimmed " } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 5); - - EXPECT_LINT_TRACE( - traces, 0, "", "duplicate_allof_branches", - "Setting duplicate subschemas in `allOf` is redundant, as it produces " - "unnecessary additional validation that is guaranteed to not affect the " - "validation result", - true); - EXPECT_LINT_TRACE( - traces, 1, "", "unnecessary_allof_wrapper", - "Keywords inside `allOf` that do not conflict with the parent schema can " - "be elevated", - true); - EXPECT_LINT_TRACE( - traces, 2, "", "duplicate_allof_branches", - "Setting duplicate subschemas in `allOf` is redundant, as it produces " - "unnecessary additional validation that is guaranteed to not affect the " - "validation result", - true); - EXPECT_LINT_TRACE(traces, 3, "", "drop_allof_empty_schemas", - "Empty schemas in `allOf` are redundant and can be removed", - true); - EXPECT_LINT_TRACE(traces, 4, "/properties/foo", "description_trim", - "Descriptions should not contain leading or trailing " - "whitespace", - true); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My Title", - "description": "My Description", - "examples": [ "foo" ], - "properties": { - "foo": { "description": "untrimmed" } - }, - "minLength": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unfixable_allof_renumber_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My Title", - "description": "My Description", - "examples": [ "foo" ], - "properties": { - "foo-bar": { "type": "number" } - }, - "allOf": [ - { "minLength": 1 }, - { "minLength": 1 }, - { "minLength": 1 }, - { - "properties": { - "foo-bar": { "type": "string" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 5); - - // The mutable rules that were applied - EXPECT_LINT_TRACE( - traces, 0, "", "duplicate_allof_branches", - "Setting duplicate subschemas in `allOf` is redundant, as it produces " - "unnecessary additional validation that is guaranteed to not affect the " - "validation result", - true); - EXPECT_LINT_TRACE( - traces, 1, "", "unnecessary_allof_wrapper", - "Keywords inside `allOf` that do not conflict with the parent schema can " - "be elevated", - true); - EXPECT_LINT_TRACE(traces, 2, "", "drop_allof_empty_schemas", - "Empty schemas in `allOf` are redundant and can be removed", - true); - - // The non-mutable rules that matched but couldn't be fixed - EXPECT_LINT_TRACE(traces, 3, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily " - "mapped to programming languages (matching " - "[A-Za-z_][A-Za-z0-9_]*)", - false); - EXPECT_LINT_TRACE(traces, 4, "/allOf/0", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily " - "mapped to programming languages (matching " - "[A-Za-z_][A-Za-z0-9_]*)", - false); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My Title", - "description": "My Description", - "examples": [ "foo" ], - "properties": { - "foo-bar": { "type": "number" } - }, - "minLength": 1, - "allOf": [ - { - "properties": { - "foo-bar": { "type": "string" } - } - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_trim_and_trailing_period_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": " foo. ", - "description": "A description", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "foo", - "description": "A description", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, description_trim_and_trailing_period_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": " bar... ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "bar", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, title_description_trim_period_and_equal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": " foo. ", - "description": " foo. ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "foo", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, comment_trim_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": " A comment with whitespace ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "A comment with whitespace", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, comment_trim_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "\t\nA comment\r\n", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "A comment", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, comment_trim_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "A comment without whitespace", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "A comment without whitespace", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, comment_trim_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$comment": " Nested comment ", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$comment": "Nested comment", - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, comment_trim_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": " ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$comment": "", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_examples_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description", - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_examples", - "Set a non-empty examples array at the top level of the " - "schema to illustrate the expected data", - false); -} - -TEST(AlterSchema_lint_2020_12, top_level_examples_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_examples_3) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description", - "examples": [], - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_examples", - "Set a non-empty examples array at the top level of the " - "schema to illustrate the expected data", - false); -} - -TEST(AlterSchema_lint_2020_12, top_level_examples_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "examples": [], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "examples": [], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, top_level_examples_5) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "description": "A description", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, top_level_examples_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "My schema", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_examples_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "examples": [ "foo", "bar", "foo" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_examples_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_examples_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "examples": [ 1, 2, 1, 3, 2 ], - "type": "integer" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "examples": [ 1, 2, 3 ], - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_examples_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "examples": [ "a", "b", "a" ], - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "examples": [ "a", "b" ], - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$defs": { - "unused": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$defs": { - "unused1": { "type": "string" }, - "unused2": { "type": "integer" }, - "unused3": { "type": "boolean" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { "type": "string" }, - "unused": { "type": "integer" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$defs": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$defs": {} - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "$ref": "#/$defs/helper" } - }, - "$defs": { - "helper": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "$ref": "#/$defs/helper" } - }, - "$defs": { - "helper": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/parent", - "$defs": { - "parent": { - "$ref": "#/$defs/child" - }, - "child": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/parent", - "$defs": { - "parent": { - "$ref": "#/$defs/child" - }, - "child": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$defs": { - "unused": { - "$anchor": "my-anchor", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$defs": { - "unused1": { - "$anchor": "my-anchor", - "type": "string" - }, - "unused2": { - "type": "integer" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "definitions": { - "unused": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_11) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/definitions/used", - "definitions": { - "used": { - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { - "type": "string" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_12) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "definitions": { - "unused": { - "$anchor": "my-anchor", - "type": "string" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_13) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "$defs": { - "unused_in_defs": { "type": "string" } - }, - "definitions": { - "unused_in_definitions": { "type": "integer" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_14) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/definitions/used", - "$defs": { - "unused_in_defs": { "type": "string" } - }, - "definitions": { - "used": { "type": "integer" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { "type": "integer" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_15) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { "type": "string" } - }, - "definitions": { - "unused_in_definitions": { "type": "integer" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/used", - "$defs": { - "used": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_16) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/from_defs", - "$defs": { - "from_defs": { "$ref": "#/definitions/from_definitions" } - }, - "definitions": { - "from_definitions": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/from_defs", - "$defs": { - "from_defs": { "$ref": "#/definitions/from_definitions" } - }, - "definitions": { - "from_definitions": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_17) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "$anchor": "my-anchor", "type": "string" } - }, - "$ref": "#my-anchor" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "$anchor": "my-anchor", "type": "string" } - }, - "$ref": "#my-anchor" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_18) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "$anchor": "my-anchor", "type": "string" } - }, - "$ref": "#/$defs/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "$anchor": "my-anchor", "type": "string" } - }, - "$ref": "#/$defs/foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_19) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "$ref": "#/$defs/bar" }, - "bar": { "$ref": "#/$defs/baz" }, - "baz": { "type": "string" } - }, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_20) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "$ref": "#/$defs/bar" }, - "bar": { "$ref": "#/$defs/baz" }, - "baz": { "$ref": "#/$defs/foo" } - }, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_21) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": true - }, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_22) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/foo", - "$defs": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/foo", - "$defs": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_23) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$defs": { - "unused": { "type": "string" } - }, - "type": "object" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "type": "object" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_24) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$ref": "#/properties/foo/$defs/used", - "$defs": { - "used": { "type": "string" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { - "$ref": "#/properties/foo/$defs/used", - "$defs": { - "used": { "type": "string" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_25) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/properties/foo/$defs/nested", - "properties": { - "foo": { - "$defs": { - "nested": { "type": "integer" } - }, - "type": "object" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/properties/foo/$defs/nested", - "properties": { - "foo": { - "$defs": { - "nested": { "type": "integer" } - }, - "type": "object" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_26) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.sourcemeta.com/schema", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "$ref": "#/$defs/bar" } - }, - "$defs": { - "bar": { - "allOf": [ - { "$ref": "#/$defs/baz" } - ] - }, - "baz": { - "type": "object", - "properties": { - "qux": { "$ref": "#/$defs/extra" } - } - }, - "extra": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.sourcemeta.com/schema", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "$ref": "#/$defs/bar" } - }, - "$defs": { - "bar": { "$ref": "#/$defs/baz" }, - "baz": { - "type": "object", - "properties": { - "qux": { "$ref": "#/$defs/extra" } - } - }, - "extra": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_27) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.sourcemeta.com/schema", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "start": { "$ref": "#/$defs/L1" } - }, - "$defs": { - "L1": { "allOf": [ { "$ref": "#/$defs/L2" } ] }, - "L2": { "properties": { "a": { "$ref": "#/$defs/L3" } } }, - "L3": { "allOf": [ { "$ref": "#/$defs/L4" } ] }, - "L4": { "properties": { "b": { "$ref": "#/$defs/L5" } } }, - "L5": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$id": "https://www.sourcemeta.com/schema", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "start": { "$ref": "#/$defs/L1" } - }, - "$defs": { - "L1": { "$ref": "#/$defs/L2" }, - "L2": { "properties": { "a": { "$ref": "#/$defs/L3" } } }, - "L3": { "$ref": "#/$defs/L4" }, - "L4": { "properties": { "b": { "$ref": "#/$defs/L5" } } }, - "L5": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, orphan_definitions_28) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/outer/$defs/inner", - "$defs": { - "outer": { - "$defs": { - "inner": { "type": "string" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/outer/$defs/inner", - "$defs": { - "outer": { - "$defs": { - "inner": { "type": "string" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_unevaluated_properties_depends_on_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "allOf": [ - { "properties": { "foo": { "type": "string" } } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "allOf": [ - { "properties": { "foo": { "type": "string" } } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_unevaluated_properties_depends_on_pattern_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "allOf": [ - { "patternProperties": { "^f": { "type": "string" } } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "allOf": [ - { "patternProperties": { "^f": { "type": "string" } } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_unevaluated_properties_depends_on_additional_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "allOf": [ - { "additionalProperties": { "type": "string" } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "allOf": [ - { "additionalProperties": { "type": "string" } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_inner_additional_properties_outer_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_inner_properties_and_additional_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_inner_unevaluated_properties_with_all_dependencies) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "properties": { "foo": { "type": "string" } }, - "patternProperties": { "^b": { "type": "number" } }, - "additionalProperties": { "type": "boolean" }, - "unevaluatedProperties": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { "foo": { "type": "string" } }, - "patternProperties": { "^b": { "type": "number" } }, - "additionalProperties": { "type": "boolean" }, - "unevaluatedProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_unevaluated_items_depends_on_prefix_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": false, - "allOf": [ - { "prefixItems": [ { "type": "string" } ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": false, - "allOf": [ - { "prefixItems": [ { "type": "string" } ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_unevaluated_items_depends_on_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": false, - "allOf": [ - { "items": { "type": "string" } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": false, - "allOf": [ - { "items": { "type": "string" } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_unevaluated_items_depends_on_contains) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": false, - "allOf": [ - { "contains": { "type": "string" } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": false, - "allOf": [ - { "contains": { "type": "string" } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_inner_items_outer_prefix_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "prefixItems": [ { "type": "string" } ], - "allOf": [ - { "items": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "prefixItems": [ { "type": "string" } ], - "allOf": [ - { "items": false } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_inner_prefix_items_and_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "prefixItems": [ { "type": "string" }, { "type": "number" } ], - "items": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "prefixItems": [ { "type": "string" }, { "type": "number" } ], - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_inner_unevaluated_items_with_all_dependencies) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "prefixItems": [ { "type": "string" } ], - "items": { "type": "number" }, - "contains": { "minimum": 0 }, - "unevaluatedItems": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "prefixItems": [ { "type": "string" } ], - "items": { "type": "number" }, - "contains": { "minimum": 0 }, - "unevaluatedItems": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_outer_if_inner_then_only) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { "type": "string" }, - "allOf": [ - { "then": { "minLength": 1 } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_outer_if_inner_else_only) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { "type": "string" }, - "allOf": [ - { "else": { "minimum": 0 } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_outer_if_inner_then_and_else) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { "type": "string" }, - "allOf": [ - { "then": { "minLength": 1 }, "else": { "minimum": 0 } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unnecessary_allof_wrapper_inner_if_only) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "if": { "type": "string" } } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_inner_if_then_else_complete) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "if": { "type": "string" }, - "then": { "minLength": 1 }, - "else": { "minimum": 0 } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { "type": "string" }, - "then": { "minLength": 1 }, - "else": { "minimum": 0 } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_multiple_entries_with_dependencies) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "allOf": [ - { "properties": { "foo": { "type": "string" } } }, - { "type": "object" }, - { "minProperties": 1 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "type": "object", - "minProperties": 1, - "allOf": [ - { "properties": { "foo": { "type": "string" } } } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_complex_mixed_dependencies) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "unevaluatedItems": false, - "allOf": [ - { "properties": { "foo": { "type": "string" } } }, - { "prefixItems": [ { "type": "number" } ] }, - { "title": "Test schema" }, - { "description": "A test" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": false, - "unevaluatedItems": false, - "title": "Test schema", - "description": "A test", - "allOf": [ - { "properties": { "foo": { "type": "string" } } }, - { "prefixItems": [ { "type": "number" } ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, circular_ref_through_defs_1) { - auto document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "a": { "$ref": "#/$defs/b" }, - "b": { "$ref": "#/$defs/a" } - }, - "$ref": "#/$defs/a" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const auto expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "a": { "$ref": "#/$defs/b" }, - "b": { "$ref": "#/$defs/a" } - }, - "$ref": "#/$defs/a" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, simple_properties_identifiers_valid) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo": { "type": "string" }, - "bar_baz": { "type": "number" }, - "_private": { "type": "boolean" }, - "CamelCase": { "type": "object" }, - "name123": { "type": "array" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, simple_properties_identifiers_hyphen) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily mapped " - "to programming languages (matching [A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_2020_12, - simple_properties_identifiers_starts_with_digit) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "123abc": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily mapped " - "to programming languages (matching [A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_2020_12, simple_properties_identifiers_special_char) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo@bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily mapped " - "to programming languages (matching [A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_2020_12, simple_properties_identifiers_space) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily mapped " - "to programming languages (matching [A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_2020_12, simple_properties_identifiers_nested) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "valid": { - "type": "object", - "properties": { - "invalid-name": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "/properties/valid", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily mapped " - "to programming languages (matching [A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_2020_12, simple_properties_identifiers_skip_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/my-metaschema", - "title": "My meta-schema", - "description": "A custom meta-schema", - "examples": [ {} ], - "$vocabulary": { - "https://json-schema.org/draft/2020-12/vocab/core": true, - "https://json-schema.org/draft/2020-12/vocab/applicator": true - }, - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, - simple_properties_identifiers_skip_metaschema_nested) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/my-metaschema", - "title": "My meta-schema", - "description": "A custom meta-schema", - "examples": [ {} ], - "$vocabulary": { - "https://json-schema.org/draft/2020-12/vocab/core": true, - "https://json-schema.org/draft/2020-12/vocab/applicator": true - }, - "properties": { - "valid": { - "properties": { - "also-invalid": { "type": "number" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, - simple_properties_identifiers_skip_bundled_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/main", - "title": "Main schema", - "description": "A schema that bundles a meta-schema", - "examples": [ {} ], - "$ref": "https://example.com/my-metaschema", - "$defs": { - "metaschema": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://example.com/my-metaschema", - "$vocabulary": { - "https://json-schema.org/draft/2020-12/vocab/core": true, - "https://json-schema.org/draft/2020-12/vocab/applicator": true - }, - "properties": { - "foo-bar": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, duplicate_allof_branches_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "string" }, - { "type": "string" } - ], - "properties": { - "test": { - "$ref": "#/allOf/1" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "type": "string" } - ], - "properties": { - "test": { - "$ref": "#/allOf/0" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, duplicate_anyof_branches_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "string" }, - { "type": "string" } - ], - "properties": { - "test": { - "$ref": "#/anyOf/1" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "string" } - ], - "properties": { - "test": { - "$ref": "#/anyOf/0" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - duplicate_allof_branches_with_reference_should_deduplicate_and_update_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "#/$defs/a" }, - { "$ref": "#/$defs/b" }, - { "$ref": "#/$defs/a" } - ], - "$defs": { - "a": { "minLength": 1 }, - "b": { "minLength": 5 } - }, - "properties": { - "test": { - "$ref": "#/allOf/2" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "#/$defs/a" }, - { "$ref": "#/$defs/b" } - ], - "$defs": { - "a": { "minLength": 1 }, - "b": { "minLength": 5 } - }, - "properties": { - "test": { - "$ref": "#/allOf/0" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_modern_items_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "items": { - "type": "string" - } - } - ], - "properties": { - "foo": { - "$ref": "#/allOf/0/items" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": { - "type": "string" - }, - "properties": { - "foo": { - "$ref": "#/items" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unnecessary_allof_wrapper_modern_additional_properties_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { - "additionalProperties": { - "type": "number" - } - } - ], - "items": { - "$ref": "#/allOf/0/additionalProperties" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": { - "type": "number" - }, - "items": { - "$ref": "#/additionalProperties" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_empty_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "then": {}, - "additionalProperties": { - "$ref": "#/then" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "then": true, - "additionalProperties": { - "$ref": "#/then" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_empty_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "else": {}, - "properties": { - "foo": { - "$ref": "#/else" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": true, - "else": true, - "properties": { - "foo": { - "$ref": "#/else" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, if_without_then_else_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "type": "string" - }, - "additionalProperties": { - "$ref": "#/if" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "if": { - "type": "string" - }, - "additionalProperties": { - "$ref": "#/if" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, items_schema_default_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": true, - "additionalProperties": { - "$ref": "#/items" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "items": true, - "additionalProperties": { - "$ref": "#/items" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_properties_default_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": true, - "items": { - "$ref": "#/unevaluatedProperties" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedProperties": true, - "items": { - "$ref": "#/unevaluatedProperties" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, unevaluated_items_default_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": true, - "properties": { - "foo": { - "$ref": "#/unevaluatedItems" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "unevaluatedItems": true, - "properties": { - "foo": { - "$ref": "#/unevaluatedItems" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, property_names_default_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "propertyNames": {}, - "items": { - "$ref": "#/propertyNames" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "propertyNames": true, - "items": { - "$ref": "#/propertyNames" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, content_schema_default_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentSchema": true, - "items": { - "$ref": "#/contentSchema" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "contentSchema": true, - "items": { - "$ref": "#/contentSchema" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_without_if_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "then": { - "type": "string" - }, - "properties": { - "foo": { - "$ref": "#/then" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "then": { - "type": "string" - }, - "properties": { - "foo": { - "$ref": "#/then" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_without_if_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "else": { - "type": "string" - }, - "properties": { - "foo": { - "$ref": "#/else" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "else": { - "type": "string" - }, - "properties": { - "foo": { - "$ref": "#/else" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, not_false_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": false, - "properties": { - "foo": { - "$ref": "#/not" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": false, - "properties": { - "foo": { - "$ref": "#/not" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - non_applicable_type_specific_keywords_additional_properties_for_array_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "additionalProperties": { - "type": "string" - }, - "items": { - "$ref": "#/additionalProperties" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "additionalProperties": { - "type": "string" - }, - "items": { - "$ref": "#/additionalProperties" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - non_applicable_type_specific_keywords_properties_for_array_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "properties": { - "foo": { - "type": "string" - } - }, - "items": { - "$ref": "#/properties/foo" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "properties": { - "foo": { - "type": "string" - } - }, - "items": { - "$ref": "#/properties/foo" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - non_applicable_type_specific_keywords_items_for_object_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "items": { - "type": "string" - }, - "additionalProperties": { - "$ref": "#/items" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "items": { - "type": "string" - }, - "additionalProperties": { - "$ref": "#/items" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unevaluated_properties_default_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "unevaluatedProperties": true, - "properties": { - "foo": { "$ref": "#/unevaluatedProperties" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "unevaluatedProperties": true, - "properties": { - "foo": { "$ref": "#/unevaluatedProperties" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - unevaluated_items_default_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "unevaluatedItems": true, - "properties": { - "foo": { "$ref": "#/unevaluatedItems" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "unevaluatedItems": true, - "properties": { - "foo": { "$ref": "#/unevaluatedItems" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - content_schema_default_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "contentSchema": true, - "properties": { - "foo": { "$ref": "#/contentSchema" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "contentSchema": true, - "properties": { - "foo": { "$ref": "#/contentSchema" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - items_schema_default_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "#/$defs/nested" }, - { "$ref": "#/$defs/ref_to_items" } - ], - "$defs": { - "ref_to_items": { "$ref": "nested#/items" }, - "nested": { - "$id": "nested", - "type": "array", - "items": true - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ - { "$ref": "#/$defs/nested" }, - { "$ref": "#/$defs/ref_to_items" } - ], - "$defs": { - "ref_to_items": { "$ref": "nested#/items" }, - "nested": { - "$id": "nested", - "type": "array", - "items": true - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - property_names_default_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "propertyNames": {}, - "properties": { - "foo": { "$ref": "#/propertyNames" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "propertyNames": true, - "properties": { - "foo": { "$ref": "#/propertyNames" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, not_false_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "not": false, - "properties": { - "foo": { "$ref": "#/not" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "not": false, - "properties": { - "foo": { "$ref": "#/not" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_without_if_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "then": { "type": "string" }, - "properties": { - "foo": { "$ref": "#/then" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "then": { "type": "string" }, - "properties": { - "foo": { "$ref": "#/then" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_without_if_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "else": { "type": "string" }, - "properties": { - "foo": { "$ref": "#/else" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "else": { "type": "string" }, - "properties": { - "foo": { "$ref": "#/else" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - if_without_then_else_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "if": { "type": "string" }, - "properties": { - "foo": { "$ref": "#/if" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "if": { "type": "string" }, - "properties": { - "foo": { "$ref": "#/if" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, then_empty_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "if": { "type": "string" }, - "then": {}, - "properties": { - "foo": { "$ref": "#/then" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "if": { "type": "string" }, - "then": true, - "properties": { - "foo": { "$ref": "#/then" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, else_empty_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "if": { "type": "string" }, - "else": {}, - "properties": { - "foo": { "$ref": "#/else" } - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "if": { "type": "string" }, - "else": true, - "properties": { - "foo": { "$ref": "#/else" } - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST( - AlterSchema_lint_2020_12, - non_applicable_type_specific_keywords_items_nested_resource_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "type": "object", - "items": { "type": "string" }, - "additionalProperties": { "$ref": "#/items" } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "#/$defs/nested", - "$defs": { - "nested": { - "$id": "nested", - "type": "object", - "items": { "type": "string" }, - "additionalProperties": { "$ref": "#/items" } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_remove_false_schemas_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - false, - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "string" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_remove_false_schemas_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - false, - { "type": "string" }, - false, - { "type": "number" }, - false - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "string" }, - { "type": "number" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_remove_false_schemas_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_remove_false_schemas_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ false, false, false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_remove_false_schemas_with_ref_through_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - false, - { "type": "string" } - ], - "properties": { - "foo": { "$ref": "#/anyOf/1" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - false, - { "type": "string" } - ], - "properties": { - "foo": { "$ref": "#/anyOf/1" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_remove_false_schemas_with_ref_through_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - false, - { - "type": "object", - "properties": { - "name": { "type": "string" } - } - } - ], - "properties": { - "foo": { "$ref": "#/anyOf/1/properties/name" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - false, - { - "type": "object", - "properties": { - "name": { "type": "string" } - } - } - ], - "properties": { - "foo": { "$ref": "#/anyOf/1/properties/name" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_true_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ true, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_true_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ { "type": "string" }, true ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_true_simplify_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ { "type": "string" }, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_true_simplify_with_ref_through) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - true, - { - "type": "object", - "properties": { - "name": { "type": "string" } - } - } - ], - "properties": { - "foo": { "$ref": "#/anyOf/1/properties/name" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - true, - { - "type": "object", - "properties": { - "name": { "type": "string" } - } - } - ], - "properties": { - "foo": { "$ref": "#/anyOf/1/properties/name" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, anyof_false_simplify_with_ref_through) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ false ], - "properties": { - "foo": { "$ref": "#/anyOf/0" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ false ], - "properties": { - "foo": { "$ref": "#/anyOf/0" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_false_simplify_with_ref_through) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ false ], - "properties": { - "foo": { "$ref": "#/oneOf/0" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ false ], - "properties": { - "foo": { "$ref": "#/oneOf/0" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "const": "hello" }, - { "const": 42 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "const": "hello" }, - { "const": 42 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "enum": [ "a", "b" ] }, - { "enum": [ 1, 2, 3 ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "enum": [ "a", "b" ] }, - { "enum": [ 1, 2, 3 ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" }, - { "minLength": 1 } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" }, - { "minLength": 1 } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_ref_only) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "type": "string" } - }, - "oneOf": [ - { "type": "integer" }, - { "$ref": "#/$defs/foo" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "type": "string" } - }, - "oneOf": [ - { "type": "integer" }, - { "$ref": "#/$defs/foo" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_with_ref) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string", "minLength": 1 }, - { "type": "integer", "minimum": 0 } - ], - "properties": { - "foo": { "$ref": "#/oneOf/0" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "string", "minLength": 1 }, - { "type": "integer", "minimum": 0 } - ], - "properties": { - "foo": { "$ref": "#/anyOf/0" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_mixed) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "string" }, - { "const": 42 }, - { "enum": [ true, false ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "anyOf": [ - { "type": "string" }, - { "const": 42 }, - { "enum": [ true, false ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_enum_overlap) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "enum": [ "a", 1 ] }, - { "enum": [ "b", 2 ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "enum": [ "a", 1 ] }, - { "enum": [ "b", 2 ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, oneof_to_anyof_disjoint_types_number_integer) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "number" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "oneOf": [ - { "type": "number" }, - { "type": "integer" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, empty_object_as_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": {} - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, empty_object_as_true_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, empty_object_as_true_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [ {}, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, object_oneof_required_not_required_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test", - "examples": [ {} ], - "properties": { - "term1": true, - "term2": true - }, - "oneOf": [ - { "required": [ "term1" ], "not": { "required": [ "term2" ] } }, - { "required": [ "term2" ], "not": { "required": [ "term1" ] } } - ] - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, object_oneof_required_not_required_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test", - "examples": [ [] ], - "properties": { - "term1": true, - "term2": true - }, - "items": { - "not": { "required": [ "term2" ] } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "/items/not", "required_properties_in_properties", - "Every property listed in the `required` keyword must be explicitly " - "defined using the `properties` keyword", - true); -} - -TEST(AlterSchema_lint_2020_12, object_oneof_required_not_required_3) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test", - "examples": [ {} ], - "properties": { - "foo": true, - "bar": true - }, - "if": { "type": "object" }, - "then": { - "oneOf": [ - { "not": { "required": [ "foo" ] } }, - { "not": { "required": [ "bar" ] } } - ] - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, object_oneof_required_not_required_4) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test", - "examples": [ {} ], - "properties": { - "foo": true - }, - "if": { "required": [ "foo" ] }, - "then": { "not": { "required": [ "foo" ] } } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, object_oneof_required_not_required_5) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test", - "examples": [ [] ], - "properties": { - "foo": true - }, - "oneOf": [ - { - "items": { - "not": { "required": [ "foo" ] } - } - } - ] - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "/oneOf/0/items/not", "required_properties_in_properties", - "Every property listed in the `required` keyword must be explicitly " - "defined using the `properties` keyword", - true); -} - -TEST(AlterSchema_lint_2020_12, object_oneof_required_not_required_6) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "A test", - "examples": [ {} ], - "properties": { - "foo": true, - "bar": true - }, - "allOf": [ - { - "oneOf": [ - { "not": { "required": [ "foo" ] } }, - { "not": { "required": [ "bar" ] } } - ] - } - ] - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE( - traces, 0, "", "unnecessary_allof_wrapper", - "Keywords inside `allOf` that do not conflict with the parent schema " - "can be elevated", - true); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "not": true - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "enum": [] - }, - "bar": { - "enum": [] - }, - "baz": { - "enum": [1, 2] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "not": true - }, - "bar": { - "not": true - }, - "baz": { - "enum": [1, 2] - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [[]], - "prefixItems": [ - { - "enum": [] - }, - { - "type": "string" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [[]], - "prefixItems": [ - { - "not": true - }, - { - "type": "string" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [[]], - "properties": { - "arr": { - "type": "array", - "items": { - "x-note": "placeholder", - "enum": [] - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [[]], - "properties": { - "arr": { - "type": "array", - "items": { - "x-note": "placeholder", - "not": true - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": {} - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "not": { - "enum": [] - } - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "not": { - "not": true - } - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "enum": [] - } - }, - "$ref": "#/$defs/A" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "enum": [] - } - }, - "$ref": "#/$defs/A" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_11) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "enum": [], - "$defs": { - "inner": { "type": "string" } - } - } - }, - "$ref": "#/$defs/A/$defs/inner" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "enum": [], - "$defs": { - "inner": { "type": "string" } - } - } - }, - "$ref": "#/$defs/A/$defs/inner" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_12) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "$id": "https://example.com/schemas/A", - "enum": [] - } - }, - "$ref": "https://example.com/schemas/A" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "$id": "https://example.com/schemas/A", - "enum": [] - } - }, - "$ref": "https://example.com/schemas/A" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_13) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "x-note": "placeholder", - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "x-note": "placeholder", - "not": true - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_14) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": { "type": "string" }, - "enum": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "not": { "type": "string" }, - "enum": [] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, forbid_empty_enum_15) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "enum": [], - "additionalProperties": { "type": "string" } - } - }, - "$ref": "#/$defs/A/additionalProperties" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "A": { - "enum": [], - "additionalProperties": { "type": "string" } - } - }, - "$ref": "#/$defs/A/additionalProperties" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://unknown.example.com/nonexistent" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://example.com/external" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_3) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "type": "object" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_4) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$defs": { - "foo": { "type": "string" } - }, - "$ref": "#/$defs/foo" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_5) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://example.com/external-with-defs#/$defs/foo" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_6) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://example.com/external-with-defs#/$defs/nonexistent" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_7) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$defs": { - "foo": { - "$id": "https://example.com/embedded", - "type": "string" - } - }, - "$ref": "https://example.com/embedded" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_8) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$defs": { - "foo": { - "$id": "https://example.com/embedded", - "type": "string" - } - }, - "$ref": "https://example.com/embedded#/nonexistent" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 2); - EXPECT_LINT_TRACE(traces, 0, "", "unknown_local_ref", - "Local references that point to unknown locations are " - "invalid and will result in evaluation failures", - true); - EXPECT_LINT_TRACE(traces, 1, "", "orphan_definitions", - "Schema definitions in `$defs` or `definitions` that are " - "never internally referenced can be removed", - true); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_9) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "properties": { - "foo": { - "$ref": "https://unknown.example.com/nonexistent" - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/properties/foo", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://unknown.example.com/nonexistent" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://unknown.example.com/nonexistent" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, invalid_external_ref_11) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "Test", - "description": "Test description", - "examples": [{}], - "properties": { - "bar": { - "$ref": "https://unknown.example.com/first" - }, - "foo": { - "$ref": "https://unknown.example.com/second" - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 2); - EXPECT_LINT_TRACE(traces, 0, "/properties/bar", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); - EXPECT_LINT_TRACE(traces, 1, "/properties/foo", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_2020_12, modern_official_dialect_with_http_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, modern_official_dialect_with_http_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft/2020-12/hyper-schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/hyper-schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, modern_official_dialect_with_http_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft/2020-12/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - modern_official_dialect_with_http_already_https) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_2020_12, - modern_official_dialect_with_http_non_dialect_uri) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://json-schema.org/draft/2020-12/meta/applicator" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$ref": "http://json-schema.org/draft/2020-12/meta/applicator" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_draft0_test.cc b/test/alterschema/alterschema_lint_draft0_test.cc deleted file mode 100644 index 887ab6492..000000000 --- a/test/alterschema/alterschema_lint_draft0_test.cc +++ /dev/null @@ -1,542 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_draft0, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "array", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "boolean", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "null", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "number", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "integer", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "string", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "title": "Test", - "type": "string", - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, draft_official_dialect_without_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, draft_ref_siblings_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "#/definitions/foo", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "#/definitions/foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, draft_ref_siblings_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "A string field" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "#/definitions/foo", - "description": "A string field" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, draft_ref_siblings_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "#/definitions/foo", - "title": "Test Schema", - "$comment": "This is a comment", - "examples": [42], - "default": null, - "type": "object", - "required": ["name"] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "#/definitions/foo", - "default": null, - "title": "Test Schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, draft_ref_siblings_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "id": "http://example.com/schema", - "$ref": "#/definitions/foo", - "type": "string", - "description": "Documentation" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "#/definitions/foo", - "description": "Documentation" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "x-x-foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "x-x-x-foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "definitions": { - "MyType": { - "type": "string" - } - }, - "customKeyword": "should be prefixed" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "object", - "x-definitions": { - "MyType": { - "type": "string" - } - }, - "x-customKeyword": "should be prefixed" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "schema", - "unknownKeyword": "should be removed due to $ref siblings rule", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "$ref": "schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft0, draft_official_dialect_with_https_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-00/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-00/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_draft1_test.cc b/test/alterschema/alterschema_lint_draft1_test.cc deleted file mode 100644 index 610d66c2e..000000000 --- a/test/alterschema/alterschema_lint_draft1_test.cc +++ /dev/null @@ -1,1115 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_draft1, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "foo", "bar" ], - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, 2, 3 ], - "minLength": 0, - "maxLength": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ], - "minLength": 3, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "x-foo-bar": 1, - "maxLength": 100, - "maxItems": 10, - "x-baz-qux": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "x-foo-bar": 1, - "maxLength": 100, - "maxItems": 10, - "x-baz-qux": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, - non_applicable_enum_validation_keywords_unknown_keyword) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "foo", "bar" ], - "x-unknown-keyword": "value", - "x-custom-prop": 42 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ "foo", "bar" ], - "x-unknown-keyword": "value", - "x-custom-prop": 42 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "items": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "items": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, items_array_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "items": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, duplicate_enum_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, maximum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e500 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e+500 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, minimum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "minimum": 9.99999999999999999999999999999e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "minimum": 99.9999999999999999999999999999e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "array", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "boolean", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "null", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "number", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "integer", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "string", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "title": "Test", - "type": "string", - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, equal_numeric_bounds_to_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, draft_official_dialect_without_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, draft_ref_siblings_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "#/definitions/foo", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "#/definitions/foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, draft_ref_siblings_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "A string field" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "#/definitions/foo", - "description": "A string field" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, draft_ref_siblings_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "#/definitions/foo", - "title": "Test Schema", - "$comment": "This is a comment", - "examples": [42], - "default": null, - "type": "object", - "required": ["name"] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "#/definitions/foo", - "title": "Test Schema", - "default": null - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, draft_ref_siblings_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "id": "http://example.com/schema", - "$ref": "#/definitions/foo", - "type": "string", - "description": "Documentation" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "#/definitions/foo", - "description": "Documentation" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "x-x-foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "x-x-x-foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "definitions": { - "MyType": { - "type": "string" - } - }, - "customKeyword": "should be prefixed" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "object", - "x-definitions": { - "MyType": { - "type": "string" - } - }, - "x-customKeyword": "should be prefixed" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "schema", - "unknownKeyword": "should be removed due to $ref siblings rule", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "$ref": "schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft1, draft_official_dialect_with_https_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-01/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-01/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_draft2_test.cc b/test/alterschema/alterschema_lint_draft2_test.cc deleted file mode 100644 index 930f4ab60..000000000 --- a/test/alterschema/alterschema_lint_draft2_test.cc +++ /dev/null @@ -1,1115 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_draft2, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "foo", "bar" ], - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, 2, 3 ], - "minLength": 0, - "maxLength": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ], - "minLength": 3, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "x-foo-bar": 1, - "maxLength": 100, - "maxItems": 10, - "x-baz-qux": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "x-foo-bar": 1, - "maxLength": 100, - "maxItems": 10, - "x-baz-qux": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, - non_applicable_enum_validation_keywords_unknown_keyword) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "foo", "bar" ], - "x-unknown-keyword": "value", - "x-custom-prop": 42 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ "foo", "bar" ], - "x-unknown-keyword": "value", - "x-custom-prop": 42 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "items": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "items": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, items_array_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "items": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, duplicate_enum_values_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, maximum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e500 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e+500 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, minimum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "minimum": 9.99999999999999999999999999999e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "minimum": 99.9999999999999999999999999999e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "array", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "boolean", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "null", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "number", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "integer", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "string", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "title": "Test", - "type": "string", - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, equal_numeric_bounds_to_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, draft_official_dialect_without_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, draft_ref_siblings_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "#/definitions/foo", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "#/definitions/foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, draft_ref_siblings_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "A string field" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "#/definitions/foo", - "description": "A string field" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, draft_ref_siblings_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "#/definitions/foo", - "title": "Test Schema", - "$comment": "This is a comment", - "examples": [42], - "default": null, - "type": "object", - "required": ["name"] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "#/definitions/foo", - "title": "Test Schema", - "default": null - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, draft_ref_siblings_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "id": "http://example.com/schema", - "$ref": "#/definitions/foo", - "type": "string", - "description": "Documentation" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "#/definitions/foo", - "description": "Documentation" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "x-x-foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "x-x-x-foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "definitions": { - "MyType": { - "type": "string" - } - }, - "customKeyword": "should be prefixed" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "object", - "x-definitions": { - "MyType": { - "type": "string" - } - }, - "x-customKeyword": "should be prefixed" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "schema", - "unknownKeyword": "should be removed due to $ref siblings rule", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "$ref": "schema" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft2, draft_official_dialect_with_https_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-02/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-02/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_draft3_test.cc b/test/alterschema/alterschema_lint_draft3_test.cc deleted file mode 100644 index 02dd03541..000000000 --- a/test/alterschema/alterschema_lint_draft3_test.cc +++ /dev/null @@ -1,1330 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_draft3, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, forbid_empty_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Example", - "description": "Example schema", - "properties": { - "foo": { - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Example", - "description": "Example schema", - "properties": { - "foo": { - "enum": [] - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "foo", "bar" ], - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, 2, 3 ], - "minLength": 0, - "maxLength": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ], - "minLength": 3, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "x-foo-bar": 1, - "maxLength": 100, - "maxItems": 10, - "x-baz-qux": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "x-foo-bar": 1, - "maxLength": 100, - "maxItems": 10, - "x-baz-qux": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, - non_applicable_enum_validation_keywords_unknown_keyword) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "foo", "bar" ], - "x-unknown-keyword": "value", - "x-custom-prop": 42 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ "foo", "bar" ], - "x-unknown-keyword": "value", - "x-custom-prop": 42 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, items_array_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, duplicate_enum_values_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, maximum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e500 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e+500 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, minimum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "minimum": 9.99999999999999999999999999999e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "minimum": 99.9999999999999999999999999999e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, dependent_required_tautology_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": "bar", - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "required": [ "foo", "bar" ], - "dependencies": { - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - }, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, dependent_required_tautology_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": [ "bar" ], - "bar": [ "baz" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "required": [ "foo", "bar", "baz" ], - "properties": { - "foo": true, - "bar": true, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, pattern_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "patternProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "array", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "boolean", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "null", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "number", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "integer", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "string", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test", - "type": "string", - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, equal_numeric_bounds_to_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, draft_official_dialect_without_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, additional_items_with_schema_items_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": { - "type": "number" - }, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, additional_items_with_schema_items_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": { - "type": "string" - }, - "additionalItems": { - "type": "boolean" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, - additional_items_with_schema_items_boolean_items_true) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": true, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, - additional_items_with_schema_items_boolean_items_false) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": false, - "additionalItems": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, additional_items_with_schema_items_array_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, draft_ref_siblings_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "$ref": "#/definitions/foo", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, draft_ref_siblings_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "A string field" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "description": "A string field" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, draft_ref_siblings_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "$ref": "#/definitions/foo", - "title": "Test Schema", - "$comment": "This is a comment", - "examples": [42], - "default": null, - "type": "object", - "required": ["name"] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "title": "Test Schema", - "default": null - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, draft_ref_siblings_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "id": "http://example.com/schema", - "$ref": "#/definitions/foo", - "type": "string", - "description": "Documentation" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "description": "Documentation" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "x-x-foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "x-x-x-foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "definitions": { - "MyType": { - "type": "string" - } - }, - "customKeyword": "should be prefixed" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "object", - "x-definitions": { - "MyType": { - "type": "string" - } - }, - "x-customKeyword": "should be prefixed" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "$ref": "#/definitions/MyType", - "unknownKeyword": "should be removed due to $ref siblings rule", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft3, draft_official_dialect_with_https_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-03/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-03/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_draft4_test.cc b/test/alterschema/alterschema_lint_draft4_test.cc deleted file mode 100644 index 8c333cb3d..000000000 --- a/test/alterschema/alterschema_lint_draft4_test.cc +++ /dev/null @@ -1,2790 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_draft4, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ "foo", "bar" ], - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, 2, 3 ], - "minLength": 0, - "maxLength": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ], - "minLength": 3, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2, - "minProperties": 1, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, items_array_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, duplicate_enum_values_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, duplicate_required_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar", "baz", "foo" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, duplicate_allof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "allOf": [ false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, anyof_true_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "anyOf": [ { "type": "string" }, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, anyof_true_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "anyOf": [ {}, { "type": "integer" }, { "type": "boolean" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, oneof_to_anyof_disjoint_types_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "oneOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "anyOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, oneof_to_anyof_disjoint_types_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "oneOf": [ - { "enum": [ "a", "b" ] }, - { "enum": [ 1, 2 ] } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "anyOf": [ - { "enum": [ "a", "b" ] }, - { "enum": [ 1, 2 ] } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, duplicate_anyof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "anyOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "anyOf": [ { "type": "string" }, { "type": "integer" } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, maximum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e500 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "maximum": 1.23456789012345678901234567890e+500 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, maximum_real_for_integer_decimal_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "maximum": 9.99999999999999999999999999999e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "maximum": 9.99999999999999999999999999999e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, minimum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 1.23456789012345678901234567890e500 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 1.23456789012345678901234567890e+500 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, minimum_real_for_integer_decimal_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 9.99999999999999999999999999999e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 99.9999999999999999999999999999e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, dependent_required_tautology_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": [ "bar" ], - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "dependencies": { - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - }, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, dependent_required_tautology_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": [ "bar" ], - "bar": [ "baz" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar", "baz" ], - "properties": { - "foo": true, - "bar": true, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, pattern_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "patternProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unsatisfiable_min_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unsatisfiable_min_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "bar", "baz", "foo" ], - "minProperties": 4, - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unsatisfiable_min_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "array", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "boolean", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "null", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "number", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "integer", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "string", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "type": "string", - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, equal_numeric_bounds_to_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, equal_numeric_bounds_to_enum_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "minimum": 999999999999999999999999999999, - "maximum": 999999999999999999999999999999 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 999999999999999999999999999999 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, equal_numeric_bounds_to_enum_decimal_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "minimum": 1.23456789012345678901234567890e309, - "maximum": 1.23456789012345678901234567890e309 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ 1.23456789012345678901234567890e309 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unnecessary_allof_wrapper_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unnecessary_allof_wrapper_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unnecessary_allof_wrapper_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, multiple_of_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "multipleOf": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, multiple_of_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "multipleOf": 1.0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, multiple_of_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "multipleOf": 1, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, multiple_of_default_no_change_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "multipleOf": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "integer", - "multipleOf": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, multiple_of_default_no_change_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "multipleOf": 0.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "multipleOf": 0.5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, multiple_of_default_no_change_zero) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "multipleOf": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "multipleOf": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, multiple_of_default_no_change_negative) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "multipleOf": -1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "number", - "multipleOf": -1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unnecessary_allof_wrapper_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com", - "properties": { - "bar": { "pattern": "^f" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_ref_wrapper_draft_no_elevation_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { - "$ref": "https://example.com", - "id": "https://other.com" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { - "$ref": "https://example.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unnecessary_allof_ref_wrapper_draft_elevation) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "additionalProperties": { - "allOf": [ - { "$ref": "https://example.com" } - ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "additionalProperties": { - "$ref": "https://example.com" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_ref_wrapper_draft_no_elevation_with_schema) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_ref_wrapper_draft_no_elevation_with_sibling_keyword) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_ref_wrapper_draft_no_elevation_multiple_branches) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, draft_official_dialect_without_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, additional_items_with_schema_items_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": { - "type": "number" - }, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, additional_items_with_schema_items_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "array", - "items": { - "type": "string" - }, - "additionalItems": { - "type": "boolean" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "array", - "items": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - additional_items_with_schema_items_no_change_array_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, additional_items_with_schema_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - additional_items_with_schema_items_boolean_items_true) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": true, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - additional_items_with_schema_items_boolean_items_false) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": false, - "additionalItems": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, draft_ref_siblings_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/foo", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, draft_ref_siblings_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "A string field" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "A string field" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, draft_ref_siblings_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "http://example.com/schema", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "Documentation" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "Documentation" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, draft_ref_siblings_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/foo", - "description": "Documentation only" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "description": "Documentation only" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, draft_ref_siblings_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, draft_ref_siblings_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "nested": { - "$ref": "#/definitions/foo", - "type": "string", - "description": "ignored sibling" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "nested": { - "description": "ignored sibling" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, not_false_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, not_false_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "minimum": 5, - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "minimum": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, not_false_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, not_false_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "not": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "not": {} - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, not_false_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, required_properties_in_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, required_properties_in_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, required_properties_in_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": {}, - "bar": false, - "baz": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": {}, - "bar": false, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, required_properties_in_properties_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, required_properties_in_properties_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, required_properties_in_properties_16) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, required_properties_in_properties_17) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "custom": "value", - "x-custom": "conflicting value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "x-custom": "conflicting value", - "x-x-custom": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "nested": { - "type": "string", - "custom": "value", - "x-custom": "conflicting value" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "nested": { - "type": "string", - "x-custom": "conflicting value", - "x-x-custom": "value" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "definitions": { - "foo": { - "type": "string", - "custom": "value", - "x-custom": "conflicting value" - } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "definitions": { - "foo": { - "type": "string", - "x-custom": "conflicting value", - "x-x-custom": "value" - } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "#/definitions/foo", - "custom": "value", - "x-custom": "conflicting value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, top_level_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "https://sourcemeta.com", - "$ref": "https://example.com" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, orphan_definitions_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, orphan_definitions_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, orphan_definitions_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "definitions": { - "foo": { "type": "string" }, - "bar": { "type": "integer" } - }, - "properties": { - "baz": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "baz": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_wrapper_inner_additional_properties_outer_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_wrapper_inner_properties_and_additional_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, unnecessary_allof_wrapper_with_id_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "id": "nested", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "id": "nested", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_wrapper_with_id_anchor_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "id": "#foo", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "allOf": [ - { "id": "#foo", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, simple_properties_identifiers_skip_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "http://json-schema.org/draft-04/schema#", - "title": "My Meta-Schema", - "description": "A meta-schema for testing", - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft4, - simple_properties_identifiers_skip_metaschema_nested) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "http://json-schema.org/draft-04/schema#", - "title": "My Meta-Schema", - "description": "A meta-schema for testing", - "properties": { - "valid": { - "properties": { - "also-invalid": { "type": "number" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft4, simple_properties_identifiers_applies_non_meta) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "https://example.com/my-schema", - "title": "Test", - "description": "A test schema", - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily " - "mapped to programming languages (matching " - "[A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_draft4, - simple_properties_identifiers_skip_bundled_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "https://example.com/main", - "title": "Main schema", - "description": "A schema that bundles a meta-schema", - "allOf": [ - { "$ref": "#/definitions/metaschema" } - ], - "definitions": { - "metaschema": { - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "http://json-schema.org/draft-04/schema#", - "title": "Bundled Meta-Schema", - "description": "A bundled meta-schema", - "properties": { - "foo-bar": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft4, empty_object_as_true_not_applicable) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "foo": {} - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "foo": {} - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, - unnecessary_allof_wrapper_ref_with_type_object_branch) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "allOf": [ - { "$ref": "../codeType_v01.json" }, - { - "type": "object", - "properties": { - "identificationMethodCode": { - "$ref": "../codeType_v01.json" - } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "object", - "properties": { - "identificationMethodCode": { - "$ref": "../codeType_v01.json" - } - }, - "allOf": [ - { "$ref": "../codeType_v01.json" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, forbid_empty_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "enum": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "not": {} - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, forbid_empty_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "enum": [1, 2] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "enum": [1, 2] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, forbid_empty_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, forbid_empty_enum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "properties": { - "foo": { - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Example", - "description": "Example schema", - "properties": { - "foo": { - "not": {} - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft4, invalid_external_ref_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "description": "Test description", - "properties": { - "foo": { - "$ref": "https://unknown.example.com/nonexistent" - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/properties/foo", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_draft4, invalid_external_ref_1_with_siblings) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "description": "Test description", - "properties": { - "foo": { - "$ref": "https://unknown.example.com/nonexistent", - "type": "string" - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 2); - EXPECT_LINT_TRACE(traces, 0, "/properties/foo", "draft_ref_siblings", - "In Draft 7 and older dialects, keywords sibling to " - "`$ref` are never evaluated", - true); - EXPECT_LINT_TRACE(traces, 1, "/properties/foo", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_draft4, invalid_external_ref_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "Test", - "description": "Test description", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { - "$ref": "#/definitions/foo" - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft4, draft_official_dialect_with_https_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-04/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-04/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_draft6_test.cc b/test/alterschema/alterschema_lint_draft6_test.cc deleted file mode 100644 index 601772ca3..000000000 --- a/test/alterschema/alterschema_lint_draft6_test.cc +++ /dev/null @@ -1,3167 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_draft6, enum_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, const_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, const_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": [ "string", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, const_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, const_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ "foo", "bar" ], - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, 2, 3 ], - "minLength": 0, - "maxLength": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ], - "minLength": 3, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2, - "minProperties": 1, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, items_array_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, duplicate_enum_values_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, duplicate_required_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar", "baz", "foo" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_maximum_number_and_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMaximum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMaximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_maximum_number_and_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMaximum": 3, - "maximum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "maximum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_maximum_number_and_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMaximum": 3, - "maximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_minimum_number_and_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMinimum": 3, - "minimum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_minimum_number_and_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMinimum": 3, - "minimum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_minimum_number_and_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "exclusiveMinimum": 3, - "minimum": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, duplicate_allof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, duplicate_anyof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ { "type": "string" }, { "type": "integer" } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, anyof_true_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ true, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, anyof_true_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ { "type": "string" }, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, anyof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, anyof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, oneof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "oneOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, oneof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, oneof_to_anyof_disjoint_types_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "oneOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "anyOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, oneof_to_anyof_disjoint_types_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, dependent_required_tautology_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": [ "bar" ], - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "dependencies": { - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - }, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, dependent_required_tautology_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": [ "bar" ], - "bar": [ "baz" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar", "baz" ], - "properties": { - "foo": true, - "bar": true, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, pattern_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "patternProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unsatisfiable_min_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unsatisfiable_min_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "bar", "baz", "foo" ], - "minProperties": 4, - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unsatisfiable_min_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "array", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "boolean", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "null", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "number", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "integer", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "string", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "type": "string", - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, const_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_maximum_integer_to_maximum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, exclusive_minimum_integer_to_minimum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, equal_numeric_bounds_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, equal_numeric_bounds_to_const_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, equal_numeric_bounds_to_const_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "minimum": 1.0e400, - "maximum": 1.0e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unnecessary_allof_wrapper_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unnecessary_allof_wrapper_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unnecessary_allof_wrapper_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, multiple_of_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer", - "multipleOf": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, multiple_of_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "multipleOf": 1.0, - "maximum": 100 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "maximum": 100 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unnecessary_allof_wrapper_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com", - "properties": { - "bar": { "pattern": "^f" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unnecessary_allof_ref_wrapper_draft_elevation) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "additionalProperties": { - "allOf": [ - { "$ref": "https://example.com" } - ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "additionalProperties": { - "$ref": "https://example.com" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - unnecessary_allof_ref_wrapper_draft_no_elevation_with_schema) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - unnecessary_allof_ref_wrapper_draft_no_elevation_with_sibling_keyword) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - unnecessary_allof_ref_wrapper_draft_no_elevation_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { - "$ref": "https://example.com", - "$id": "https://other.com" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { - "$ref": "https://example.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - unnecessary_allof_ref_wrapper_draft_no_elevation_multiple_branches) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, draft_official_dialect_without_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, additional_items_with_schema_items_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": { - "type": "number" - }, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, additional_items_with_schema_items_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": { - "const": "foo" - }, - "additionalItems": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": { - "const": "foo" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - additional_items_with_schema_items_boolean_items_true) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": true, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - additional_items_with_schema_items_boolean_items_false) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": false, - "additionalItems": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, additional_items_with_schema_items_array_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, property_names_type_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "propertyNames": { - "type": "string", - "pattern": "^S_" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "propertyNames": { - "pattern": "^S_" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, property_names_type_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "propertyNames": { - "type": [ "string" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, property_names_type_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "propertyNames": { - "type": "integer" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "propertyNames": { - "type": "integer" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, property_names_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "propertyNames": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, draft_ref_siblings_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$ref": "#/definitions/foo", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, draft_ref_siblings_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "A string field" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "description": "A string field" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, draft_ref_siblings_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "http://example.com/schema", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "Documentation" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "description": "Documentation" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, draft_ref_siblings_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$ref": "#/definitions/foo", - "description": "Documentation only" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "description": "Documentation only" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, draft_ref_siblings_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$ref": "#/definitions/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, draft_ref_siblings_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "nested": { - "$ref": "#/definitions/bar", - "type": "object", - "description": "Nested schema with $ref" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "nested": { - "description": "Nested schema with $ref" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_type_specific_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": null, - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": null - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, non_applicable_type_specific_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": "foo", - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "const": "foo", - "maxLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, not_false_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, not_false_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "minimum": 5, - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "minimum": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, not_false_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, not_false_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "not": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, not_false_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, required_properties_in_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, required_properties_in_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, required_properties_in_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": {}, - "bar": false, - "baz": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": false, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, required_properties_in_properties_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, required_properties_in_properties_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, required_properties_in_properties_16) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, required_properties_in_properties_17) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "custom": "value", - "x-custom": "conflicting value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "x-custom": "conflicting value", - "x-x-custom": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "properties": { - "nested": { - "type": "string", - "custom": "value", - "x-custom": "conflicting value" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "properties": { - "nested": { - "type": "string", - "x-custom": "conflicting value", - "x-x-custom": "value" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "definitions": { - "foo": { - "type": "string", - "custom": "value", - "x-custom": "conflicting value" - } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object", - "definitions": { - "foo": { - "type": "string", - "x-custom": "conflicting value", - "x-x-custom": "value" - } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$ref": "#/definitions/foo", - "custom": "value", - "x-custom": "conflicting value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, top_level_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://sourcemeta.com", - "$ref": "https://example.com" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, additional_items_with_no_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, top_level_examples_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "My schema", - "description": "A description", - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_examples", - "Set a non-empty examples array at the top level of the " - "schema to illustrate the expected data", - false); -} - -TEST(AlterSchema_lint_draft6, top_level_examples_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "My schema", - "description": "A description", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft6, duplicate_examples_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "examples": [ "foo", "bar", "foo" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, duplicate_examples_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, orphan_definitions_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, orphan_definitions_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, orphan_definitions_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "foo": { "type": "string" }, - "bar": { "type": "integer" } - }, - "properties": { - "baz": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "baz": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - unnecessary_allof_wrapper_inner_additional_properties_outer_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - unnecessary_allof_wrapper_inner_properties_and_additional_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, unnecessary_allof_wrapper_with_id_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, - unnecessary_allof_wrapper_with_id_anchor_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$id": "#foo", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "allOf": [ - { "$id": "#foo", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, simple_properties_identifiers_skip_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "http://json-schema.org/draft-06/schema#", - "title": "My Meta-Schema", - "description": "A meta-schema for testing", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft6, - simple_properties_identifiers_skip_metaschema_nested) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "http://json-schema.org/draft-06/schema#", - "title": "My Meta-Schema", - "description": "A meta-schema for testing", - "examples": [ {} ], - "properties": { - "valid": { - "properties": { - "also-invalid": { "type": "number" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft6, simple_properties_identifiers_applies_non_meta) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://example.com/my-schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily " - "mapped to programming languages (matching " - "[A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_draft6, - simple_properties_identifiers_skip_bundled_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://example.com/main", - "title": "Main schema", - "description": "A schema that bundles a meta-schema", - "examples": [ {} ], - "allOf": [ - { "$ref": "#/definitions/metaschema" } - ], - "definitions": { - "metaschema": { - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "http://json-schema.org/draft-06/schema#", - "title": "Bundled Meta-Schema", - "description": "A bundled meta-schema", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft6, empty_object_as_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "foo": {} - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, forbid_empty_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, forbid_empty_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, forbid_empty_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, forbid_empty_enum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "not": true - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, const_in_enum_edge_case_preserves_siblings) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://example.com/schemas/my-schema", - "description": "Edge case schema", - "examples": [{}], - "title": "Edge Case Schema", - "x-custom-annotation": "should not be deleted", - "const": 1, - "enum": [1, 2, 3] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "$id": "https://example.com/schemas/my-schema", - "description": "Edge case schema", - "examples": [{}], - "title": "Edge Case Schema", - "x-custom-annotation": "should not be deleted", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft6, const_not_in_enum_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "description": "Test description", - "examples": [1], - "const": 1, - "enum": [2, 3] - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "const_not_in_enum", - "Do not set the `const` and `enum` keyword at the same " - "time, mainly when their values diverge", - false); -} - -TEST(AlterSchema_lint_draft6, const_not_in_enum_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "description": "Test description", - "examples": [{}], - "properties": { - "foo": { - "const": 1, - "enum": [2, 3] - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/properties/foo", "const_not_in_enum", - "Do not set the `const` and `enum` keyword at the same " - "time, mainly when their values diverge", - false); -} - -TEST(AlterSchema_lint_draft6, invalid_external_ref_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://unknown.example.com/nonexistent" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_draft6, invalid_external_ref_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "title": "Test", - "description": "Test description", - "examples": [{}], - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { - "$ref": "#/definitions/foo" - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft6, draft_official_dialect_with_https_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-06/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-06/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_draft7_test.cc b/test/alterschema/alterschema_lint_draft7_test.cc deleted file mode 100644 index d16640583..000000000 --- a/test/alterschema/alterschema_lint_draft7_test.cc +++ /dev/null @@ -1,3843 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_draft7, enum_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, const_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, const_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": [ "string", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, const_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, const_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": [ "boolean", "null" ], - "const": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, enum_with_type_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, enum_with_type_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "enum": [ "foo", 1 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, enum_with_type_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, enum_with_type_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": [ "string", "null" ], - "enum": [ "foo", "bar", "null" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ "foo", "bar", "null" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ "foo", "bar" ], - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ "foo", "bar" ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, 2, 3 ], - "minLength": 0, - "maxLength": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ], - "minLength": 3, - "minimum": 0 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ { "a": 1 }, { "b": 2 } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, "foo" ], - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, "foo" ], - "minLength": 2, - "minimum": 0 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - }, - "minLength": 5, - "minimum": 10 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ { "name": "alice" }, { "age": 25 } ], - "properties": { - "name": { "type": "string" }, - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3, - "minItems": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ "small", "medium", "large" ], - "title": "Size Options", - "minLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 42, "hello", true, null, { "key": "value" }, [1, 2, 3] ], - "minimum": 10, - "minLength": 2, - "minItems": 1, - "minProperties": 1, - "maxLength": 100, - "maxItems": 10, - "maxProperties": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_enum_validation_keywords_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "$comment": "This schema uses enum with various annotation keywords", - "enum": [ "red", "green", "blue" ], - "minimum": 5, - "minLength": 10, - "minItems": 2, - "minProperties": 1, - "maxProperties": 5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com/schema", - "title": "My Enum Schema", - "description": "A schema with enum and annotations", - "$comment": "This schema uses enum with various annotation keywords", - "enum": [ "red", "green", "blue" ], - "minLength": 10 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, single_type_array_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": [ "string" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, content_media_type_without_encoding_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "contentMediaType": "application/json" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, then_without_if_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "then": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, then_without_if_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": true, - "then": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": true, - "then": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, else_without_if_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "else": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, else_without_if_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": true, - "else": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": true, - "else": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, if_without_then_else_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, items_schema_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, items_schema_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, items_schema_default_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, items_array_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, duplicate_enum_values_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, {}, 2, 1, 1, 3, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ 1, {}, 2, 3 ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, duplicate_required_values_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar", "baz", "foo" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_maximum_number_and_maximum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMaximum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMaximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_maximum_number_and_maximum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMaximum": 3, - "maximum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "maximum": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_maximum_number_and_maximum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMaximum": 3, - "maximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "maximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_minimum_number_and_minimum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMinimum": 3, - "minimum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_minimum_number_and_minimum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMinimum": 3, - "minimum": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMinimum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_minimum_number_and_minimum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "exclusiveMinimum": 3, - "minimum": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, duplicate_allof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, duplicate_anyof_branches_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ { "type": "string" }, { "type": "integer" }, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ { "type": "string" }, { "type": "integer" } ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, anyof_true_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ true, { "type": "string" } ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, anyof_true_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ { "type": "string" }, {} ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, anyof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, anyof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, oneof_false_simplify_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "oneOf": [ false ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, oneof_false_simplify_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "oneOf": [ false ], - "not": { "type": "string" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, oneof_to_anyof_disjoint_types_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "oneOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "anyOf": [ - { "type": "string" }, - { "type": "integer" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, oneof_to_anyof_disjoint_types_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "oneOf": [ - { "type": "string" }, - { "type": "string" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, maximum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "maximum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "maximum": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, minimum_real_for_integer_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "minimum": 3.5 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "minimum": 4 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, maximum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "maximum": 9.99999999999999999999999999999e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "maximum": 9.99999999999999999999999999999e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, minimum_real_for_integer_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "minimum": 9.99999999999999999999999999999e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "minimum": 99.9999999999999999999999999999e+399 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, dependent_required_tautology_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": [ "bar" ], - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "dependencies": { - "xxx": { "type": "string" }, - "yyy": [ "extra" ] - }, - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, dependent_required_tautology_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo" ], - "dependencies": { - "foo": [ "bar" ], - "bar": [ "baz" ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar", "baz" ], - "properties": { - "foo": true, - "bar": true, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, pattern_properties_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "patternProperties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unsatisfiable_min_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unsatisfiable_min_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 4 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "bar", "baz", "foo" ], - "minProperties": 4, - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unsatisfiable_min_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar", "bar", "baz" ], - "minProperties": 2 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "bar", "baz", "foo" ], - "properties": { - "bar": true, - "baz": true, - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, drop_non_array_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "array", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "array", - "minItems": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, drop_non_boolean_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "boolean", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, drop_non_null_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "null", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, drop_non_numeric_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "number", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "number" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, drop_non_numeric_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "integer", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, drop_non_object_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "object", - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, drop_non_string_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "string", - "additionalProperties": false, - "minLength": 2, - "minItems": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "type": "string", - "minLength": 2 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, type_boolean_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "boolean" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "boolean" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, type_null_as_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "null" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "null" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, const_as_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_maximum_integer_to_maximum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMaximum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, exclusive_minimum_integer_to_minimum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "exclusiveMinimum": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, equal_numeric_bounds_to_const_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, equal_numeric_bounds_to_const_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "minimum": 3, - "maximum": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, equal_numeric_bounds_to_const_decimal_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "minimum": 1.0e400, - "maximum": 1.0e400 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 1.0e+400 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, equal_numeric_bounds_to_const_decimal_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "number", - "minimum": 1.23456789012345678901234567890e500, - "maximum": 1.23456789012345678901234567890e500 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": 1.23456789012345678901234567890e+500 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unnecessary_allof_wrapper_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unnecessary_allof_wrapper_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "type": "string" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unnecessary_allof_wrapper_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, multiple_of_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer", - "multipleOf": 1 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "integer" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, multiple_of_default_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "multipleOf": 1, - "properties": { - "age": { "type": "number" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "age": { "type": "number" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unnecessary_allof_wrapper_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com", - "properties": { - "bar": { "pattern": "^f" } - } - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "foo": { "type": "string" } - }, - "allOf": [ - { - "$ref": "https://example.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unnecessary_allof_ref_wrapper_draft_elevation) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "additionalProperties": { - "allOf": [ - { "$ref": "https://example.com" } - ] - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "additionalProperties": { - "$ref": "https://example.com" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - unnecessary_allof_ref_wrapper_draft_no_elevation_with_schema) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - unnecessary_allof_ref_wrapper_draft_no_elevation_with_sibling_keyword) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ], - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com" } - ], - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - unnecessary_allof_ref_wrapper_draft_no_elevation_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { - "$ref": "https://example.com", - "$id": "https://other.com" - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { - "$ref": "https://example.com" - } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - unnecessary_allof_ref_wrapper_draft_no_elevation_multiple_branches) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$ref": "https://example.com/foo" }, - { "$ref": "https://example.com/bar" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_official_dialect_without_empty_fragment_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - draft_official_dialect_without_empty_fragment_hyper) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/hyper-schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/hyper-schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - draft_official_dialect_without_empty_fragment_already_has_hash) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, additional_items_with_schema_items_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { - "type": "number" - }, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, additional_items_with_schema_items_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "array", - "items": { - "if": { "type": "string" }, - "then": { "minLength": 1 } - }, - "additionalItems": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "array", - "items": { - "if": { "type": "string" }, - "then": { "minLength": 1 } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - additional_items_with_schema_items_boolean_items_true) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": true, - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - additional_items_with_schema_items_boolean_items_false) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": false, - "additionalItems": { - "type": "string" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, additional_items_with_schema_items_array_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": [ - { "type": "string" }, - { "type": "number" } - ], - "additionalItems": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, then_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, else_empty_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, then_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": {}, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, else_empty_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, then_empty_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "if": { - "properties": { - "flag": { - "const": true - } - } - }, - "then": { - "type": "string" - }, - "else": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, then_empty_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "then": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, property_names_type_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "propertyNames": { - "type": "string", - "pattern": "^S_" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "propertyNames": { - "pattern": "^S_" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, property_names_default_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "propertyNames": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_ref_siblings_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/foo", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_ref_siblings_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/foo", - "type": "string", - "minLength": 5, - "description": "A string field" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "description": "A string field" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_ref_siblings_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "http://example.com/schema", - "$ref": "#/definitions/foo", - "if": { "type": "string" }, - "then": { "minLength": 1 }, - "$comment": "This is a comment", - "examples": [42], - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$comment": "This is a comment", - "examples": [42] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_ref_siblings_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/foo", - "description": "Documentation only" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "description": "Documentation only" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_ref_siblings_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_ref_siblings_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "nested": { - "$ref": "#/definitions/foo", - "type": "string", - "description": "ignored sibling" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "nested": { - "description": "ignored sibling" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_type_specific_keywords_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ true, false ], - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "enum": [ true, false ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_type_specific_keywords_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": null, - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": null - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, non_applicable_type_specific_keywords_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": "foo", - "maxItems": 4, - "maxLength": 3 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "const": "foo", - "maxLength": 3 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, not_false_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, not_false_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "minimum": 5, - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "minimum": 5 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, not_false_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, not_false_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "not": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, not_false_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "not": { - "type": "number" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, required_properties_in_properties_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, required_properties_in_properties_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, required_properties_in_properties_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": {}, - "bar": false, - "baz": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": false, - "baz": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, required_properties_in_properties_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": {} - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, required_properties_in_properties_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "properties": { - "foo": true, - "bar": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, required_properties_in_properties_16) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, required_properties_in_properties_17) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "required": [ "foo", "bar" ], - "additionalProperties": false, - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "fooBar": true - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "x-fooBar": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "baz": 123 - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string", - "x-baz": 123 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "needsPrefix": "value" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "x-alreadyPrefixed": true, - "x-X-alsoGood": 456, - "x-needsPrefix": "value" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "foo": { "type": "string" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_5) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "customKeyword": "value", - "anotherOne": 123, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "x-customKeyword": "value", - "x-anotherOne": 123, - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_6) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "name": { "type": "string" } - }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_7) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/MyType", - "unknownKeyword": "should be removed due to $ref siblings rule", - "type": "object", - "title": "test" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "test" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_8) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "x-x-foo": "original value", - "x-foo": "already prefixed value", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_9) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "x-x-x-foo": "original value", - "x-foo": "first prefixed", - "x-x-foo": "second prefixed", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unknown_keywords_prefix_10) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "MyType": { "type": "string" } - }, - "customKeyword": "should be prefixed", - "type": "object", - "properties": { - "foo": { "$ref": "#/definitions/MyType" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "MyType": { "type": "string" } - }, - "x-customKeyword": "should be prefixed", - "type": "object", - "properties": { - "foo": { "$ref": "#/definitions/MyType" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, top_level_ref_with_id) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://sourcemeta.com", - "$ref": "https://example.com" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "https://example.com" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, additional_items_with_no_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "additionalItems": false - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, comment_trim_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$comment": " A comment with whitespace ", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$comment": "A comment with whitespace", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, comment_trim_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$comment": "A comment without whitespace", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$comment": "A comment without whitespace", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, top_level_examples_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "My schema", - "description": "A description", - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "top_level_examples", - "Set a non-empty examples array at the top level of the " - "schema to illustrate the expected data", - false); -} - -TEST(AlterSchema_lint_draft7, top_level_examples_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "My schema", - "description": "A description", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft7, duplicate_examples_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "examples": [ "foo", "bar", "foo" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "examples": [ "foo", "bar" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, duplicate_examples_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "examples": [ "foo", "bar", "baz" ], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, orphan_definitions_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "type": "object" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, orphan_definitions_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, orphan_definitions_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "foo": { "type": "string" }, - "bar": { "type": "integer" } - }, - "properties": { - "baz": { "$ref": "#/definitions/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "baz": { "$ref": "#/definitions/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - unnecessary_allof_wrapper_inner_additional_properties_outer_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { "foo": { "type": "string" } }, - "allOf": [ - { "additionalProperties": false } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - unnecessary_allof_wrapper_inner_properties_and_additional_properties) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { "foo": { "type": "string" } }, - "additionalProperties": false - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, unnecessary_allof_wrapper_with_id_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$id": "nested", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - unnecessary_allof_wrapper_with_id_anchor_not_elevated) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$id": "#foo", "type": "object" } - ] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { "$id": "#foo", "type": "object" } - ] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, simple_properties_identifiers_skip_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "http://json-schema.org/draft-07/schema#", - "title": "My Meta-Schema", - "description": "A meta-schema for testing", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft7, - simple_properties_identifiers_skip_metaschema_nested) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "http://json-schema.org/draft-07/schema#", - "title": "My Meta-Schema", - "description": "A meta-schema for testing", - "examples": [ {} ], - "properties": { - "valid": { - "properties": { - "also-invalid": { "type": "number" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft7, simple_properties_identifiers_applies_non_meta) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com/my-schema", - "title": "Test", - "description": "A test schema", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "simple_properties_identifiers", - "Set `properties` to identifier names that can be easily " - "mapped to programming languages (matching " - "[A-Za-z_][A-Za-z0-9_]*)", - false); -} - -TEST(AlterSchema_lint_draft7, - simple_properties_identifiers_skip_bundled_metaschema) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com/main", - "title": "Main schema", - "description": "A schema that bundles a meta-schema", - "examples": [ {} ], - "allOf": [ - { "$ref": "#/definitions/metaschema" } - ], - "definitions": { - "metaschema": { - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "http://json-schema.org/draft-07/schema#", - "title": "Bundled Meta-Schema", - "description": "A bundled meta-schema", - "examples": [ {} ], - "properties": { - "foo-bar": { "type": "string" } - } - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft7, unnecessary_allof_wrapper_draft_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "allOf": [ - { - "items": { - "type": "string" - } - } - ], - "properties": { - "foo": { - "$ref": "#/allOf/0/items" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { - "type": "string" - }, - "properties": { - "foo": { - "$ref": "#/items" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, dependencies_default_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "dependencies": {}, - "items": { - "$ref": "#/dependencies" - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "dependencies": {}, - "items": { - "$ref": "#/dependencies" - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - additional_items_with_schema_items_with_reference) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { - "type": "string" - }, - "additionalItems": { - "type": "number" - }, - "properties": { - "foo": { - "$ref": "#/additionalItems" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { - "type": "string" - }, - "additionalItems": { - "type": "number" - }, - "properties": { - "foo": { - "$ref": "#/additionalItems" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - additional_items_reference_to_nested_schema_inside_additional_items) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { - "type": "string" - }, - "additionalItems": { - "type": "object", - "properties": { - "nested": { - "type": "number" - } - } - }, - "properties": { - "test": { - "$ref": "#/additionalItems/properties/nested" - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "items": { - "type": "string" - }, - "additionalItems": { - "type": "object", - "properties": { - "nested": { - "type": "number" - } - } - }, - "properties": { - "test": { - "$ref": "#/additionalItems/properties/nested" - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, empty_object_as_true_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "foo": {} - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "foo": true - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - pattern_properties_ref_with_slashes_in_key_and_defs) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$defs": { - "foo": { "description": "ignored" } - }, - "type": "object", - "patternProperties": { - "^//.*": { "$ref": "#/$defs/foo" } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "x-$defs": { - "foo": { "description": "ignored" } - }, - "type": "object", - "patternProperties": { - "^//.*": { "$ref": "#/x-$defs/foo" } - } - })JSON"); - - EXPECT_EQ(document, expected); - - EXPECT_EQ(traces.size(), 4); - EXPECT_LINT_TRACE( - traces, 0, "", "unknown_keywords_prefix", - "Future versions of JSON Schema will refuse to evaluate unknown " - "keywords or custom keywords from optional vocabularies that don't " - "have an x- prefix", - true); - EXPECT_LINT_TRACE( - traces, 1, "", "top_level_title", - "Set a concise non-empty title at the top level of the schema to " - "explain what the definition is about", - false); - EXPECT_LINT_TRACE( - traces, 2, "", "top_level_description", - "Set a non-empty description at the top level of the schema to " - "explain what the definition is about in detail", - false); - EXPECT_LINT_TRACE( - traces, 3, "", "top_level_examples", - "Set a non-empty examples array at the top level of the schema to " - "illustrate the expected data", - false); -} - -TEST(AlterSchema_lint_draft7, forbid_empty_enum_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "not": true - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, forbid_empty_enum_2) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "enum": [1, 2] - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, forbid_empty_enum_3) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [1], - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, forbid_empty_enum_4) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "enum": [] - } - } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Example", - "description": "Example schema", - "examples": [{}], - "properties": { - "foo": { - "not": true - } - } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, const_in_enum_edge_case_preserves_siblings) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com/schemas/my-schema", - "description": "Edge case schema", - "examples": [{}], - "title": "Edge Case Schema", - "x-custom-annotation": "should not be deleted", - "const": 1, - "enum": [1, 2, 3] - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$id": "https://example.com/schemas/my-schema", - "description": "Edge case schema", - "examples": [{}], - "title": "Edge Case Schema", - "x-custom-annotation": "should not be deleted", - "const": 1 - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, const_not_in_enum_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "description": "Test description", - "examples": [1], - "const": 1, - "enum": [2, 3] - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "const_not_in_enum", - "Do not set the `const` and `enum` keyword at the same " - "time, mainly when their values diverge", - false); -} - -TEST(AlterSchema_lint_draft7, const_not_in_enum_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "description": "Test description", - "examples": [{}], - "properties": { - "foo": { - "const": 1, - "enum": [2, 3] - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "/properties/foo", "const_not_in_enum", - "Do not set the `const` and `enum` keyword at the same " - "time, mainly when their values diverge", - false); -} - -TEST(AlterSchema_lint_draft7, invalid_external_ref_1) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://unknown.example.com/nonexistent" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 1); - EXPECT_LINT_TRACE(traces, 0, "", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_draft7, invalid_external_ref_1_with_siblings) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "description": "Test description", - "examples": [{}], - "$ref": "https://unknown.example.com/nonexistent", - "type": "string" - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - EXPECT_EQ(traces.size(), 2); - EXPECT_LINT_TRACE(traces, 0, "", "draft_ref_siblings", - "In Draft 7 and older dialects, keywords sibling to " - "`$ref` are never evaluated", - true); - EXPECT_LINT_TRACE(traces, 1, "", "invalid_external_ref", - "External references must point to schemas that can be " - "resolved", - false); -} - -TEST(AlterSchema_lint_draft7, invalid_external_ref_2) { - const sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Test", - "description": "Test description", - "examples": [{}], - "definitions": { - "foo": { "type": "string" } - }, - "properties": { - "bar": { - "$ref": "#/definitions/foo" - } - } - })JSON"); - - LINT_WITHOUT_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - EXPECT_EQ(traces.size(), 0); -} - -TEST(AlterSchema_lint_draft7, draft_official_dialect_with_https_1) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_official_dialect_with_https_hyper) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-07/hyper-schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_TRUE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/hyper-schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - draft_official_dialect_with_https_without_fragment) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft-07/schema", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, draft_official_dialect_with_https_already_http) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "string" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_draft7, - draft_official_dialect_with_https_non_dialect_uri) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "https://json-schema.org/draft-07/links#" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "https://json-schema.org/draft-07/links#" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_lint_openapi_test.cc b/test/alterschema/alterschema_lint_openapi_test.cc deleted file mode 100644 index 871db7e0c..000000000 --- a/test/alterschema/alterschema_lint_openapi_test.cc +++ /dev/null @@ -1,245 +0,0 @@ -#include - -#include - -#include "alterschema_test_utils.h" - -TEST(AlterSchema_lint_openapi_3_1, discriminator_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "object", - "discriminator": { "propertyName": "type" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "object", - "discriminator": { "propertyName": "type" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi_3_1, xml_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "object", - "xml": { "name": "foo" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "object", - "xml": { "name": "foo" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi_3_1, externalDocs_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "object", - "externalDocs": { "url": "https://example.com" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "object", - "externalDocs": { "url": "https://example.com" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi_3_1, example_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "string", - "example": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", - "type": "string", - "example": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi_3_2, discriminator_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "object", - "discriminator": { "propertyName": "type" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "object", - "discriminator": { "propertyName": "type" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi_3_2, xml_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "object", - "xml": { "name": "foo" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "object", - "xml": { "name": "foo" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi_3_2, externalDocs_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "object", - "externalDocs": { "url": "https://example.com" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "object", - "externalDocs": { "url": "https://example.com" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi_3_2, example_known_with_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "string", - "example": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://spec.openapis.org/oas/3.2/dialect/2025-09-17", - "type": "string", - "example": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi, discriminator_unknown_without_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "discriminator": { "propertyName": "type" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "x-discriminator": { "propertyName": "type" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi, xml_unknown_without_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "xml": { "name": "foo" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "x-xml": { "name": "foo" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi, externalDocs_unknown_without_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "externalDocs": { "url": "https://example.com" } - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "x-externalDocs": { "url": "https://example.com" } - })JSON"); - - EXPECT_EQ(document, expected); -} - -TEST(AlterSchema_lint_openapi, example_unknown_without_vocabulary) { - sourcemeta::core::JSON document = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "example": "foo" - })JSON"); - - LINT_AND_FIX(document, result, traces); - - EXPECT_FALSE(result.first); - - const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string", - "x-example": "foo" - })JSON"); - - EXPECT_EQ(document, expected); -} diff --git a/test/alterschema/alterschema_test_utils.h b/test/alterschema/alterschema_test_utils.h deleted file mode 100644 index 8b1a45366..000000000 --- a/test/alterschema/alterschema_test_utils.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef SOURCEMETA_CORE_ALTERSCHEMA_TEST_UTILS_H_ -#define SOURCEMETA_CORE_ALTERSCHEMA_TEST_UTILS_H_ - -#include -#include - -#include -#include - -static auto alterschema_test_resolver(std::string_view identifier) - -> std::optional { - if (identifier == - "https://sourcemeta.com/2020-12-custom-vocabulary-optional") { - return sourcemeta::core::parse_json(R"JSON({ - "$id": "https://sourcemeta.com/2020-12-custom-vocabulary-optional", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$vocabulary": { - "https://json-schema.org/draft/2020-12/vocab/core": true, - "https://sourcemeta.com/2020-12-custom-vocabulary-optional": false - } - })JSON"); - } else if (identifier == "https://example.com") { - return sourcemeta::core::parse_json(R"JSON({ - "$id": "https://example.com", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - } else if (identifier == "https://example.com/external") { - return sourcemeta::core::parse_json(R"JSON({ - "$id": "https://example.com/external", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "string" - })JSON"); - } else if (identifier == "https://example.com/external-with-defs") { - return sourcemeta::core::parse_json(R"JSON({ - "$id": "https://example.com/external-with-defs", - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$defs": { - "foo": { "type": "string" } - } - })JSON"); - } else { - return sourcemeta::core::schema_resolver(identifier); - } -} - -#define LINT_WITHOUT_FIX(document, result, traces) \ - std::vector> \ - traces; \ - sourcemeta::core::SchemaTransformer bundle; \ - sourcemeta::core::add(bundle, sourcemeta::core::AlterSchemaMode::Linter); \ - const auto result = bundle.check( \ - document, sourcemeta::core::schema_walker, alterschema_test_resolver, \ - [&traces](const auto &pointer, const auto &name, const auto &message, \ - const auto &outcome, const auto &fixable) { \ - traces.emplace_back(pointer, name, message, outcome, fixable); \ - }); - -#define EXPECT_LINT_TRACE(traces, index, pointer, name, message, fixable) \ - EXPECT_EQ(sourcemeta::core::to_string(std::get<0>((traces).at(index))), \ - (pointer)); \ - EXPECT_EQ(std::get<1>((traces).at(index)), (name)); \ - EXPECT_EQ(std::get<2>((traces).at(index)), (message)); \ - EXPECT_EQ(std::get<4>((traces).at(index)), (fixable)); - -#define LINT_AND_FIX(document, result, traces) \ - std::vector> \ - traces; \ - sourcemeta::core::SchemaTransformer bundle; \ - sourcemeta::core::add(bundle, sourcemeta::core::AlterSchemaMode::Linter); \ - const auto result = bundle.apply( \ - document, sourcemeta::core::schema_walker, alterschema_test_resolver, \ - [&traces](const auto &pointer, const auto &name, const auto &message, \ - const auto &outcome, const auto &fixable) { \ - traces.emplace_back(pointer, name, message, outcome, fixable); \ - }); - -#define CANONICALIZE(document, result, traces) \ - std::vector> \ - traces; \ - sourcemeta::core::SchemaTransformer bundle; \ - sourcemeta::core::add(bundle, \ - sourcemeta::core::AlterSchemaMode::Canonicalizer); \ - const auto result = bundle.apply( \ - document, sourcemeta::core::schema_walker, alterschema_test_resolver, \ - [&traces](const auto &pointer, const auto &name, const auto &message, \ - const auto &outcome, const auto &fixable) { \ - traces.emplace_back(pointer, name, message, outcome, fixable); \ - }); - -#endif diff --git a/test/packaging/find_package/CMakeLists.txt b/test/packaging/find_package/CMakeLists.txt index e281fb81d..c02e3070d 100644 --- a/test/packaging/find_package/CMakeLists.txt +++ b/test/packaging/find_package/CMakeLists.txt @@ -21,7 +21,6 @@ target_link_libraries(core_hello PRIVATE sourcemeta::core::jsonpointer) target_link_libraries(core_hello PRIVATE sourcemeta::core::jsonl) target_link_libraries(core_hello PRIVATE sourcemeta::core::yaml) target_link_libraries(core_hello PRIVATE sourcemeta::core::html) -target_link_libraries(core_hello PRIVATE sourcemeta::core::alterschema) target_link_libraries(core_hello PRIVATE sourcemeta::core::editorschema) target_link_libraries(core_hello PRIVATE sourcemeta::core::options) target_link_libraries(core_hello PRIVATE sourcemeta::core::preprocessor) diff --git a/test/packaging/find_package/hello.cc b/test/packaging/find_package/hello.cc index 925e19a68..ef853350d 100644 --- a/test/packaging/find_package/hello.cc +++ b/test/packaging/find_package/hello.cc @@ -1,4 +1,3 @@ -#include #include #include #include